Skip to content

HTTP Clients

The client parameter of the Consumer constructor offers a way to swap out Requests with another HTTP client, including those listed here:

github = GitHub(BASE_URL, client=...)

Requests

uplink.RequestsClient

RequestsClient(session=None, **kwargs)

Bases: HttpClientAdapter

A requests client that returns requests.Response responses.

PARAMETER DESCRIPTION
session

The session that should handle sending requests. If this argument is omitted or set to None, a new session will be created.

DEFAULT: None

Source code in uplink/clients/requests_.py
def __init__(self, session=None, **kwargs):
    self.__auto_created_session = False
    if session is None:
        session = self._create_session(**kwargs)
        self.__auto_created_session = True
    self.__session = session

Aiohttp

uplink.AiohttpClient

AiohttpClient(*args, **kwargs)

Bases: HttpClientAdapter

Source code in uplink/clients/__init__.py
def __init__(self, *args, **kwargs):
    raise NotImplementedError(
        "Failed to load `aiohttp` client: you may be using a version "
        "of Python below 3.3. `aiohttp` requires Python 3.4+."
    )

Twisted

uplink.TwistedClient

TwistedClient(session=None)

Bases: HttpClientAdapter

Client that returns [twisted.internet.defer.Deferred][] responses.

Note

This client is an optional feature and requires the [twisted][] package. For example, here's how to install this extra using pip:

$ pip install uplink[twisted]
PARAMETER DESCRIPTION
session

The session that should handle sending requests. If this argument is omitted or set to None, a new session will be created.

TYPE: [`requests.Session`][requests.Session] DEFAULT: None

Source code in uplink/clients/twisted_.py
def __init__(self, session=None):
    if threads is None:
        raise NotImplementedError("twisted is not installed.")
    self._proxy = register.get_client(session)