Skip to main content

Python API for UniFi Video

Project description

unifi-video-api

Build Status Documentation Status

Python API for interfacing with UniFi Video.

Supported UniFi Video versions: v3.9.12 to v3.10.13

Supported Ubiquiti camera models: UVC, UVC G3, UVC G3 Dome, UVC Dome, UVC Pro, UVC G3 Pro, UVC G3 Flex, UVC Micro, UVC G3 Micro, airCam, airCam Dome, and airCam Mini, UVC G4 Bullet, UVC G4 Pro.

Features

For a single UniFi Video server:

  • Support both username/password and API key auths
  • Provide GET, POST, PUT, and DELETE methods
  • Handle session tracking and login when necessary
  • Provide iterable collections for cameras and recordings that the UniFi Video server is aware of

Per camera:

  • Set or show picture settings: brightness, contrast, saturation, hue, denoise, sharpness, dynamic range
  • Set or show IR led state
  • Set or show on-display text
  • Set or show timestamp state
  • Set or show watermark/logo state
  • Set recording mode to fulltime, motion, or disabled
  • Set recording pre/post padding
  • Take and download pictures (snapshots)
  • Download camera footage between arbitrary start and end times

Per recording:

  • Delete
  • Download
  • Snapshot (thumbnail) download

Installation

Either grab it from PyPI

pip install unifi-video

or download a release and manually place unifi_video in your project directory, or any path in $PYTHONPATH.

You shouldn't need any external libraries, unless you want to run the tests or build the docs (see requirements_dev.txt). unifi-video-api does use the six library but will fallback to using the included six should it fail to import six from system level packages.

Both python 2.7+ and python3 are supported.

Usage

See the docs for an API reference.

from unifi_video import UnifiVideoAPI

# Default kwargs: addr = 'localhost', port = 7080, schema = http
uva = UnifiVideoAPI(username='username', password='password', addr='10.3.2.1')

# Use API key (can be set per user in Unifi NVR user settings)
uva = UnifiVideoAPI(api_key='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', addr='10.3.2.1')

# Skip version checking
uva = UnifiVideoAPI(api_key='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', addr='10.3.2.1',
  check_ufv_version=False)

# Use HTTPS and skip cert verification
uva = UnifiVideoAPI(api_key='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', addr='10.3.2.1',
  port=7443, schema='https', verify_cert=False)

# Save snapshot from camera whose id, name or onscreen display text
# is "Garage"
uva.get_camera('Garage').snapshot('some/path/snapshot.jpg')

# List all cameras UniFi Video is aware of
for camera in uva.cameras:
  print(camera)

# Save snapshot from every currently online camera managed by the UniFi Video
# instance. Default filepath: # ./snapshot_{camera ID}_{timestamp}.jpg
for camera in uva.active_cameras:
  camera.snapshot()

# List all cameras managed by the UniFi Video instance, online or not
for camera in uva.managed_cameras:
  camera.snapshot()

# Get footage from camera "Garage" for specific timespan.
# (The resulting file will be 0 bytes when no footage is found.)
uva.get_camera('Garage').recording_between('2018-12-01 00:00:00',
  '2018-12-01 00:05:00')

# Specify filename
uva.get_camera('Garage').recording_between('2018-12-01 00:00:00',
  '2018-12-01 00:05:00', 'first_mins_of_dec.mp4')

# Change onscreen display text
uva.get_camera('Garage').set_onscreen_text('Home garage')

# Set IR leds to auto mode
uva.get_camera('Garage').ir_leds('auto')

# Turn off IR leds (manual mode implied)
uva.get_camera('Garage').ir_leds('off')

# Turn on IR leds (manual mode implied)
uva.get_camera('Garage').ir_leds('on')

# Set camera to record at all times and to pre capture 5 secs
uva.get_camera('Garage').set_recording_settings('fulltime',
  pre_padding_secs=5)

# Set camera to record motion events only
uva.get_camera('Garage').set_recording_settings('motion')

# Disable recording altogether
uva.get_camera('Garage').set_recording_settings('disable')

# List recordings whose details were fetched during initialization
for rec in uva.recordings:
  print(rec)

# Download recording, write to local file recording01.mp4
uva.recordings['xxxxxxxxxxxxxxxxxxxx'].download('recording01.mp4')

Warning

This software has been tested against a limited set of API versions and hardware. While unlikely, should any of the POST payloads result in software or hardware failure, the maintainer of this package is not liable.

Proceed at your own risk.

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

unifi-video-0.3.1.tar.gz (26.4 kB view details)

Uploaded Source

File details

Details for the file unifi-video-0.3.1.tar.gz.

File metadata

  • Download URL: unifi-video-0.3.1.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.21.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for unifi-video-0.3.1.tar.gz
Algorithm Hash digest
SHA256 cdcfb3cb00942c12fb91a1cef77f8b21223f71a4f94d7f2710fddd0d1a97e255
MD5 808632a7a278ff9ecb671a3be175d447
BLAKE2b-256 427cc7df540910949722c021ee928d4e4459d72d82598e1f036d4dbc0eda4ce8

See more details on using hashes here.

Supported by

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