py_httpx_toolkit
一个对 httpx 库的轻量级封装工具包,简化了 HTTP 客户端的创建和使用,支持同步和异步两种请求模式。
功能特性
- 🚀 支持同步和异步 HTTP 客户端
- ⚙️ 支持预配置默认参数
- 🔄 支持复用已有的客户端实例
- 📡 支持统一的请求接口,自动管理客户端生命周期
安装方式
使用 pip
pip install py-httpx-toolkit
使用 uv
uv add py-httpx-toolkit
快速开始
同步请求
from py_httpx_toolkit import Httpx
# 创建 HTTP 客户端实例
http = Httpx(client_kwargs={"timeout": 30})
# 发起同步请求
response = http.request(method='GET', url='https://api.example.com/data')
print(response.status_code)
print(response.json())
异步请求
import asyncio
from py_httpx_toolkit import Httpx
async def main():
http = Httpx()
# 发起异步请求
response = await http.async_request(method='GET', url='https://api.example.com/data')
print(response.status_code)
print(response.json())
asyncio.run(main())
API 文档
Httpx 类
初始化
http = Httpx(client_kwargs=None)
client_kwargs: 客户端的默认配置参数,如 headers、timeout 等
创建同步客户端
client = http.client(**kwargs)
返回 httpx.Client 实例
创建异步客户端
async_client = http.async_client(**kwargs)
返回 httpx.AsyncClient 实例
同步请求
response = http.request(client=None, client_kwargs=None, **kwargs)
client: 已有的同步客户端实例(可选)client_kwargs: 创建新客户端时的配置参数(可选)**kwargs: 请求参数,如 method、url、headers、data、json 等
异步请求
response = await http.async_request(client=None, client_kwargs=None, **kwargs)
client: 已有的异步客户端实例(可选)client_kwargs: 创建新客户端时的配置参数(可选)**kwargs: 请求参数,如 method、url、headers、data、json 等
项目结构
py_httpx_toolkit/
├── src/
│ └── py_httpx_toolkit/
│ ├── __init__.py # Httpx 客户端封装
│ └── responses.py # 响应模型定义
├── .venv/ # 虚拟环境
├── .gitignore # Git 忽略配置
└── README.md # 项目文档
依赖
- httpx >= 0.27.0
项目主页
https://gitee.com/guolei19850528/py_httpx_toolkit
作者
郭磊
许可证
MIT License
Metadata
Release files for py-httpx-toolkit 1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| py_httpx_toolkit-1.0.7.tar.gz | 4.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| py_httpx_toolkit-1.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.7 kB
Release files / py_httpx_toolkit-1.0.7.tar.gz
| Download URL | py_httpx_toolkit-1.0.7.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8a7d1896d72b8c6a3f9d8d8fbdb5c7653cd42e3a7ed5aecb0cbf0b32c9f8e07a
|
|
BLAKE2b-256 checksum How to use checksums |
ce89199575e97a12172b24acaef9440dd394d137b270cc952171fba4b1e535b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.11
|
Release files / py_httpx_toolkit-1.0.7-py3-none-any.whl
| Download URL | py_httpx_toolkit-1.0.7-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7fd86d8f0df2507809dcbb1335fbf8a7ae713a1a1757807102ecffc0980848e
|
|
BLAKE2b-256 checksum How to use checksums |
e3533fa7423dad498020fcd0e2884695e8f2a66d80fa97e1915a02f311c63973
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.11
|
Security for py-httpx-toolkit 1.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.