1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
apiclient
==========
Client class for calling http+json APIs in Python. Requires Python 2.7.
Supports json home pages per:
http://tools.ietf.org/html/draft-nottingham-json-home-03
Installation
------------
Standard python package installation:
python setup.py install
Usage
-----
Import the apiclient package and instantiate a client.
import apiclient
api = apiclient.APIClient('http://api.example.com')
Call APIs:
result = api.call('foo', var1=arg1, var2=arg2)
print result.data
APIClient class
---------------
**class apiclient.APIClient(baseURI, version = None, username = None, password = None)**
The APIClient constructor takes the base URI for the api, an optional request version identifier, username and password.
**APIClient.baseURI**
The base URI set in the constructor, read-only.
**APIClient.resourceNames**
A list of available API resource names.
**APIClient.resource(name)**
Get a named APIResource.
**APIClient.setVersion(name, version)**
Set the request version identifier for a specific resource. If not set, the default version identifier will be used.
**APIClient.setAccept(name, mimeType)**
Set the requested Content-Type for a specific resource. If not set, 'application/json' will be used.
**APIClient.get(name, [kwargs])**
Perform an HTTP GET on the named resource. Any named arguments supplied may be used in computing the actual URI to call. Returns an APIResponse or None if the resource name is not known.
**APIClient.postForm(name, payload = None, [kwargs])**
Perform an HTTP POST on the named resource. The payload, if present, may be either a dict or sequence of two-tuples and will be form encoded. Any named arguments supplied may be used in computing the actual URI to call. Returns an APIResponse or None if the resource name is not known.
**APIClient.put(name, payload = None, payloadType = None, [kwargs])**
Perform an HTTP PUT on the named resource. The payload, if present, will be sent to the server using the payloadType Content-Type. The payload must be pre-encoded and will not be processed by the APIClient. Any named arguments supplied may be used in computing the actual URI to call. Returns an APIResponse or None if the resource name is not known.
**APIClient.patch(name, patch = None, [kwargs])**
Perform an HTTP PATCH on the named resource. The patch, if present, will be encoded in JSON and sent to the server as a 'application/json-patch'. Any named arguments supplied may be used in computing the actual URI to call. Returns an APIResponse or None if the resource name is not known.
**APIClient.delete(name, [kwargs])**
Perform an HTTP DELETE on the named resource. Any named arguments supplied may be used in computing the actual URI to call. Returns an APIResponse or None if the resource name is not known.
APIResponse class
-----------------
**APIResponse.status**
The HTTP status code of the response.
**APIResponse.headers**
A dict of HTTP response headers.
**APIResponse.contentType**
The Content-Type of the response.
**APIResponse.encoding**
The encoding of the response.
**APIResponse.data**
The body of the response. If the contentType is json, the data will be decoded into native objects.
APIResource class
-----------------
Describes the properties of an available API resource.
**APIResource.template**
The URITemplate used when calling the resource.
**APIResource.variables**
A dict of variables that may be passed to the resource. Keys are variable names, values are the URI identifier of the variable, if available (see http://tools.ietf.org/html/draft-nottingham-json-home-03#section-3.1 ).
**APIResource.hints**
An APIHints object describing any hints for the resource (see http://tools.ietf.org/html/draft-nottingham-json-home-03#section-4 ).
APIHints class
--------------
**APIHints.httpMethods**
A list of HTTP methods the resource may be called with.
**APIHints.formats**
A dict of formats available for each HTTP method. Keys are HTTP methods, values are a list of Content-Types available.
**APIHints.ranges**
Not yet implemented.
**APIHints.preferences**
Not yet implemented.
**APIHints.preconditions**
Not yet implemented.
**APIHints.auth**
Not yet implemented.
**APIHints.docs**
A URI for documentation for the resource.
**APIHints.status**
The status of the resource.
URITemplate class
-----------------
Parses and expands URITemplates per RFC 6750 (plus a few extensions).
**class uritemplate.URITemplate(template)**
Construct a URITemplate. Raises exceptions if malformed.
**URITemplate.variables**
A set of variables available in the template.
**URITemplate.expand([kwargs])**
Return the expanded template substituting any passed keyword arguments.
Notes
-----
Resource names may be absolute URIs or relative to the base URI of the API.
|