Skip to main content

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

项目主页

许可证

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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_tiehu_toolkit-1.0.1-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

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

Hashes for py_tiehu_toolkit-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4737165aa431c1b4c0a572ad7b90fd082bd614da0272b9ed4989815a9b33cb8c
MD5 ed32eff78fc479d470d7838f120e9089
BLAKE2b-256 1124989d5ae1966a0a85eaeb254cac2ed157bf071b97685372c5bd2fa99720a9

See more details on using hashes here.

File details

Details for the file py_tiehu_toolkit-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for py_tiehu_toolkit-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a6a646babd1a5224af56cfa60acd8da1aea9a16fdde78a2412a25c0ba0003012
MD5 c9ebcdff55f4a6bbdb991f77321311ce
BLAKE2b-256 3d115910a26cce413413e862d64cbd72a93c36afac58a66b62f4c78402d88180

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

This release

1.0.1 This release

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page