Response Deserialization with Marshmallow
Many modern Web APIs deliver content as JSON objects. To abstract away the data source, we often want to convert that JSON into a regular Python object, so that other parts of our code can interact with the resource using well-defined methods and attributes.
This example illustrates how to use Uplink with
have your JSON API return Python objects.
Uplink's integration with
marshmallow is an optional feature. You
can either install
marshmallow separately or declare the extra when
installing Uplink with
$ pip install -U uplink[marshmallow]
This example includes three files:
schemas.py: Defines our schemas for repositories and contributors.
github.py: Defines a
GitHubAPI with two methods:
GitHub.get_repos: Gets all public repositories. Uses the repository schema to return
GitHub.get_contributors: Lists contributors for the specified repository. Uses the contributors schema to return
main.py: Connects all the pieces with an example that prints to the console the contributors for the first 10 public repositories.
as a guide, rewrite
main.py to make non-blocking requests using