Converters

The converter parameter of the uplink.Consumer constructor accepts an adapter class that handles deserialization of HTTP response objects:

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

Marshmallow

class uplink.MarshmallowConverter

A converter that serializes and deserializes values using marshmallow schemas.

To deserialize JSON responses into Python objects with this converter, define a marshmallow.Schema subclass and set it as the return annotation of a consumer method:

@get("/users")
def get_users(self, username) -> UserSchema():
    '''Fetch a single user'''

Also, when instantiating a consumer, be sure to set this class as a converter for the instance:

github = GitHub(BASE_URL, converter=MarshmallowConverter())

Note

This converter is an optional feature and requires the marshmallow package. For example, here’s how to install this feature using pip:

$ pip install uplink[marshmallow]