py-tiehu-toolkit
铁虎管理系统 API Python SDK,提供同步和异步两种调用方式,实现完整的请求签名机制,用于与铁虎停车场管理系统(Parking)和 SCMP 进行 API 交互。
功能特性
- ✅ 自动生成请求签名/Token(MD5 算法)
- ✅ 支持同步/异步 HTTP 请求
- ✅ 自动添加公共请求参数
- ✅ Pydantic 响应模型支持
- ✅ JSON Schema 响应校验
项目结构
src/py_tiehu_toolkit/
├── __init__.py # 模块入口
├── parking/ # 停车场模块
│ ├── __init__.py # Pklot 客户端类
│ ├── utils.py # 工具函数
│ └── responses.py # 响应数据模型
└── scmp/ # SCMP 模块
├── __init__.py # Scmp 客户端类
├── utils.py # 工具函数
└── responses.py # 响应数据模型
安装方式
使用 pip
pip install py-tiehu-toolkit
使用 uv(推荐)
uv add py-tiehu-toolkit
从源码安装
git clone https://gitee.com/guolei19850528/py_tiehu_toolkit.git
cd py_tiehu_toolkit
uv install .
依赖包
| 依赖 | 版本要求 | 说明 |
|---|---|---|
| httpx | >=0.27.0 | HTTP 客户端库,支持同步和异步 |
| pydantic | >=2.0 | 数据验证和序列化 |
| jsonschema | >=4.21.0 | JSON Schema 校验 |
| py-httpx-toolkit | >=1.0.1 | HTTP 工具包封装 |
快速开始
停车场模块 (Parking)
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 模块
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)
异步调用
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() |
生成毫秒级时间戳 |
build_base_instance(response) |
响应转 Base 模型 |
build_success_instance(response) |
响应转 Success 模型 |
success_is_valid(response, schema) |
校验成功响应 |
模块差异说明
| 特性 | Parking 模块 | SCMP 模块 |
|---|---|---|
| 认证方式 | sign 参数 | token 请求头 |
| 成功状态码 | status=1 |
code=0 |
| 请求参数位置 | JSON body | form data |
| 数据字段名 | Data (PascalCase) |
data (camelCase) |
| 消息字段名 | message |
msg |
作者
Guolei - 174000902@qq.com
项目主页
- 仓库: https://gitee.com/guolei19850528/py_tiehu_toolkit
- 官方文档: https://www.showdoc.com.cn/1735808258920310/9467753400037587
许可证
MIT License
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
py_tiehu_toolkit-1.0.1.tar.gz
(14.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 py_tiehu_toolkit-1.0.1.tar.gz.
File metadata
- Download URL: py_tiehu_toolkit-1.0.1.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.6.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4737165aa431c1b4c0a572ad7b90fd082bd614da0272b9ed4989815a9b33cb8c
|
|
| MD5 |
ed32eff78fc479d470d7838f120e9089
|
|
| BLAKE2b-256 |
1124989d5ae1966a0a85eaeb254cac2ed157bf071b97685372c5bd2fa99720a9
|
File details
Details for the file py_tiehu_toolkit-1.0.1-py3-none-any.whl.
File metadata
- Download URL: py_tiehu_toolkit-1.0.1-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.6.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6a646babd1a5224af56cfa60acd8da1aea9a16fdde78a2412a25c0ba0003012
|
|
| MD5 |
c9ebcdff55f4a6bbdb991f77321311ce
|
|
| BLAKE2b-256 |
3d115910a26cce413413e862d64cbd72a93c36afac58a66b62f4c78402d88180
|