Python library for HikCentral Open API
Project description
HikCentral OpenAPI Client
A Python async client library for interacting with the HikCentral OpenAPI.
This package provides typed models and helper methods for common resource and ACS workflows, including:
- Version discovery and client initialization
- Organization management
- Access level retrieval and assignment
- Person lifecycle management (including face updates)
Installation
Install with uv:
uv pip install hikcentral-openapi
Or with pip:
pip install hikcentral-openapi
Quick Start
Initialize the Client
from hikcentral_openapi import Client
client = Client(
user_key="your-user-key",
user_secret="your-user-secret",
host="localhost",
port=443,
)
await client.initialize()
print(client.version)
Use a Custom httpx.AsyncClient
import httpx
from hikcentral_openapi import Client
httpx_client = httpx.AsyncClient(verify=False)
client = Client(
user_key="your-user-key",
user_secret="your-user-secret",
httpx_client=httpx_client,
)
Usage Examples
Organizations
# Get all organizations
orgs = await client.get_organization()
# Filter organizations by name
filtered_orgs = await client.get_organization(name="Head Office")
# Get the root organization
root = await client.get_root_organization()
# Add organization under root automatically
new_org = await client.add_organization(name="Engineering")
# Add organization under explicit parent
child_org = await client.add_organization(
name="R&D",
parent_id=new_org.org_id,
)
# Update organization
child_org.org_name = "Research and Development"
await client.update_organization(child_org)
# Delete organization
await client.delete_organization(org_id=child_org.org_id)
Access Levels
# Retrieve all access levels
access_levels = await client.get_access_level()
# Assign one access level to one or more persons
level = access_levels[0]
await client.assign_access_level(
access_level=level,
person_id=["person-id-1", "person-id-2"],
)
# Remove assignment
await client.unassign_access_level(
access_level=level,
person_id=["person-id-2"],
)
Persons
from datetime import datetime, timezone
from hikcentral_openapi.models import Card, Person
# Get person by ID
person = await client.get_person(person_id="person-id-1")
# Search persons by name
persons_by_name = await client.get_person(name="John")
# Search persons by card number
persons_by_card = await client.get_person(card_no="1234567890")
# Add new person
new_person = Person(
person_code="EMP-0001",
person_name="John Doe",
org_index_code="org-index-code",
phone_no="+1-555-1000",
email="john.doe@example.com",
cards=[Card(card_no="1234567890")],
begin_time=datetime.now(timezone.utc),
)
new_person_id = await client.add_person(new_person)
# Update person
new_person.person_id = new_person_id
new_person.person_name = "John A. Doe"
await client.update_person(new_person)
# Update person face (face_data is expected as base64 string)
await client.update_person_face(
person_id=new_person_id,
face_data="base64-encoded-face-image",
)
# Delete person
await client.delete_person(person_id=new_person_id)
Data Models
Main models are available in hikcentral_openapi.models:
OrganizationAccessLevelPersonCardFaceCustomField
Error Handling
The library raises typed exceptions from hikcentral_openapi.exceptions:
HikApiError: Base exceptionConnectError: Transport-level connection errorsUnauthorizedError: Authentication/authorization failuresRequestError: API request or validation errors returned by the server
from hikcentral_openapi import Client, HikApiError
try:
await client.initialize()
except HikApiError as err:
print(f"HikCentral API error: {err}")
API Reference
- Client implementation:
src/hikcentral_openapi/client.py - Models:
src/hikcentral_openapi/models.py - Exceptions:
src/hikcentral_openapi/exceptions.py
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 Distribution
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 hikcentral_openapi-0.1.1.tar.gz.
File metadata
- Download URL: hikcentral_openapi-0.1.1.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7de39bfe0505db5c1f872e6ba3d2daa76be1f06da3f2c022241891ef0d2d2a13
|
|
| MD5 |
25ad2653c85da9234837e3dd9810e13a
|
|
| BLAKE2b-256 |
f37c420b3e0b17f857273650f05afef8ae92efaa18189d8d559fd7b9865ae44e
|
File details
Details for the file hikcentral_openapi-0.1.1-py3-none-any.whl.
File metadata
- Download URL: hikcentral_openapi-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca4d7f8f54ab227e8e31f5f159c3726fe3cb493074edca11e9aa5796d553d1f0
|
|
| MD5 |
bdb6ff703118a62b296ff21a2771dc8d
|
|
| BLAKE2b-256 |
caad9d34602a0f828e467a86cfc97be6329e2f494c831ebd5680efe40e9ac537
|