Skip to main content

ViewtronCamera

Overview

ViewtronCamera is an HTTP client for sending commands to Viewtron IP cameras. It provides device information and license plate database management (CRUD operations). Uses Basic HTTP authentication, so no manual login step is needed -- just provide credentials in the constructor and start calling methods.

from viewtron import ViewtronCamera

camera = ViewtronCamera(host="192.168.1.108", username="admin", password="password123", port=80)
info = camera.get_device_info()
print(info["deviceName"])

Constructor

ViewtronCamera(host, username, password, port=80)
ParameterTypeDefaultDescription
hoststrrequiredCamera IP address or hostname
usernamestrrequiredLogin username
passwordstrrequiredLogin password
portint80HTTP port

Context Manager

ViewtronCamera supports Python's with statement for clean resource handling:

with ViewtronCamera("192.168.1.108", "admin", "password123") as camera:
info = camera.get_device_info()
print(info["deviceName"])

Methods

get_device_info()

Get camera device information.

info = camera.get_device_info()
print(info["deviceName"]) # "Front Door"
print(info["model"]) # "LPR-IP4"

Returns: dict with keys:

KeyTypeExample
deviceNamestr"Front Door"
modelstr"LPR-IP4"
firmwareVersionstr"2.800.0000042.0.R"
(and more device-specific fields)

add_plate(plate_number, group_id="1")

Add a single license plate to the camera's plate database.

camera.add_plate("ABC1234")
camera.add_plate("XYZ5678", group_id="2")
ParameterTypeDefaultDescription
plate_numberstrrequiredPlate text to add
group_idstr"1"Group ID ("1" = allow list, etc.)

Returns: True on success. Raises RuntimeError on failure.


add_plates(plate_numbers, group_id="1")

Bulk add multiple plates in a single request.

plates = ["ABC1234", "DEF5678", "GHI9012"]
camera.add_plates(plates, group_id="1")
ParameterTypeDefaultDescription
plate_numberslistrequiredList of plate strings
group_idstr"1"Group ID for all plates

Returns: True on success. Raises RuntimeError on failure.


get_plates(max_results=50, offset=1, group_id="1")

Retrieve plates from the camera's database.

plates = camera.get_plates()
for plate in plates:
print(f"{plate['plate_number']} - Group {plate['group_id']}")
ParameterTypeDefaultDescription
max_resultsint50Maximum plates to return
offsetint1Starting position (1-based)
group_idstr"1"Which group to query

Returns: list of dicts, each with:

KeyTypeDescription
plate_numberstrPlate text
group_idstrGroup ID
begin_timestrValid from
end_timestrValid until
ownerstrOwner name
telephonestrContact number

Returns an empty list if the database has no plates in the requested group.


modify_plate(plate_number, group_id="1", owner=None, telephone=None)

Update metadata for an existing plate.

camera.modify_plate("ABC1234", owner="John Smith", telephone="555-0100")
ParameterTypeDefaultDescription
plate_numberstrrequiredPlate to modify (must already exist)
group_idstr"1"Group containing the plate
ownerstrNoneSet owner name
telephonestrNoneSet contact number

Returns: True on success. Raises RuntimeError on failure.


delete_plate(plate_number, group_id="1")

Remove a plate from the database.

camera.delete_plate("ABC1234")
ParameterTypeDefaultDescription
plate_numberstrrequiredPlate to delete
group_idstr"1"Group containing the plate

Returns: True on success. Raises RuntimeError on failure.


Group IDs

IPC cameras use numeric group IDs to organize plates:

Group IDMeaning
"1"Allow list (whiteList)
"2"Block list (blackList)
"3"Temporary list

Pass the group ID as a string to all plate methods. The default is "1" (allow list).


Code Examples

List All Plates

camera = ViewtronCamera("192.168.1.108", "admin", "password123")
plates = camera.get_plates(max_results=100)
for p in plates:
print(f"{p['plate_number']} | Owner: {p['owner']} | Group: {p['group_id']}")

Sync Plates from External Source

# Add plates from a CSV or database
new_plates = ["ABC1234", "DEF5678", "GHI9012", "JKL3456"]

with ViewtronCamera("192.168.1.108", "admin", "password123") as camera:
camera.add_plates(new_plates, group_id="1")
print(f"Added {len(new_plates)} plates to allow list")

Manage Plate Metadata

with ViewtronCamera("192.168.1.108", "admin", "password123") as camera:
# Add a plate with metadata
camera.add_plate("ABC1234")
camera.modify_plate("ABC1234", owner="Jane Doe", telephone="555-0199")

# Verify
plates = camera.get_plates()
for p in plates:
if p["plate_number"] == "ABC1234":
print(f"Owner: {p['owner']}, Phone: {p['telephone']}")

Authentication

ViewtronCamera uses Basic HTTP authentication. Every request sends credentials in the Authorization header. No session or login step is needed -- provide the username and password in the constructor and all methods authenticate automatically.