Introduction
This is a python module for interacting with Hikvision IP cameras and NVRs. Most rebadged models work as well with full functionality. It provides two ways to talk to a device:
HikCamera- connects to a device's ISAPI event stream and tracks event/sensor state changes in real time (motion, line crossing, tamper, I/O, disk errors, etc.), with callbacks on updates. Also supports snapshots, RTSP stream URLs, motion detection toggling, and recording search/download.ISAPIClient- a synchronous ISAPI client for querying and controlling a device: device info/capabilities, storage devices, streaming channels, cameras, I/O ports, event enable/disable, snapshots, RTSP URLs, holiday mode, and reboot.
Code is licensed under the MIT license.
Requirements
- Python 3.9+
- requests >= 2.20.0
Optional:
xmltodict>= 0.13.0 - required forISAPIClient(install with theisapiextra)- pyDispatcher 2.0.5 - only needed if you want
HikCamerato also broadcast updates viapydispatchsignals; the built-in callback mechanism (add_update_callback) works without it
Installation
pip install pyhik
To also use ISAPIClient:
pip install pyhik[isapi]
Usage - Event streaming (HikCamera)
import pyhik.hikvision as hikvision
camera = hikvision.HikCamera('http://X.X.X.X', port=80, usr='admin', pwd='1234')
# Register a callback, then start the event stream processing thread
camera.add_update_callback(lambda msg: print('Update:', msg), camera.get_id)
camera.start_stream()
print(camera.get_name, camera.current_event_states)
# ...when finished
camera.disconnect()
Callbacks
add_update_callback(callback, msg)- register a callback function, called withcam_id.event_type.channelwhenever a tracked event changes state.
Properties
get_id- unique camera/NVR idget_name- camera/NVR nameget_type- device type (CAMorNVR)current_event_states- dictionary of all tracked events and their current statecurrent_motion_detection_state- current motion detection on/off statestream_connected- whether the event stream is currently connected
Functions
start_stream()- start the event stream processing threaddisconnect()- close the event stream session and stop the processing threadget_channels()- list available channelsget_motion_detection()/enable_motion_detection()/disable_motion_detection()- read/toggle motion detectionget_snapshot(channel=1)- fetch a JPEG snapshot for a channelget_stream_url(channel=1, protocol='rtsp', stream_type=1)- build an RTSP stream URLfetch_attributes(event, channel)- get the state list for a specific sensor/channelget_recording_days(track_id, start_date, end_date)- list days that have recordingssearch_recordings(track_id, start_time, end_time, max_results=100)- search for recordings in a time rangedownload_recording(playback_uri, output_stream=None, chunk_size=65536)- download a recording found viasearch_recordings
Usage - Device control (ISAPIClient)
from pyhik.isapi import ISAPIClient
with ISAPIClient('X.X.X.X', port=80, username='admin', password='1234') as client:
print(client.get_device_name(), client.get_firmware_version())
print(client.get_capabilities())
snapshot = client.get_snapshot(channel=1)
rtsp_url = client.get_rtsp_url(channel=1)
Functions
get_device_info()/get_device_serial()/get_device_name()/get_device_model()/get_device_type()/get_firmware_version()- device identityget_capabilities()- returns aDeviceCapabilitiessummary of what the device supportsget_storage_devices()- listStorageDeviceentries (HDD/SD status, capacity)get_alarm_server_info()/ configure viarequest()- alarm server settingsget_streaming_channels()- listStreamInfofor available streamsget_cameras()- listCameraInfo(useful on NVRs with multiple channels)get_output_ports()/get_input_ports()- list I/O portsget_output_state(output_id)/set_output_state(output_id, state)- read/set an output relayget_holiday_mode_enabled()/set_holiday_mode_enabled(enabled)- read/set holiday modeget_event_states()/set_event_enabled(...)- read/toggle event detection typesget_snapshot(channel=1, stream_type=1, width=None, height=None)- fetch a snapshotget_rtsp_url(channel=1, stream_type=1, include_credentials=True)- build an RTSP stream URLreboot()- reboot the devicecustom_request(...)- issue an arbitrary ISAPI request for endpoints not otherwise wrapped
TODO
- Support IR day/night status and ability to switch between day/night/auto
Metadata
Release files for pyHik 0.4.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyhik-0.4.6.tar.gz | 36.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyhik-0.4.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 62.9 kB
Release files / pyhik-0.4.6.tar.gz
| Download URL | pyhik-0.4.6.tar.gz |
|---|---|
| Size | 36.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
50dbe20b3749e37495d76e2a582d4cfb63bf6061fec3747a52f3cb0269f0462f
|
|
BLAKE2b-256 checksum How to use checksums |
d916d13e7ef4de091b777d22adcf9027fe67685fca86b8bd34dc52e7d5e46b68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.
Transparency logRelease files / pyhik-0.4.6-py3-none-any.whl
| Download URL | pyhik-0.4.6-py3-none-any.whl |
|---|---|
| Size | 26.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3ca3cb3f86115584b6f561a222fbcddda2d88052a75824dd41f78109d0e9eb45
|
|
BLAKE2b-256 checksum How to use checksums |
9c0f3e5ef1bcce9054a07560bc2e22cc9def2d6f23d44b8cb987f018498d7eb4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.
Transparency log