requests-gracedb Documentation¶
requests-gracedb provides a generic REST API client for GraceDB and similar LIGO/Virgo API services. It uses the powerful Requests package for reliable and high-throughput HTTP connection pooling.
Quick Start¶
Install with pip:
pip install requests-gracedb
API¶
- class requests_gracedb.Session(url=None, token=None, username=None, password=None, force_noauth=False, fail_if_noauth=False, auth_reload=False, auth_reload_timeout=300, **kwargs)[source]¶
Bases:
SessionAuthMixin,SessionErrorMixin,SessionFileMixin,SessionUserAgentMixin,SessionA
requests.Sessionsubclass that adds behaviors that are common to ligo.org REST API services such as that of GraceDB.It adds the following behaviors to the session:
GraceDB-style authentication (see
SessionAuthMixin)Raise exceptions based on HTTP status codes (see
SessionErrorMixin)Automatically load POSTed files from disk, automatically guess MIME types (see
SessionFileMixin)Add User-Agent string based on Python package name and version (see
SessionUserAgentMixin)
- class requests_gracedb.auth.SessionAuthMixin(url=None, token=None, username=None, password=None, force_noauth=False, fail_if_noauth=False, auth_reload=False, auth_reload_timeout=300, **kwargs)[source]¶
Bases:
objectA mixin for
requests.Sessionto add support for all GraceDB authentication mechanisms.- Parameters:
url (str) – GraceDB Client URL.
token (str) – Filename for SciTokens bearer token.
username (str) – Username for basic auth.
password (str) – Password for basic auth.
force_noauth (bool, default=False) – If true, then do not use any authentication at all.
fail_if_noauth (bool, default=False) – If true, then raise an exception if authentication credentials are not provided.
auth_reload (bool, default=False) – If true, then automatically reload the authentication before it expires.
auth_reload_timeout (int, default=300) – Reload the authentication this many seconds before it expires.
Notes
When a new Session instance is created, the following sources of authentication are tried, in order:
If the
force_noauthkeyword argument is true, then perform no authentication at all.If the
tokenkeyword argument is provided, then use SciTokens bearer token authentication.If the
usernameandpasswordkeyword arguments are provided, then use basic auth.Look for a SciTokens bearer token in:
the environment variable
BEARER_TOKEN_FILEthe file
$XDG_RUNTIME_DIR/bt_uUID, whereUIDis your numeric user ID, if the file exists and is readable
Read the netrc file [1] located at
~/.netrc, or at the path stored in the environment variableNETRC, and look for a username and password matching the hostname in the URL.If the
fail_if_noauthkeyword argument is true, and no authentication source was found, then raise aValueError.
References
- class requests_gracedb.errors.SessionErrorMixin(**kwargs)[source]¶
Bases:
objectA mixin for
requests.Sessionto raise exceptions for HTTP errors.
- class requests_gracedb.file.SessionFileMixin[source]¶
Bases:
objectA mixin for
requests.Sessionto add features for file uploads.The
requests.Session.request()method takes a files argument which is a dictionary of {fieldname: fileobject}, where fileobject may be a file-like object or a tuple of 2-4 elements consisting of the filename, file content, MIME type, and any custom headers.This mixin adds the following features:
The MIME type is automatically guessed from the filename.
If the file content is None, then the filename is treated as a path, and the file is opened and read. If the filename is -, then the file content is read from stdin.
- class requests_gracedb.user_agent.SessionUserAgentMixin(**kwargs)[source]¶
Bases:
objectA mixin for
requests.Sessionto add a User-Agent header.