uplink

prkumarMIT长期未更新

用声明式写法定义 HTTP 接口,把 REST API 调用变成 Python 函数,省去手写请求和解析响应的样板代码。

A Declarative HTTP Client for Python

v0.10.0发布于 2025-06-14 20:23 UTC1,141star67fork同步于 2026-11-07 07:32 UTC

怎么上手

由 README 提炼,执行前请确认
pip install -U uplink
硬件要求按 README 说明

README 未说明,纯 Python 库,无 GPU 或显存要求

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用装饰器和类型注解把 HTTP API 声明成 Python 类的客户端库

用声明式写法定义 HTTP 接口,把 REST API 调用变成 Python 函数,省去手写请求和解析响应的样板代码。

核心能力

  • 用装饰器和类型提示声明每个 HTTP 请求
  • 支持 JSON、URL 编码、multipart 表单与文件上传
  • 可替换底层会话,兼容 Requests、aiohttp、Twisted
  • 支持 marshmallow、pydantic 模型与自定义转换器
  • 内置 Basic Auth,可用中间件组合响应与错误处理

容易踩的坑

需要 Python 3.10 及以上版本;aiohttp、marshmallow 等异步与序列化支持需通过 extras 单独安装,如 pip install -U uplink[aiohttp, marshmallow]

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.10.0
  1. v0.10.0最新正式版2025-06-14 · 2025-06-14 20:23 UTC

    What's Changed

    New Contributors

    Full Changelog: https://github.com/prkumar/uplink/compare/v0.9.7...v0.10.0

  2. v0.10.0a1pre-release2025-03-16 · 2025-03-16 17:16 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/prkumar/uplink/compare/v0.9.7...v0.10.0a1

  3. v0.9.72022-03-12 · 2022-03-12 04:12 UTC
    查看更新说明

    Fixed

    • Fix behavior of async @response_handler with AiohttpClient. (#256)
  4. 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 a RetryBackoff subclass can be provided through the backoff argument of the @retry decorator. (#238)

    Changed

    • Bump minimum version of six to 1.13.0. (#246)

    Fixed

    • Fix @returns.json to cast JSON response (or field referenced by the key argument) using the type argument when the given type is callable. This restores behavior that was inadvertently changed in v0.9.3. (#215)
    • Remove all usages of asyncio.coroutine in the library code to fix warnings related to the function's deprecation in Python 3.8+. (#203)
  5. 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 FieldMap and PartMap from raising NoneType error. (#221)
    • Fix Python 2.7 support. (#217)

    Deprecated

    • Python 2.7 support will be removed in v0.10.0.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Uplink

    PyPI Version CI Coverage Status Code Climate GitHub Discussions Ruff Documentation

    • 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

    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 💜