需要 Python 3.10 及以上版本;aiohttp、marshmallow 等异步与序列化支持需通过 extras 单独安装,如 pip install -U uplink[aiohttp, marshmallow]
pip install -U uplinkREADME 未说明,纯 Python 库,无 GPU 或显存要求
用装饰器和类型注解把 HTTP API 声明成 Python 类的客户端库
用声明式写法定义 HTTP 接口,把 REST API 调用变成 Python 函数,省去手写请求和解析响应的样板代码。
核心能力
- 用装饰器和类型提示声明每个 HTTP 请求
- 支持 JSON、URL 编码、multipart 表单与文件上传
- 可替换底层会话,兼容 Requests、aiohttp、Twisted
- 支持 marshmallow、pydantic 模型与自定义转换器
- 内置 Basic Auth,可用中间件组合响应与错误处理
容易踩的坑
- v0.10.0最新正式版2025-06-14 · 2025-06-14 20:23 UTC
What's Changed
- spelling fix by @gpflaum in https://github.com/prkumar/uplink/pull/292
- Update docs/user/serialization.rst by @yyolk in https://github.com/prkumar/uplink/pull/283
- Merge stable into master by @prkumar in https://github.com/prkumar/uplink/pull/293
- Require setuptools on install by @nealian in https://github.com/prkumar/uplink/pull/306
- Move to pydantic2 by @leiserfg in https://github.com/prkumar/uplink/pull/312
- Migrate CI pipeline to GitHub Actions by @prkumar in https://github.com/prkumar/uplink/pull/315
- Modernize python to 3.10, introduce ruff formating by @leiserfg in https://github.com/prkumar/uplink/pull/313
- Remove tj-actions/changed-files by @leiserfg in https://github.com/prkumar/uplink/pull/317
- Allow arguments initialization using subscription syntax by @whippiii in https://github.com/prkumar/uplink/pull/316
- Migrate some docs to Markdown by @prkumar in https://github.com/prkumar/uplink/pull/318
- Migrate from Travis CI to GitHub Actions by @prkumar in https://github.com/prkumar/uplink/pull/319
- Prepare for 0.10.0a1 release by @prkumar in https://github.com/prkumar/uplink/pull/320
- Set id-token: write permission for Trusted Publishing by @prkumar in https://github.com/prkumar/uplink/pull/321
- Update CONTRIBUTING.md to reflect uv usage by @leiserfg in https://github.com/prkumar/uplink/pull/323
- Handle tuples in pydantic v1 by @leiserfg in https://github.com/prkumar/uplink/pull/324
- Use optional dependencies instead of dependency groups by @whippiii in https://github.com/prkumar/uplink/pull/325
- Fix my name and add Ernesto Avilés Vázquez by @leiserfg in https://github.com/prkumar/uplink/pull/326
- Migrate to mkdocs by @prkumar in https://github.com/prkumar/uplink/pull/327
- Extract pydantic import (fixes #328) by @leiserfg in https://github.com/prkumar/uplink/pull/332
- Support marshmallow 4.0, covers #333 by @leiserfg in https://github.com/prkumar/uplink/pull/334
- Clean up some stale info and links by @prkumar in https://github.com/prkumar/uplink/pull/336
- Bump version to v0.10.0 by @prkumar in https://github.com/prkumar/uplink/pull/338
New Contributors
- @gpflaum made their first contribution in https://github.com/prkumar/uplink/pull/292
- @nealian made their first contribution in https://github.com/prkumar/uplink/pull/306
- @whippiii made their first contribution in https://github.com/prkumar/uplink/pull/316
Full Changelog: https://github.com/prkumar/uplink/compare/v0.9.7...v0.10.0
- v0.10.0a1pre-release2025-03-16 · 2025-03-16 17:16 UTC
查看更新说明
What's Changed
- Spelling fix by @gpflaum in https://github.com/prkumar/uplink/pull/292
- Update docs/user/serialization.rst by @yyolk in https://github.com/prkumar/uplink/pull/283
- Merge stable into master by @prkumar in https://github.com/prkumar/uplink/pull/293
- Require setuptools on install by @nealian in https://github.com/prkumar/uplink/pull/306
- Move to pydantic2 by @leiserfg in https://github.com/prkumar/uplink/pull/312
- Migrate CI pipeline to GitHub Actions by @prkumar in https://github.com/prkumar/uplink/pull/315
- Modernize python to 3.10, introduce ruff formating by @leiserfg in https://github.com/prkumar/uplink/pull/313
- Remove tj-actions/changed-files by @leiserfg in https://github.com/prkumar/uplink/pull/317
- Allow arguments initialization using subscription syntax by @whippiii in https://github.com/prkumar/uplink/pull/316
- Migrate some docs to Markdown by @prkumar in https://github.com/prkumar/uplink/pull/318
- Migrate from Travis CI to GitHub Actions by @prkumar in https://github.com/prkumar/uplink/pull/319
- Prepare for 0.10.0a1 release by @prkumar in https://github.com/prkumar/uplink/pull/320
New Contributors
- @gpflaum made their first contribution in https://github.com/prkumar/uplink/pull/292
- @nealian made their first contribution in https://github.com/prkumar/uplink/pull/306
- @whippiii made their first contribution in https://github.com/prkumar/uplink/pull/316
Full Changelog: https://github.com/prkumar/uplink/compare/v0.9.7...v0.10.0a1
- v0.9.72022-03-12 · 2022-03-12 04:12 UTC
查看更新说明
Fixed
- Fix behavior of async
@response_handlerwithAiohttpClient. (#256)
- Fix behavior of async
- v0.9.62022-01-24 · 2022-01-24 20:09 UTC
查看更新说明
Added
- Add a new base class,
uplink.retry.RetryBackoff, which can be extended to implement custom backoff strategies. An instance of aRetryBackoffsubclass can be provided through thebackoffargument of the@retrydecorator. (#238)
Changed
- Bump minimum version of
sixto1.13.0. (#246)
Fixed
- Fix
@returns.jsonto cast JSON response (or field referenced by thekeyargument) using thetypeargument when the given type is callable. This restores behavior that was inadvertently changed in v0.9.3. (#215) - Remove all usages of
asyncio.coroutinein the library code to fix warnings related to the function's deprecation in Python 3.8+. (#203)
- Add a new base class,
- v0.9.52022-01-04 · 2022-01-04 09:17 UTC
查看更新说明
Added
- Add Python 3.8, 3.9, and 3.10 as officially supported. (#237)
Fixed
- Fix
FieldMapandPartMapfrom raisingNoneTypeerror. (#221) - Fix Python 2.7 support. (#217)
Deprecated
- Python 2.7 support will be removed in v0.10.0.
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Uplink
- 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
marshmallowschemas,pydanticmodels, 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 3.10+.
Installation
To install the latest stable release, you can use pip (or uv):
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.prkumar.dev/.
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 💜
