The Base Consumer Class

Consumer

class uplink.Consumer(base_url='', client=None, converters=(), auth=None, hooks=(), **kwargs)

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', ... }
Parameters:
  • base_url (str, optional) – The base URL for any request sent from this consumer instance.
  • client (optional) – A supported HTTP client instance (e.g., a requests.Session) or an adapter (e.g., RequestsClient).
  • converters (ConverterFactory, optional) – One or more objects that encapsulate custom (de)serialization strategies for request properties and/or the response body. (E.g., MarshmallowConverter)
  • auth (tuple or callable, optional) – The authentication object for this consumer instance.
  • hooks (TransactionHook, optional) – One or more hooks to modify behavior of request execution and response handling (see response_handler or error_handler).
session

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:Session

Session

class 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.

auth

The authentication object for this consumer instance.

base_url

The base URL for any requests sent from this consumer instance.

headers

A dictionary of headers to be sent on each request from this consumer instance.

inject(hook, *more_hooks)

Add hooks (e.g., functions decorated with either response_handler or error_handler) to the session.

params

A dictionary of querystring data to attach to each request from this consumer instance.