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

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.4.tar.gz (13.3 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.4-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file py_tiehu_toolkit-1.0.4.tar.gz.

File metadata

  • Download URL: py_tiehu_toolkit-1.0.4.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.11

File hashes

Hashes for py_tiehu_toolkit-1.0.4.tar.gz
Algorithm Hash digest
SHA256 97334350269fb7f9103e1f5651a8e6cf3b18a0d176e7fb92c9cadb51246d3758
MD5 75c1b409f676cd6d2b2aeb3c121a2fc5
BLAKE2b-256 4979fc660df8a1bd227d6f0135d45601165ca38c08630b7a072a84e127cf10d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_tiehu_toolkit-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cddfa9abf98f59ffcf748cd047d7d381c50633562f1f4773a429d9604a4824c8
MD5 abaf8b547b4158a9627903bd285edce1
BLAKE2b-256 050a237983bdf279a68687ba081506e55161beaacaed209cdec68d206497c378

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

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