Metadata-Version: 2.4
Name: py-tiehu-toolkit
Version: 1.0.0
Summary: py-tiehu 是铁虎管理系统的 Python SDK，提供同步和异步两种调用方式，实现完整的请求签名机制，用于与铁虎停车场管理系统（Parking）和 SCMP 进行 API 交互。
Author-email: Guolei <174000902@qq.com>
License: MIT License
        
        Copyright (c) 2026 郭磊
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://gitee.com/guolei19850528/py_tiehu_toolkit
Project-URL: Repository, https://gitee.com/guolei19850528/py_tiehu_toolkit.git
Project-URL: Documentation, https://www.showdoc.com.cn/1735808258920310/9467753400037587
Keywords: tiehu,python,client,api,铁虎,parking,scmp
Classifier: License :: OSI Approved :: MIT License
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
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: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Session
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.27.0
Requires-Dist: pydantic>=2.0
Requires-Dist: jsonpath-ng>=1.5.3
Requires-Dist: jsonschema>=4.21.0
Requires-Dist: py-httpx-toolkit>=1.0.1
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: setuptools>=61.0; extra == "dev"
Requires-Dist: twine>=4.0; extra == "dev"
Requires-Dist: black>=23.0; extra == "dev"
Requires-Dist: isort>=5.12.0; extra == "dev"
Requires-Dist: flake8>=6.0; extra == "dev"
Requires-Dist: mypy>=1.0; extra == "dev"
Dynamic: license-file

# py-tiehu-toolkit

铁虎管理系统 API Python SDK，提供同步和异步两种调用方式，实现完整的请求签名机制，用于与铁虎停车场管理系统（Parking）和 SCMP 进行 API 交互。

## 功能特性

- ✅ 自动生成请求签名/Token（MD5 算法）
- ✅ 支持同步/异步 HTTP 请求
- ✅ 自动添加公共请求参数
- ✅ Pydantic 响应模型支持
- ✅ JSON Schema 响应校验
- ✅ JSONPath 数据查询

## 项目结构

```
src/py_tiehu_toolkit/
├── __init__.py          # 模块入口
├── parking/             # 停车场模块
│   ├── __init__.py      # Pklot 客户端类
│   ├── utils.py         # 工具函数
│   └── responses.py     # 响应数据模型
└── scmp/                # SCMP 模块
    ├── __init__.py      # Scmp 客户端类
    ├── utils.py         # 工具函数
    └── responses.py     # 响应数据模型
```

## 安装方式

### 使用 pip

```bash
pip install py-tiehu-toolkit
```

### 使用 uv（推荐）

```bash
uv add py-tiehu-toolkit
```

### 从源码安装

```bash
git clone https://gitee.com/guolei19850528/py_tiehu_toolkit.git
cd py_tiehu_toolkit
uv install .
```

## 依赖包

| 依赖 | 版本要求 | 说明 |
|------|----------|------|
| httpx | >=0.27.0 | HTTP 客户端库，支持同步和异步 |
| pydantic | >=2.0 | 数据验证和序列化 |
| jsonpath-ng | >=1.5.3 | JSONPath 查询支持 |
| jsonschema | >=4.21.0 | JSON Schema 校验 |
| py-httpx-toolkit | >=1.0.1 | HTTP 工具包封装 |

## 快速开始

### 停车场模块 (Parking)

```python
from py_tiehu_toolkit.parking import Pklot
from py_tiehu_toolkit.parking.utils import build_success_instance, timestamp

# 创建同步客户端
pklot = Pklot(
    base_url="https://isc.example.com",
    parking_id="park001",
    app_key="your_app_secret"
)

# 发送请求
response = pklot.request_with_signature(url="/api/v1/query")

# 转换为响应模型
result = build_success_instance(response)
print(result.status)
print(result.Data)
```

### SCMP 模块

```python
from py_tiehu_toolkit.scmp import Scmp
from py_tiehu_toolkit.scmp.utils import build_success_instance

# 创建同步客户端
scmp = Scmp(
    base_url="https://scmp.example.com",
    appid="app001",
    secret="your_secret"
)

# 发送请求
response = scmp.request_with_token(url="/api/v1/data")

# 转换为响应模型
result = build_success_instance(response)
print(result.code)
print(result.Data)
```

### 异步调用

```python
import asyncio
from py_tiehu_toolkit.parking import Pklot

async def main():
    pklot = Pklot(
        base_url="https://isc.example.com",
        parking_id="park001",
        app_key="your_app_secret"
    )
    
    # 异步请求
    response = await pklot.async_request_with_signature(url="/api/v1/query")
    print(response.json())

asyncio.run(main())
```

## API 参考

### parking.Pklot 类

| 方法 | 说明 |
|------|------|
| `__init__(base_url, parking_id, app_key, client_kwargs)` | 初始化客户端 |
| `signature(data)` | 生成请求签名 |
| `request_with_signature(client, client_kwargs, **kwargs)` | 同步请求（带签名） |
| `async_request_with_signature(client, client_kwargs, **kwargs)` | 异步请求（带签名） |

### scmp.Scmp 类

| 方法 | 说明 |
|------|------|
| `__init__(base_url, appid, secret, client_kwargs)` | 初始化客户端 |
| `token(ts)` | 生成请求 Token |
| `request_with_token(client, client_kwargs, **kwargs)` | 同步请求（带 Token） |
| `async_request_with_token(client, client_kwargs, **kwargs)` | 异步请求（带 Token） |

### utils 工具函数

| 函数 | 说明 |
|------|------|
| `timestamp()` | 生成毫秒级时间戳 |
| `json_find_first(expression, data)` | JSONPath 查询 |
| `json_is_valid(schema, data)` | JSON Schema 校验 |
| `build_success_instance(response)` | 响应转模型 |
| `success_is_valid(response, schema)` | 校验成功响应 |


## 作者

**Guolei** - <174000902@qq.com>

## 项目主页

- **仓库**: https://gitee.com/guolei19850528/py_tiehu_toolkit
- **官方文档**: https://www.showdoc.com.cn/1735808258920310/9467753400037587

## 许可证

MIT License
