A Declarative HTTP Client for Python.
Project description
Python HTTP Made Expressive. Inspired by Retrofit.
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 latest stable release, you can use pip:
$ pip install uplink
Interested in the cutting-edge? You can install the work-in-progress for the upcoming release with:
$ pip install https://github.com/prkumar/uplink/archive/develop.zip
Documentation
For more details, check out the documentation at http://uplink.readthedocs.io/.
Contributing
Looking to report a bug, request a feature, or contribute code to Uplink? Checkout the Contribution Guide ! Thanks for taking the time to improve an open source project!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for uplink-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14db2f6b8a8685edd238e2a080963f81c44a6838781411d19ba4886000cbdd89 |
|
MD5 | 0460ef73209afc91c3a04c797ebbdaaa |
|
BLAKE2b-256 | 06c9c364d22de314963f92dbb189b0dfd9f66cc20553c8be1a51639a18d2a544 |