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 .

依赖包

依赖 版本要求 说明
pydantic >=2.0 数据验证和序列化
py-httpx-toolkit >=1.0.1 HTTP 工具包封装

快速开始

停车场模块 (Parking)

from py_tiehu_toolkit.parking import Pklot
from py_tiehu_toolkit.parking.responses import build_base_instance
from py_tiehu_toolkit.parking.utils import 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_base_instance(response)
print(result.is_success())
print(result.Data)

SCMP 模块

from py_tiehu_toolkit.scmp import Scmp
from py_tiehu_toolkit.scmp.responses import build_base_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_base_instance(response)
print(result.is_success())
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() 生成毫秒级时间戳

模块差异说明

特性 Parking 模块 SCMP 模块
认证方式 sign 参数 token 请求头
成功状态码 status=1 code=0
请求参数位置 JSON body form data
数据字段名 Data (PascalCase) data (camelCase)
消息字段名 message msg

作者

Guolei - 174000902@qq.com

项目主页

许可证

MIT License

Metadata

Release files for py-tiehu-toolkit 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-tiehu-toolkit 1.0.4
File Size Uploaded Provenance
py_tiehu_toolkit-1.0.4.tar.gz 13.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for py-tiehu-toolkit 1.0.4
File Interpreter ABI Platform
py_tiehu_toolkit-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 31.5 kB

Release files / py_tiehu_toolkit-1.0.4.tar.gz

Download URL py_tiehu_toolkit-1.0.4.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
97334350269fb7f9103e1f5651a8e6cf3b18a0d176e7fb92c9cadb51246d3758
BLAKE2b-256 checksum
How to use checksums
4979fc660df8a1bd227d6f0135d45601165ca38c08630b7a072a84e127cf10d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.11

Release files / py_tiehu_toolkit-1.0.4-py3-none-any.whl

Download URL py_tiehu_toolkit-1.0.4-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cddfa9abf98f59ffcf748cd047d7d381c50633562f1f4773a429d9604a4824c8
BLAKE2b-256 checksum
How to use checksums
050a237983bdf279a68687ba081506e55161beaacaed209cdec68d206497c378
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.11

Security for py-tiehu-toolkit 1.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page