The Base Consumer Class
Consumer
uplink.Consumer
Bases: Consumer
, _Consumer
Base consumer class with which to define custom consumers.
Example usage:
from uplink import Consumer, get
class GitHub(Consumer):
@get("/users/{user}")
def get_user(self, user):
pass
client = GitHub("https://api.github.com/")
client.get_user("prkumar").json() # {'login': 'prkumar', ... }
PARAMETER | DESCRIPTION |
---|---|
base_url
|
The base URL for any request sent from this consumer instance.
TYPE:
|
client
|
A supported HTTP client instance (e.g.,
a
TYPE:
|
converters
|
One or more objects that encapsulate custom
(de)serialization strategies for request properties and/or
the response body. (E.g.,
TYPE:
|
auth
|
The authentication object for this consumer instance.
TYPE:
|
hooks
|
One or more hooks to modify behavior of request execution
and response handling (see
TYPE:
|
Source code in uplink/builder.py
exceptions
property
session
property
The Session object for this consumer instance.
Exposes the configuration of this Consumer instance and allows the persistence of certain properties across all requests sent from that instance.
Example usage:
import uplink
class MyConsumer(uplink.Consumer):
def __init__(self, language):
# Set this header for all requests of the instance.
self.session.headers["Accept-Language"] = language
...
RETURNS | DESCRIPTION |
---|---|
Session
uplink.session.Session
The session of a Consumer
instance.
Exposes the configuration of a Consumer
instance and
allows the persistence of certain properties across all requests sent
from that instance.
Source code in uplink/session.py
context
property
A dictionary of name-value pairs that are made available to request middleware.
headers
property
A dictionary of headers to be sent on each request from this consumer instance.
params
property
A dictionary of querystring data to attach to each request from this consumer instance.
inject
Add hooks (e.g., functions decorated with either
uplink.response_handler
or
uplink.error_handler
) to the session.