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.8

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.8
File Size Uploaded Provenance
py_httpx_toolkit-1.0.8.tar.gz 4.5 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 9.4 kB

Release files / py_httpx_toolkit-1.0.8.tar.gz

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

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

Download URL py_httpx_toolkit-1.0.8-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1e47088e243203a044b2ef4732f2137a39be9355c6f3da4d8dd8a398aed2a1b
BLAKE2b-256 checksum
How to use checksums
098b4053bbf23549d2a95987f02aaa2a8320bfba56043d0c62ee5309a8b8bcf3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.11

Security for py-httpx-toolkit 1.0.8

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