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)
| Parameter | Type | Default | Description |
|---|---|---|---|
host | str | required | Camera IP address or hostname |
username | str | required | Login username |
password | str | required | Login password |
port | int | 80 | HTTP 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:
| Key | Type | Example |
|---|---|---|
deviceName | str | "Front Door" |
model | str | "LPR-IP4" |
firmwareVersion | str | "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")
| Parameter | Type | Default | Description |
|---|---|---|---|
plate_number | str | required | Plate text to add |
group_id | str | "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")
| Parameter | Type | Default | Description |
|---|---|---|---|
plate_numbers | list | required | List of plate strings |
group_id | str | "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']}")
| Parameter | Type | Default | Description |
|---|---|---|---|
max_results | int | 50 | Maximum plates to return |
offset | int | 1 | Starting position (1-based) |
group_id | str | "1" | Which group to query |
Returns: list of dicts, each with:
| Key | Type | Description |
|---|---|---|
plate_number | str | Plate text |
group_id | str | Group ID |
begin_time | str | Valid from |
end_time | str | Valid until |
owner | str | Owner name |
telephone | str | Contact 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")
| Parameter | Type | Default | Description |
|---|---|---|---|
plate_number | str | required | Plate to modify (must already exist) |
group_id | str | "1" | Group containing the plate |
owner | str | None | Set owner name |
telephone | str | None | Set 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")
| Parameter | Type | Default | Description |
|---|---|---|---|
plate_number | str | required | Plate to delete |
group_id | str | "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 ID | Meaning |
|---|---|
"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.
Related Pages
- LPR Events -- receiving plate detection events from cameras
- ViewtronServer -- HTTP server for receiving camera webhook events
- ViewtronEvent -- parsing events returned by the server