海康威视 ISecureCenter Python SDK,提供简单易用的海康威视 ISecureCenter 平台 API 交互功能,支持与海康威视 ISecureCenter 平台的各种操作。
Project description
py_easy_hikvision
海康威视 ISecureCenter Python SDK,提供简单易用的海康威视 ISecureCenter 平台 API 交互功能,支持与海康威视 ISecureCenter 平台的各种操作。
功能特性
- ISecureCenter API 客户端:提供与海康威视 ISecureCenter 平台 API 交互的客户端
- 签名生成:按照海康威视 API 要求生成请求签名
- 请求头构建:自动构建符合 API 规范的请求头
- 同步/异步支持:同时支持同步和异步操作
- 灵活配置:支持通过参数自定义客户端行为
- 响应处理:提供 JSON 数据验证功能
- 类型提示:完整的类型注解,提供良好的 IDE 支持
安装
使用 pip 安装
pip install py_easy_hikvision
从源码安装
git clone https://gitee.com/guolei19850528/py_easy_hikvision.git
cd py_easy_hikvision
pip install -e .
依赖
- httpx
- py_easy_httpx
快速开始
同步请求
from py_easy_hikvision.isc import ISecureCenter
# 初始化海康威视 ISecureCenter 客户端
isc_client = ISecureCenter(
host="https://example.com",
ak="YOUR_ACCESS_KEY",
sk="YOUR_SECRET_KEY"
)
# 发送同步请求
response = isc_client.request(
url="/api/parking/info",
json={
"param1": "value1",
"param2": "value2"
}
)
print(f"请求结果: {response}")
异步请求
import asyncio
from py_easy_hikvision.isc import ISecureCenter
async def main():
# 初始化海康威视 ISecureCenter 客户端
isc_client = ISecureCenter(
host="https://example.com",
ak="YOUR_ACCESS_KEY",
sk="YOUR_SECRET_KEY"
)
# 发送异步请求
response = await isc_client.async_request(
url="/api/parking/info",
json={
"param1": "value1",
"param2": "value2"
}
)
print(f"请求结果: {response}")
asyncio.run(main())
API 文档
ISecureCenter 类
初始化参数
host: ISecureCenter 平台的基础 URLak: Access Key,用于身份认证sk: Secret Key,用于签名生成client_kwargs: 传递给 httpx.Client 的额外参数
方法
静态方法
timestamp(): 生成当前时间戳(毫秒)nonce(): 生成随机的 UUID 字符串
实例方法
signature(string=""): 生成请求签名headers(method="POST", path="", headers={}): 生成符合 ISecureCenter API 规范的请求头request(client=None, **kwargs): 同步发送请求async_request(client=None, **kwargs): 异步发送请求
高级用法
自定义客户端配置
from py_easy_hikvision.isc import ISecureCenter
# 初始化海康威视 ISecureCenter 客户端,自定义客户端配置
isc_client = ISecureCenter(
host="https://example.com",
ak="YOUR_ACCESS_KEY",
sk="YOUR_SECRET_KEY",
client_kwargs={
"timeout": 60.0, # 设置超时时间为 60 秒
"headers": {
"User-Agent": "py_easy_hikvision"
}
}
)
# 发送请求
response = isc_client.request(
url="/api/parking/info",
json={
"param1": "value1",
"param2": "value2"
}
)
print(f"请求结果: {response}")
自定义请求头
from py_easy_hikvision.isc import ISecureCenter
# 初始化海康威视 ISecureCenter 客户端
isc_client = ISecureCenter(
host="https://example.com",
ak="YOUR_ACCESS_KEY",
sk="YOUR_SECRET_KEY"
)
# 发送请求,自定义请求头
response = isc_client.request(
url="/api/parking/info",
json={
"param1": "value1",
"param2": "value2"
},
headers={
"X-Custom-Header": "custom-value"
}
)
print(f"请求结果: {response}")
项目结构
py_easy_hikvision/
├── py_easy_hikvision/ # 主包目录
│ ├── __init__.py # 包初始化文件
│ └── isc/ # ISecureCenter 模块
│ ├── __init__.py # ISecureCenter 模块初始化文件
├── README.md # 项目文档
├── setup.py # 安装配置
├── requirements.txt # 依赖列表
├── LICENSE # 许可证文件
├── deploy.sh # 部署脚本
├── .gitignore # Git 忽略文件
└── test_isc.py # 测试文件
测试
运行测试:
# 运行测试
python test_isc.py
许可证
MIT License
贡献
欢迎提交 Issue 和 Pull Request!
联系方式
- 作者:guolei
- 邮箱:174000902@qq.com
- 项目地址:https://gitee.com/guolei19850528/py_easy_hikvision
致谢
- httpx - 高性能的异步 HTTP 客户端库
- py_easy_httpx - 简化 HTTP 请求的工具包
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
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_easy_hikvision-1.0.1-py3-none-any.whl.
File metadata
- Download URL: py_easy_hikvision-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f5cbad6ba7eb3d7f7ecf9bfa51b6751a7539146b40ca64e169f5ab64f71312b
|
|
| MD5 |
0950496ad33f139ef438655a0cef8127
|
|
| BLAKE2b-256 |
63d97aaf2cddfd34b49ef0d4c1f787d9929b437c3dc203a1f7fa1b021b5f31cf
|