Skip to main content

一个简化海康威视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平台的基础URL
  • ak: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!

联系方式

Project details


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

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

py_easy_hikvision-1.0.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file py_easy_hikvision-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_easy_hikvision-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf1566026e1d9f677de749f93159cae8e84890ee9da70d01343b8c1349ec6da1
MD5 48739c2b8fd223c4429f4b879cd3e5da
BLAKE2b-256 21321d8ba3949be55f74a91e477d54998181ddd63778d68b4316b0618a24f215

See more details on using hashes here.

Supported by

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