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.1.tar.gz
(4.2 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.1.tar.gz.
File metadata
- Download URL: multifuncpy-0.1.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90c33b8a9cb869cd59a8f930da647b031775088255fbbf23f601e63776da6e90
|
|
| MD5 |
21797852148e8b85925573acc0f72fad
|
|
| BLAKE2b-256 |
1031183201e4740dbdb2f558ea4012f38d476547b8b9ef5b2c977eddc38c6bfd
|
File details
Details for the file multifuncpy-0.1.1-py3-none-any.whl.
File metadata
- Download URL: multifuncpy-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.5 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 |
54ab169c7dd232af9ae157e37c9a7f64104c752b5d7edfce073d8617c25af2e5
|
|
| MD5 |
bd01404b75b24d588a422e44e73d0c87
|
|
| BLAKE2b-256 |
573f6154861c3250a81b39e1d9fae69bd74806a11c62a96e8eadfd0f33f04dfc
|