Skip to main content

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 等

依赖

  • httpx >= 0.27.0

项目主页

https://gitee.com/guolei19850528/py_httpx_toolkit

作者

郭磊

174000902@qq.com

许可证

MIT License

Metadata

Release files for py-httpx-toolkit 1.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-httpx-toolkit 1.0.9
File Size Uploaded Provenance
py_httpx_toolkit-1.0.9.tar.gz 4.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for py-httpx-toolkit 1.0.9
File Interpreter ABI Platform
py_httpx_toolkit-1.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 9.4 kB

Release files / py_httpx_toolkit-1.0.9.tar.gz

Download URL py_httpx_toolkit-1.0.9.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9ba046948f9f4f82f619d96802e5847391a0459efad0449948d274d9e19942dc
BLAKE2b-256 checksum
How to use checksums
b3b7b66c51393569803ef41041488def52922bf42281057cffbf4fa0cb8d73d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.11

Release files / py_httpx_toolkit-1.0.9-py3-none-any.whl

Download URL py_httpx_toolkit-1.0.9-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af134ceabbcce6a663bdb1548a681d9d0dfbcadfa4ba137b61eb2d0d81b837fd
BLAKE2b-256 checksum
How to use checksums
793c247cf1b3da1e9b4d7ca15dfabde99da4c53b691a483584898dc0e7a3ac86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.11

Security for py-httpx-toolkit 1.0.9

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page