A simple async HTTP client based on aiohttp
Project description
AsyncHttpClient
一个简单易用的异步HTTP客户端,基于aiohttp封装,支持链式调用。
特性
- 异步HTTP请求支持
- 链式调用API
- 自动会话管理
- 超时控制
- 统一的错误处理
- 支持自定义headers
- 支持JSON数据
安装
pip install AsyncHttpClient
快速开始
import asyncio
from async_http_client import AsyncHttpClient
async def main():
async with AsyncHttpClient() as client:
# GET请求示例
response = await client.get('https://api.example.com/users')
data = await response.json()
print(data)
# POST请求示例
response = await client.post(
'https://api.example.com/users',
json_data={"name": "test"}
)
result = await response.json()
print(result)
asyncio.run(main())
API参考
AsyncHttpClient
主要方法:
- get(url, **kwargs) - 发送GET请求
- post(url, data=None, json_data=None, **kwargs) - 发送POST请求
- put(url, data=None, json_data=None, **kwargs) - 发送PUT请求
- delete(url, data=None, json_data=None,**kwargs) - 发送DELETE请求
高级用法
from datetime import timedelta
from async_http_client import AsyncHttpClient
# 自定义配置
client = AsyncHttpClient(
base_url='https://api.example.com',
timeout=timedelta(seconds=30),
headers={'Authorization': 'Bearer token123'}
)
async def main():
# 使用上下文管理器
async with client:
response = await client.get('/users')
data = await response.json()
依赖
- Python >= 3.7
- aiohttp
许可证
MIT License
贡献
欢迎提交Issue和Pull Request!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
multifuncpy-0.1.0.tar.gz
(2.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file multifuncpy-0.1.0.tar.gz.
File metadata
- Download URL: multifuncpy-0.1.0.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da8ed3ac968bb56ec6232540b7c45420ea0f8eaa827a5f46c008693586bc9bb0
|
|
| MD5 |
c1bdeee38affba7f34f4857c52e69384
|
|
| BLAKE2b-256 |
ab1f1e70c5aa56886dec606263856a58d27f08eb54ac3b137abb8d2f0b188f72
|
File details
Details for the file multifuncpy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: multifuncpy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7e4688f776165316abf326bc33e18d547ceb881765f89f3e90d516493ae9b75
|
|
| MD5 |
d9d9f09667e2093532f2c71b635a5106
|
|
| BLAKE2b-256 |
118ca5794aee11d5f88759870ef7a908aaf6a139f26f5fd4ac56eb5866fd3b65
|