A Declarative HTTP Client for Python.
Project description
Builds Reusable Objects for Consuming Web APIs.
Works with Requests, aiohttp, and Twisted.
Inspired by Retrofit.
A Quick Walkthrough, with GitHub API v3
Uplink turns your HTTP API into a Python class.
from uplink import Consumer, get, Path, Query
class GitHub(Consumer):
"""A Python Client for the GitHub API."""
@get("users/{user}/repos")
def get_repos(self, user: Path, sort_by: Query("sort")):
"""Retrieves the user's public repositories."""
Build an instance to interact with the webservice.
github = GitHub(base_url="https://api.github.com/")
Then, executing an HTTP request is as simply as invoking a method.
repos = github.get_repos(user="octocat", sort_by="created")
The returned object is a friendly requests.Response:
print(repos.json())
# Output: [{'id': 64778136, 'name': 'linguist', ...
For sending non-blocking requests, Uplink comes with support for aiohttp and twisted.
Ready to launch your first API client with Uplink? Start with this quick tutorial!
Features
Quickly Define Structured API Clients
Use decorators and type hints to describe each HTTP request
JSON, URL-encoded, and multipart request body and file upload
URL parameter replacement, request headers, and query parameter support
Bring Your Own HTTP Library
Non-blocking I/O support for Aiohttp and Twisted
Supply your own session (e.g., requests.Session) for greater control
Easy and Transparent Deserialization/Serialization
Define custom converters for your own objects
Support for marshmallow schemas, pydantic models, and handling collections (e.g., list of Users)
Extendable
Install optional plugins for additional features (e.g., protobuf support)
Compose custom response and error handling functions as middleware
Authentication
Built-in support for Basic Authentication
Use existing auth libraries for supported clients (e.g., requests-oauthlib)
Uplink officially supports Python 2.7 and 3.5+.
Note: Python 2.7 suport will be removed in v0.10.0.
Installation
To install the latest stable release, you can use pip (or pipenv):
$ pip install -U uplink
If you are interested in the cutting-edge, preview the upcoming release with:
$ pip install https://github.com/prkumar/uplink/archive/master.zip
Extra! Extra!
Further, uplink has optional integrations and features. You can view a full list of available extras here.
When installing Uplink with pip, you can select extras using the format:
$ pip install -U uplink[extra1, extra2, ..., extraN]
For instance, to install aiohttp and marshmallow support:
$ pip install -U uplink[aiohttp, marshmallow]
User Testimonials
Michael Kennedy (@mkennedy), host of Talk Python and Python Bytes podcasts-
Of course our first reaction when consuming HTTP resources in Python is to reach for Requests. But for structured APIs, we often want more than ad-hoc calls to Requests. We want a client-side API for our apps. Uplink is the quickest and simplest way to build just that client-side API. Highly recommended.
Or Carmi (@liiight), notifiers maintainer-
Uplink’s intelligent usage of decorators and typing leverages the most pythonic features in an elegant and dynamic way. If you need to create an API abstraction layer, there is really no reason to look elsewhere.
Documentation
Check out the library’s documentation at https://uplink.readthedocs.io/.
For new users, a good place to start is this quick tutorial.
Community
Use the Discussions tab on GitHub to join the conversation! Ask questions, provide feedback, and meet other users!
We’re migrating our community from Gitter to GitHub Discussions. Feel free to search our Gitter lobby for past questions and answers. However, to help us transition, please start new threads/posts in GitHub Discussions instead of Gitter.
Contributing
Want to report a bug, request a feature, or contribute code to Uplink? Checkout the Contribution Guide for where to start. Thank you for taking the time to improve an open source project :purple_heart:
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
File details
Details for the file uplink-0.9.7.tar.gz
.
File metadata
- Download URL: uplink-0.9.7.tar.gz
- Upload date:
- Size: 82.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d5bff42fedfc1bec1c2959b7a15fc1354e1a32ead33facaeadfa76f7c5d68a2 |
|
MD5 | 608b45b5ac92267f5947b4419281a501 |
|
BLAKE2b-256 | e610f93f050e6528346c78a4d96d7f92c2af0e25b98f108e4a36a96074fbd7e1 |
File details
Details for the file uplink-0.9.7-py2.py3-none-any.whl
.
File metadata
- Download URL: uplink-0.9.7-py2.py3-none-any.whl
- Upload date:
- Size: 69.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b50be0bb657ffd1c48e2c20bdf8538d512fe4b9f0520247d46249912ed19d15 |
|
MD5 | 1062821d31372d33a45d30da774f5936 |
|
BLAKE2b-256 | 66ae8b06ac29d05fa896792dd2485b236265c381a1f6c3e3fcc6fdd989b44953 |