Skip to main content

A Declarative HTTP Client for Python.

Project description

Python HTTP Made Expressive. Inspired by Retrofit.

PyPI Version Build Status Coverage Status Documentation Status

A Quick Walkthrough, with GitHub API v3

Using decorators and function annotations, you can turn any plain old Python class into a self-describing consumer of your favorite HTTP webservice:

from uplink import *

# To register entities that are common to all API requests, you can
# decorate the enclosing class rather than each method separately:
@headers({"Accept": "application/vnd.github.v3.full+json"})
class GitHub(object):

    @get("/users/{username}")
    def get_user(self, username):
        """Get a single user."""

    @json
    @patch("/user")
    def update_user(self, access_token: Query, **info: Body):
        """Update an authenticated user."""

To construct a consumer instance, use the helper function uplink.build:

github = build(GitHub, base_url="https://api.github.com/")

To access the GitHub API with this instance, we simply invoke any of the methods that we defined in the interface above. To illustrate, let’s update my GitHub profile bio:

response = github.update_user(oauth_token, bio="Beam me up, Scotty!").execute()

Voila, update_user(...) seamlessly builds the request (using the decorators and annotations from the method’s definition), and execute() sends that synchronously over the network. Furthermore, the returned response is a requests.Response (documentation):

print(response.json()) # {u'disk_usage': 216141, u'private_gists': 0, ...

In essence, Uplink delivers reusable and self-sufficient objects for accessing HTTP webservices, with minimal code and user pain ☺️.

Installation

uplink supports Python 2.7 & 3.3-3.7. To install the package, you can use pip:

$ pip install uplink

Documentation

For more details, check out the documentation at http://uplink.readthedocs.io/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uplink-0.1.0.tar.gz (19.0 kB view hashes)

Uploaded Source

Built Distribution

uplink-0.1.0-py2.py3-none-any.whl (18.3 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page