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 package, you can use pip:
$ pip install uplink
Documentation
For more details, check out the documentation at http://uplink.readthedocs.io/.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uplink-0.1.0.tar.gz.
File metadata
- Download URL: uplink-0.1.0.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe441af156260f875a00acabd082a3360709b3c3eef4b26297872afe725e41b1
|
|
| MD5 |
e7ba277271cd2b1fe6e483a1598dd4bd
|
|
| BLAKE2b-256 |
27b29378e56b228d2db664f3989ed937dba7967300128b44d114c063bbfd0562
|
File details
Details for the file uplink-0.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: uplink-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86479d00ee48b4b2cd4efd1cbb7de2b6951d8dbbf32945750d02650cc2869b60
|
|
| MD5 |
de4676045acb18872ba83db0ac75c899
|
|
| BLAKE2b-256 |
59d82b9aefccc96836d0a46b55951e5988fce33a3a82e6d3f58554524331dbc3
|