PyTiehu 是铁虎停车场管理系统的 Python SDK,提供同步和异步两种调用方式,实现完整的请求签名机制,用于与铁虎停车场管理系统进行 API 交互。
Project description
PyTiehu - 铁虎停车场 API Python SDK
PyTiehu 是铁虎停车场管理系统的 Python SDK,提供同步和异步两种调用方式,实现完整的请求签名机制,用于与铁虎停车场管理系统进行 API 交互。
功能特性
- ✅ 自动生成请求签名(MD5 算法)
- ✅ 支持同步/异步 HTTP 请求
- ✅ 自动添加公共请求参数(parkingId、timestamp、sign)
- ✅ 灵活的客户端配置选项
- ✅ Pydantic 响应模型支持
安装
pip install py_tiehu
快速开始
同步客户端
from py_tiehu import Pklot
# 初始化客户端
client = Pklot(
base_url="https://isc.example.com",
parking_id="park001",
app_key="your_app_secret"
)
# 发送请求
response = client.request(
url="/api/v1/parking/query",
json={"plateNo": "京A12345"}
)
# 处理响应
print(response.json())
异步客户端
import asyncio
from py_tiehu import Pklot
# 初始化客户端
client = Pklot(
base_url="https://isc.example.com",
parking_id="park001",
app_key="your_app_secret"
)
# 异步发送请求
async def main():
response = await client.async_request(
url="/api/v1/parking/query",
json={"plateNo": "京A12345"}
)
print(response.json())
asyncio.run(main())
API 文档
Pklot 类
初始化参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
base_url |
str | 是 | 停车场管理系统服务器基础 URL |
parking_id |
str | 是 | 停车场 ID |
app_key |
str | 是 | 应用密钥,用于生成请求签名 |
client_kwargs |
dict | 否 | 传递给 httpx.Client 的额外配置参数 |
方法
| 方法 | 说明 | 返回值 |
|---|---|---|
client() |
创建同步 HTTP 客户端 | httpx.Client |
async_client() |
创建异步 HTTP 客户端 | httpx.AsyncClient |
signature(data) |
生成请求签名 | str |
request(**kwargs) |
发送同步请求 | httpx.Response |
async_request(**kwargs) |
发送异步请求 | httpx.Response |
签名算法
签名生成步骤:
- 排除数据中的
appKey字段 - 对剩余字段按键名进行升序排序
- 将排序后的字段以
key=value格式用&连接 - 尾部拼接
appKey的 MD5 值(大写) - 对拼接后的完整字符串进行 MD5 计算并转为大写
工具函数
timestamp()
生成当前时间戳(毫秒)
from py_tiehu.utils import timestamp
ts = timestamp() # 输出示例: 1630000000000
json_find_first(expression, data)
使用 JSONPath 表达式从数据中查找第一个匹配项
from py_tiehu.utils import json_find_first
result = json_find_first("$.data[0].name", response.json())
convert_to_status_eq_1(response)
将 HTTP 响应或字典转换为 STATUS_EQ_1 模型对象
from py_tiehu.utils import convert_to_status_eq_1
result = convert_to_status_eq_1(response)
print(result.status) # 1
print(result.Data) # 响应数据
响应模型
Base
所有 API 响应的基类:
class Base(BaseModel):
status: Union[int, str] # 错误码,1表示成功,非1表示失败
message: Optional[str] # 错误信息描述
STATUS_EQ_1
成功响应模型:
class STATUS_EQ_1(Base):
status: Literal[1, "1"] # 成功,值为1
Data: Any # 成功响应数据
配置说明
默认配置
{
"base_url": "<your_base_url>",
"verify": False, # 禁用 SSL 证书验证
"timeout": 120 # 超时时间 120 秒
}
自定义配置
client = Pklot(
base_url="https://isc.example.com",
parking_id="park001",
app_key="your_app_secret",
client_kwargs={
"timeout": 60,
"verify": True,
"headers": {"X-Custom": "value"}
}
)
示例
查询车辆信息
response = client.request(
url="/api/v1/vehicle/query",
json={
"plateNo": "京A12345",
"parkingId": "park001"
}
)
批量查询
response = client.request(
url="/api/v1/vehicle/batch",
json={
"plateNos": ["京A12345", "京B67890"],
"pageIndex": 1,
"pageSize": 20
}
)
主页
https://gitee.com/guolei19850528/py_tiehu
许可证
MIT License
开发
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
py_tiehu-0.1.0.tar.gz
(9.7 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-0.1.0.tar.gz.
File metadata
- Download URL: py_tiehu-0.1.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1800c1fdb20429806045479d32feb5fe13c628ac3458a0842fceaf1b7f6c2ef2
|
|
| MD5 |
3d4a8330f0d2bc00fbbdd9d9876987b9
|
|
| BLAKE2b-256 |
ecb05f2418f498cd18f7941665ee7ae3fa796e7f22614fcf06312e69e6a6b7ff
|
File details
Details for the file py_tiehu-0.1.0-py3-none-any.whl.
File metadata
- Download URL: py_tiehu-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae946207374f28dde9ddd9e60313eba6afeabe3472e976b5c033d73d3037e599
|
|
| MD5 |
67c03f1156cb463f350d96cdd7a37a8d
|
|
| BLAKE2b-256 |
46d5d9ab6116b5753ceb8301b258dc874a654a5fa93b4c4798e4a335f0c4d0ac
|