Common API¶
All service clients support the low level interface, provided by the
BaseClient
.
-
class
globus_sdk.base.
BaseClient
(service, environment=None, base_url=None, base_path=None, authorizer=None, app_name=None, http_timeout=None, *args, **kwargs)[source]¶ Simple client with error handling for Globus REST APIs. Implemented as a wrapper around a
requests.Session
object, with a simplified interface that does not directly expose anything from requests.You should never try to directly instantiate a
BaseClient
.- Parameters
authorizer (
GlobusAuthorizer
) – AGlobusAuthorizer
which will generate Authorization headersapp_name (str) – Optional “nice name” for the application. Has no bearing on the semantics of client actions. It is just passed as part of the User-Agent string, and may be useful when debugging issues with the Globus Team
http_timeout (float) – Number of seconds to wait on HTTP connections. Default is 60. A value of -1 indicates that no timeout should be used (requests can hang indefinitely).
All other parameters are for internal use and should be ignored.
-
set_app_name
(app_name)[source]¶ Set an application name to send to Globus services as part of the User Agent.
Application developers are encouraged to set an app name as a courtesy to the Globus Team, and to potentially speed resolution of issues when interacting with Globus Support.
-
get
(path, params=None, headers=None, response_class=None, retry_401=True)[source]¶ Make a GET request to the specified path.
- Parameters
path (str) – Path for the request, with or without leading slash
params (dict) – Parameters to be encoded as a query string
headers (dict) – HTTP headers to add to the request
response_class (class) – Class for response object, overrides the client’s
default_response_class
retry_401 (bool) – Retry on 401 responses with fresh Authorization if
self.authorizer
supports it
- Returns
GlobusHTTPResponse
object
-
post
(path, json_body=None, params=None, headers=None, text_body=None, response_class=None, retry_401=True)[source]¶ Make a POST request to the specified path.
- Parameters
path (str) – Path for the request, with or without leading slash
params (dict) – Parameters to be encoded as a query string
headers (dict) – HTTP headers to add to the request
json_body (dict) – Data which will be JSON encoded as the body of the request
text_body (str or dict) – Either a raw string that will serve as the request body, or a dict which will be HTTP Form encoded
response_class (class) – Class for response object, overrides the client’s
default_response_class
retry_401 (bool) – Retry on 401 responses with fresh Authorization if
self.authorizer
supports it
- Returns
GlobusHTTPResponse
object
-
delete
(path, params=None, headers=None, response_class=None, retry_401=True)[source]¶ Make a DELETE request to the specified path.
- Parameters
path (str) – Path for the request, with or without leading slash
params (dict) – Parameters to be encoded as a query string
headers (dict) – HTTP headers to add to the request
response_class (class) – Class for response object, overrides the client’s
default_response_class
retry_401 (bool) – Retry on 401 responses with fresh Authorization if
self.authorizer
supports it
- Returns
GlobusHTTPResponse
object
-
put
(path, json_body=None, params=None, headers=None, text_body=None, response_class=None, retry_401=True)[source]¶ Make a PUT request to the specified path.
- Parameters
path (str) – Path for the request, with or without leading slash
params (dict) – Parameters to be encoded as a query string
headers (dict) – HTTP headers to add to the request
json_body (dict) – Data which will be JSON encoded as the body of the request
text_body (str or dict) – Either a raw string that will serve as the request body, or a dict which will be HTTP Form encoded
response_class (class) – Class for response object, overrides the client’s
default_response_class
retry_401 (bool) – Retry on 401 responses with fresh Authorization if
self.authorizer
supports it
- Returns
GlobusHTTPResponse
object
Responses¶
Unless noted otherwise, all method return values for Globus SDK Clients are
GlobusResponse
objects.
Some GlobusResponse
objects are iterables.
In those cases, their contents will also be GlobusResponse
objects.
To customize client methods with additional detail, the SDK uses subclasses of
GlobusResponse
.
For example the GlobusHTTPResponse
attaches HTTP response information.
Generic Response Classes¶
-
class
globus_sdk.response.
GlobusResponse
(data, client=None)[source]¶ Generic response object, with a single
data
member.The most common response data is a JSON dictionary. To make handling this type of response as seemless as possible, the
GlobusResponse
object also supports direct dictionary item access, as an alias for accessing an item of the underlyingdata
. Ifdata
is not a dictionary, item access will raiseTypeError
.>>> print("Response ID": r["id"]) # alias for r.data["id"]
GlobusResponse
objects always wrap some kind of data to return to a caller. Most basic actions on a GlobusResponse are just ways of interacting with this data.-
property
data
¶ Response data as a Python data structure. Usually a dict or list.
-
property
-
class
globus_sdk.response.
GlobusHTTPResponse
(http_response, client=None)[source]¶ Bases:
globus_sdk.response.GlobusResponse
Response object that wraps an HTTP response from the underlying HTTP library. If the response is JSON, the parsed data will be available in
data
, otherwisedata
will beNone
andtext
should be used instead.- Variables
http_status – HTTP status code returned by the server (int)
content_type – Content-Type header returned by the server (str)
-
property
data
¶ Response data as a Python data structure. Usually a dict or list.
-
property
text
¶ The raw response data as a string.