GU

goduni/unihttp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

61 stars 质量 65 趋势 21MIT

用于创建声明式API客户端的现代库。

概览

是一个用于创建声明式API客户端的现代库。 - : 定义使用标准 Python 类型提示的 API 方法。- : 完全支持静态类型检查。- : 支持 httpx、httpx2、aiohttp、requests、niquests、zapros 及标准库 urllib。- : 强大的中间件和错误处理系统。 为了包含特定的HTTP后端(推荐): 标准库 urllib 后端(UrllibSyncClient)不需要额外内容——它开箱即用,只需一个普通的 pip 安装 unihttp,这对无依赖环境非常实用。 UniHTTP 允许您选择偏好的序列化框架: 1. (推荐):为标准 Python 类型(dataclasss、TypedDict)提供高性能序列化。2. :原生支持 Pydantic 模型。3. 原生支持 msgspec。struct 模型——如果你已经将模型定义为结构体并希望直接序列化,这是理想的选择。 在初始化客户端时,你需要通过相应的 request_dumper 和response_loader。

概述(AI 翻译)

unihttp 是一个用于创建声明式 API 客户端的现代库。

文献资料

目录

  • 特色
  • 安装
  • 序列化后端
  • 快速入门
  • 1.定义方法
  • 2.客户实施策略
  • 标记参考
  • 流式方法
  • 中间件
  • 按调用和按方法进行中间件
  • 错误处理
  • 1.方法级处理
  • 2.客户端级处理
  • 3.中间件级别处理
  • 4.响应体验证
  • 自定义 JSON 序列化
  • 由Adaptix提供技术支持
  • 皮丹积分
  • MSGSPEC 集成
  • 特工技能

特色

  • 声明式:使用标准 Python 类型提示定义 API 方法。
  • 类型安全:完全支持静态类型检查。
  • 后端无关性:可与 httpx、httpx2、aiohttp、requests、niquests、zapros 及标准库 urllib 使用。
  • 可扩展:强大的中间件和错误处理系统。

安装

为了包含特定的HTTP后端(推荐):

标准库 urllib 后端(UrllibSyncClient)不需要额外的—— 它开箱即用普通的 pip install unihttp,这很方便于 无依赖环境。

序列化后端

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

unihttp

unihttp is a modern library for creating declarative API clients.

Documentation

Table of Contents

Features

  • Declarative: Define API methods using standard Python type hints.
  • Type-Safe: Full support for static type checking.
  • Backend Agnostic: Works with httpx, httpx2, aiohttp, requests, niquests, zapros and the standard library urllib.
  • Extensible: Powerful middleware and error handling systems.

Installation

pip install unihttp

To include a specific HTTP backend (recommended):

pip install "unihttp[httpx]"    # For HTTPX (Sync/Async) support
# OR
pip install "unihttp[httpx2]"   # For HTTPX2 (Sync/Async) support
# OR
pip install "unihttp[niquests]"  # For niquests (Sync/Async) support
# OR
pip install "unihttp[requests]" # For Requests (Sync) support
# OR
pip install "unihttp[aiohttp]"  # For Aiohttp (Async) support
# OR
pip install "unihttp[zapros]"   # For Zapros (Sync/Async) support

The standard library urllib backend (UrllibSyncClient) requires no extra — it works out of the box with a plain pip install unihttp, which is handy for dependency-free environments.

Serialization Backends

unihttp allows you to choose your preferred serialization framework:

  1. Adaptix (recommended): High-performance serialization for standard Python types (dataclasses, TypedDict).
在 GitHub 查看完整 README

推荐工具

换一个关键词,或者移除筛选条件。

安装

npx skillfish add goduni/unihttp
新手?先看 mcpskill.org 教程 →