Skip to main content

The client for HIKVISION cameras, DVR

Project description

[![CircleCI](https://circleci.com/gh/MissiaL/hikvision-client.svg?style=svg)](https://circleci.com/gh/MissiaL/hikvision-client)


# Python Library for Hikvision Cameras


Simple and easy to use library for working with video equipment from Hikvision.

## Install

```bash
pip install hikvisionapi
```

## Examples

There are two formats for receiving a response:


```python
from hikvisionapi import Client

cam = Client('http://192.168.0.2', 'admin', 'admin')


# Dict response (default)
response = cam.System.deviceInfo(method='get')

response == {
u'DeviceInfo': {
u'@version': u'2.0',
'...':'...'
}
}


# xml text response
response = cam.System.deviceInfo(method='get', present='text')

response == '''<?xml version="1.0" encoding="UTF-8" ?>
<DeviceInfo version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<deviceName>HIKVISION</deviceName>
</DeviceInfo>'''
```

Hints:

```python
# to get the channel info
motion_detection_info = cam.System.Video.inputs.channels[1].motionDetection(method='get')


# to send data to device:
xml = cam.System.deviceInfo(method='get', present='text')
cam.System.deviceInfo(method='put', data=xml)


# to get events (motion, etc..)
# Increase timeout if you want to wait for the event to be received
cam = Client('http://192.168.0.2', 'admin', 'Password', timeout=30)
cam.count_events = 2 # The number of events we want to retrieve (default = 1)
response = cam.Event.notification.alertStream(method='get', type='stream')

response == [{
u'EventNotificationAlert':{
u'@version': u'2.0',
u'@xmlns': u'http://www.hikvision.com/ver20/XMLSchema',
u'activePostCount': u'0',
u'channelID': u'1',
u'dateTime': u'2018-03-21T15:49:02+08:00',
u'eventDescription': u'videoloss alarm',
u'eventState': u'inactive',
u'eventType': u'videoloss'
}
}]

# Alternative solution to get events
cam = Client('http://192.168.0.2', 'admin', 'Password', timeout=1)
while True:
try:
response = cam.Event.notification.alertStream(method='get', type='stream')
if response:
print response
except Exception:
pass

# to get opaque data type and write to file
response = cam.System.configurationData(method='get', type='opaque_data')
with open('my_file', 'wb') as f:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)

# Get and save picture from camera
response = client.Streaming.channels[102].picture(method='get', type='opaque_data')
with open('screen.jpg', 'wb') as f:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
```

## How to run the tests


```bash
pipenv install --dev
pipenv run pytest
pipenv run pytest --cov-report html --cov hikvisionapi # to get coverage report in ./htmlcov/

# or you can get into the virtual env with:
pipenv shell
pytest
```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hikvisionapi-0.2.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

hikvisionapi-0.2.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file hikvisionapi-0.2.1.tar.gz.

File metadata

  • Download URL: hikvisionapi-0.2.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.14.2 setuptools/38.5.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.12

File hashes

Hashes for hikvisionapi-0.2.1.tar.gz
Algorithm Hash digest
SHA256 778faaad2208e04f06073a0c716a24e147814468f55a92d27b8868a64a04d891
MD5 1654f64f240535a75a9aa57630465bab
BLAKE2b-256 b38f16e6533accb83d9b6a52f1dfd5ae8568ca12cb1a3e45d643c87df543e5cb

See more details on using hashes here.

File details

Details for the file hikvisionapi-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: hikvisionapi-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for hikvisionapi-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 17ad4cbf35c15eab5187713fc8e068043da40346338ac4d3e50b83b5b75fc058
MD5 ab88a8f0bc2c166bbd2b66def36a0042
BLAKE2b-256 3460717351cc5e6864a26a689c2548a6c582d1015d80de136312f485b202046c

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