oasislmf.platform_api.session

Classes

APISession

A Requests session.

Module Contents

class oasislmf.platform_api.session.APISession(api_url, username, password, timeout=25, retries=5, retry_delay=1, request_interval=0.02, logger=None, **kwargs)[source]

Bases: requests.Session

A Requests session.

Provides cookie persistence, connection-pooling, and configuration.

Basic Usage:

>>> import requests
>>> s = requests.Session()
>>> s.get('https://httpbin.org/get')
<Response [200]>

Or as a context manager:

>>> with requests.Session() as s:
...     s.get('https://httpbin.org/get')
<Response [200]>
logger[source]
tkn_access = None[source]
tkn_refresh = None[source]
url_base[source]
timeout[source]
retry_max = 0[source]
retry_delay[source]
request_interval[source]
headers[source]
unrecoverable_error(error, msg=None)[source]
health_check()[source]

Checks the health of the server.

upload(url, filepath, content_type, **kwargs)[source]
get(url, **kwargs)[source]

Sends a GET request. Returns Response object.

Parameters:
  • url – URL for the new Request object.

  • **kwargs – Optional arguments that request takes.

Return type:

requests.Response

post(url, **kwargs)[source]

Sends a POST request. Returns Response object.

Parameters:
  • url – URL for the new Request object.

  • data – (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the Request.

  • json – (optional) json to send in the body of the Request.

  • **kwargs – Optional arguments that request takes.

Return type:

requests.Response

delete(url, **kwargs)[source]

Sends a DELETE request. Returns Response object.

Parameters:
  • url – URL for the new Request object.

  • **kwargs – Optional arguments that request takes.

Return type:

requests.Response

put(url, **kwargs)[source]

Sends a PUT request. Returns Response object.

Parameters:
  • url – URL for the new Request object.

  • data – (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the Request.

  • **kwargs – Optional arguments that request takes.

Return type:

requests.Response