一个简化海康威视ISecureCenter平台API使用的Python工具包,提供设备管理、事件订阅等功能的便捷封装。
Project description
py-easy-hikvision
一个简化海康威视ISecureCenter平台API使用的Python工具包,提供设备管理、事件订阅等功能的便捷封装。
功能特性
- 认证管理:支持海康威视ISecureCenter平台的AK/SK认证
- 签名生成:自动生成符合平台要求的请求签名
- 请求头构建:自动构建符合API规范的请求头
- 同步与异步:同时支持同步和异步操作
- 响应处理:统一的响应处理机制,自动验证响应结果
- 类型提示:完整的类型注解,提供良好的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
- jsonschema
- jsonpath-ng
快速开始
基本使用
from py_easy_hikvision.isc import ISecureCenter
# 初始化ISecureCenter实例
isc = ISecureCenter(
host="https://your-isc-server:1443", # ISecureCenter平台地址
ak="YOUR_AK", # Access Key
sk="YOUR_SK" # Secret Key
)
# 发送API请求
response = isc.request(
url="/artemis/api/resource/v1/person/condition/personInfo",
json={
"paramName": "phoneNo",
"paramValue": [
"13800000000"
]
},
)
print(f"请求结果: {response.validated}")
if response.validated:
print(f"返回数据: {response.value}")
else:
print(f"错误信息: {response.json}")
异步使用
import asyncio
from py_easy_hikvision.isc import ISecureCenter
async def main():
# 初始化ISecureCenter实例
isc = ISecureCenter(
host="https://your-isc-server:1443",
ak="YOUR_AK",
sk="YOUR_SK"
)
# 异步发送API请求
response = await isc.async_request(
url="/artemis/api/resource/v1/person/condition/personInfo",
json={
"paramName": "phoneNo",
"paramValue": [
"13800000000"
]
},
)
print(f"请求结果: {response.validated}")
if response.validated:
print(f"返回数据: {response.value}")
else:
print(f"错误信息: {response.json}")
asyncio.run(main())
API文档
ISecureCenter类
初始化参数
host:ISecureCenter平台的基础URLak:Access Key,用于身份认证sk:Secret Key,用于签名生成client_kwargs:传递给httpx.Client的额外参数
方法
timestamp():生成当前时间戳(毫秒)nonce():生成随机的UUID字符串signature(string):生成请求签名headers(method, path, headers):生成符合ISecureCenter API规范的请求头client(**kwargs):创建同步客户端实例async_client(**kwargs):创建异步客户端实例request(client=None, **kwargs):同步请求方法async_request(client=None, **kwargs):异步请求方法
响应处理
所有API调用都会返回RequestResponse对象,包含以下属性:
validated:响应是否有效value:从响应中提取的值json:响应的JSON数据response:原始的httpx.Response对象
测试
运行测试用例:
python -m unittest test_isc.py
项目结构
py-easy-hikvision/
├── py_easy_hikvision/
│ ├── __init__.py # 模块初始化
│ └── isc/
│ └── __init__.py # ISecureCenter API客户端实现
├── test_isc.py # ISecureCenter测试
├── setup.py # 安装配置
├── requirements.txt # 依赖声明
├── LICENSE # 许可证
└── README.md # 项目文档
许可证
MIT License
贡献
欢迎提交Issue和Pull Request!
联系方式
- 作者:guolei
- 邮箱:174000902@qq.com
- 项目地址:https://gitee.com/guolei19850528/py_easy_hikvision
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.0-py3-none-any.whl.
File metadata
- Download URL: py_easy_hikvision-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.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 |
cf1566026e1d9f677de749f93159cae8e84890ee9da70d01343b8c1349ec6da1
|
|
| MD5 |
48739c2b8fd223c4429f4b879cd3e5da
|
|
| BLAKE2b-256 |
21321d8ba3949be55f74a91e477d54998181ddd63778d68b4316b0618a24f215
|