Metadata-Version: 2.4
Name: zcl-httpkit
Version: 1.0.0
Summary: A powerful HTTP client library with interceptor chain support
Author-email: alonsolee <lizhenchang@gmail.com>
Maintainer-email: alonsolee <lizhenchang@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/alonsolee/httpkit
Project-URL: Documentation, https://github.com/alonsolee/httpkit#readme
Project-URL: Repository, https://github.com/alonsolee/httpkit.git
Project-URL: Issues, https://github.com/alonsolee/httpkit/issues
Keywords: http,client,interceptor,aiohttp,async
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Networking
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: aiohttp>=3.8.0
Requires-Dist: pydantic>=2.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: black>=23.0; extra == "dev"
Requires-Dist: isort>=5.0; extra == "dev"
Requires-Dist: mypy>=1.0; extra == "dev"

# ZCL HTTPKit

一个基于 aiohttp 的高性能 HTTP 客户端库，采用拦截器链架构，内置重试、熔断和缓存机制。

## 特性

- **拦截器模式**：受 OkHttp 启发，支持高度可扩展的拦截器链。
- **高性能**：底层基于 aiohttp，支持连接池和异步 IO。
- **健壮性**：内置重试、熔断器和超时控制。
- **自动解析**：支持 Pydantic (v1/v2) 和 dataclass 自动将响应解析为 Python 模型。
- **业务引擎**：提供 `ZCHttpEngine` 基类，方便封装业务逻辑。

## 安装

```bash
pip install .
```

## 快速开始

### 基本用法 (`ZCHttpClient`)

```python
from zcl.httpkit import ZCHttpClient, ZCHttpConfig

# 创建配置（扁平化结构）
config = ZCHttpConfig(
    default_timeout=30.0,
    max_connections=100,
    enable_logging=True,
    user_agent="ZCHttpClient/1.0.0"
)

# 创建客户端
client = ZCHttpClient(config=config)

try:
    # 等待客户端初始化就绪
    if client.wait_until_ready(timeout=10):
        # 发送 GET 请求
        response = client.get("https://httpbin.org/get", params={"key": "value"})
        if response.success:
            print(f"Status: {response.code}, Data: {response.data}")
finally:
    client.destroy()
```

### 使用业务引擎 (`ZCHttpEngine`)

```python
from zcl.httpkit import ZCHttpEngine, ZCHttpConfig
from zcl.httpkit.models import ZCHttpRequest

class MyEngine(ZCHttpEngine):
    def _setup_interceptors(self) -> None:
        # 子类可以添加自定义拦截器
        pass

    def on_request(self, request: ZCHttpRequest) -> ZCHttpRequest:
        # 发送前的统一处理
        request.headers["X-Request-ID"] = "unique-id"
        return request

# 初始化引擎
config = ZCHttpConfig(max_retries=3, cache_enabled=True)
engine = MyEngine(config=config)

# 发送请求
response = engine.get("https://httpbin.org/get")
print(response.data)

engine.destroy()
```

## 配置说明 (`ZCHttpConfig`)

所有配置项均直接在 `ZCHttpConfig` 中定义：

| 参数 | 默认值 | 说明 |
| --- | --- | --- |
| `default_timeout` | `30.0` | 默认请求超时时间（秒） |
| `max_connections` | `100` | 最大连接池大小 |
| `max_retries` | `3` | 自动重试次数 |
| `retry_delay` | `2.0` | 重试之间的延迟（秒） |
| `circuit_breaker_enabled` | `True` | 是否启用熔断器 |
| `cache_enabled` | `False` | 是否启用 GET 请求缓存 |
| `enable_logging` | `True` | 是否启用请求日志打印 |
| `verify_ssl` | `True` | 是否验证 SSL 证书 |

## 许可证

MIT
