Client¶
-
class
clients.
Client
(url, trailing='', headers=(), auth=None, **attrs)[source]¶ Bases:
requests.sessions.Session
A Session which sends requests to a base url.
Parameters: - url – base url for requests
- trailing – trailing chars (e.g. /) appended to the url
- headers – additional headers to include in requests
- auth – additional authorization support for
{token_type: access_token}
, available per request as well - attrs – additional Session attributes
Resource¶
-
class
clients.
Resource
(url, trailing='', headers=(), auth=None, **attrs)[source]¶ Bases:
clients.base.Client
A Client which returns json content and has syntactic support for requests.
-
content_type
(response)¶ Return name {json, text,… } of response’s content_type.
-
__delitem__
(path='', **kwargs)¶ DELETE request with optional path.
-
__getitem__
(path='', **kwargs)¶ GET request with optional path.
-
__iter__
(path: str = '', **kwargs) → Iterator[T_co]¶ Iterate lines or chunks from streamed GET request.
-
__setitem__
(path='', json=None, **kwargs)¶ PUT request with optional path and json body.
Acquire oauth access token and set
auth
.
-
content_type
= functools.partial(<function content_type>, text='text/', json='application/(\\w|\\.)*\\+?json')
-
iter
(path: str = '', **kwargs) → Iterator[T_co][source]¶ Iterate lines or chunks from streamed GET request.
-
Remote¶
-
class
clients.
Remote
(url: str, json=(), **kwargs)[source]¶ Bases:
clients.base.Client
A Client which defaults to posts with json bodies, i.e., RPC.
Parameters: - url – base url for requests
- json – default json body for all calls
- kwargs – same options as Client
-
__getattr__
(name: str) → clients.base.Client¶ Return a cloned client with appended path.
-
__init__
(url: str, json=(), **kwargs)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Graph¶
Proxy¶
-
class
clients.
Proxy
(*urls, **kwargs)[source]¶ Bases:
clients.base.Client
An extensible embedded proxy client to multiple hosts.
The default implementation provides load balancing based on active connections. It does not provide error handling or retrying.
Parameters: - urls – base urls for requests
- kwargs – same options as Client
-
class
Stats
¶ Bases:
collections.Counter
Thread-safe Counter.
Context manager tracks number of active connections and errors.
-
add
(**kwargs)¶ Atomically add data.
-
-
choice
(method: str) → str[source]¶ Return chosen url according to priority.
Parameters: method – placeholder for extensions which distinguish read/write requests
AsyncClient¶
-
class
clients.
AsyncClient
(url: str, *, trailing: str = '', auth=None, **attrs)[source]¶ Bases:
httpx.client.AsyncClient
An asynchronous Client which sends requests to a base url.
Parameters: - url – base url for requests
- trailing – trailing chars (e.g. /) appended to the url
- params – default query params
- auth – additional authorization support for
{token_type: access_token}
, available per request as well - attrs – additional AsyncClient options
-
__truediv__
(path: str) → clients.base.Client¶ Return a cloned client with appended path.
-
delete
(path='', **kwargs)¶ DELETE request with optional path.
-
get
(path='', **kwargs)¶ GET request with optional path.
-
head
(path='', allow_redirects=False, **kwargs)¶ HEAD request with optional path.
-
options
(path='', **kwargs)¶ OPTIONS request with optional path.
-
patch
(path='', json=None, **kwargs)¶ PATCH request with optional path and json body.
-
post
(path='', json=None, **kwargs)¶ POST request with optional path and json body.
-
put
(path='', json=None, **kwargs)¶ PUT request with optional path and json body.
AsyncResource¶
-
class
clients.
AsyncResource
(url: str, *, trailing: str = '', auth=None, **attrs)[source]¶ Bases:
clients.aio.AsyncClient
An AsyncClient which returns json content and has syntactic support for requests.
-
__call__
(path: str = '', **params)¶ GET request with params.
-
__getattr__
(path: str) → clients.base.Client¶ Return a cloned client with appended path.
-
__getitem__
(path='', **kwargs)¶ GET request with optional path.
Acquire oauth access token and set
auth
.
-
client
¶ upcasted AsyncClient
-
content_type
= functools.partial(<function content_type>, text='text/', json='application/(\\w|\\.)*\\+?json')¶
-
AsyncRemote¶
-
class
clients.
AsyncRemote
(url: str, json=(), **kwargs)[source]¶ Bases:
clients.aio.AsyncClient
An AsyncClient which defaults to posts with json bodies, i.e., RPC.
Parameters: - url – base url for requests
- json – default json body for all calls
- kwargs – same options as AsyncClient
-
__getattr__
(path: str) → clients.base.Client¶ Return a cloned client with appended path.
-
__init__
(url: str, json=(), **kwargs)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
static
check
(result)¶ Override to return result or raise error, for APIs which don’t use status codes.
-
client
¶ upcasted AsyncClient
AsyncGraph¶
-
class
clients.
AsyncGraph
(url: str, json=(), **kwargs)[source]¶ Bases:
clients.aio.AsyncRemote
An AsyncRemote client which executes GraphQL queries.
-
Error
¶ alias of
httpx.exceptions.HTTPError
-
classmethod
check
(result: dict)¶ Return
data
or raiseerrors
.
-
execute
(query: str, **variables)¶ Execute query over POST.
-
AsyncProxy¶
-
class
clients.
AsyncProxy
(*urls, **kwargs)[source]¶ Bases:
clients.aio.AsyncClient
An extensible embedded proxy client to multiple hosts.
The default implementation provides load balancing based on active connections. It does not provide error handling or retrying.
Parameters: - urls – base urls for requests
- kwargs – same options as AsyncClient
-
class
Stats
¶ Bases:
collections.Counter
Thread-safe Counter.
Context manager tracks number of active connections and errors.
-
add
(**kwargs)¶ Atomically add data.
-
-
choice
(method: str) → str¶ Return chosen url according to priority.
Parameters: method – placeholder for extensions which distinguish read/write requests
-
priority
(url: str)¶ Return comparable priority for url.
Minimizes errors, failures (500s), and active connections. None may be used to eliminate from consideration.