Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI

on:
push:
branches: [master]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
enable-cache: true
- name: Install dependencies
run: uv sync --group dev
- name: Lint
run: uv run ruff check .
- name: Test
run: uv run pytest
- name: Build distribution
run: uv build
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 derens99

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
110 changes: 97 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,110 @@
# Vapix API Python Wrapper by Axis Communications
# vapix-python

This Python library provides a seamless wrapper around the Vapix API by Axis Communications, facilitating effortless interactions with all their cameras.
A Python wrapper for the [VAPIX API](https://developer.axis.com/vapix/) by Axis Communications, providing a clean, typed interface for controlling Axis network cameras.

## Features

- Complete Pythonic access to all Vapix API endpoints.
- Simplified methods for interacting with all cameras.
- Built with extensibility and ease-of-use in mind.
- **PTZ control** — absolute, relative, and continuous pan/tilt/zoom moves, focus, iris, brightness, presets, and home position via `com/ptz.cgi`.
- **Geolocation** — read and set the camera's configured position and heading.
- **Device parameters** — list device parameters via `param.cgi`.
- **Solid HTTP layer** — one authenticated session (digest or basic auth), HTTP or HTTPS, real per-request timeouts, and typed exceptions (`VapixAuthenticationError`, `VapixRequestError`, `VapixResponseError`).
- **Typed and tested** — full type hints and a mocked test suite that runs without camera hardware.

## Installation

To install the wrapper, you can use pip:
Not yet published to PyPI. Install from source:

TODO - PyPi hosting coming soon
```bash
pip install git+https://github.com/derens99/vapix-python.git
```

## Quick Start
Or for local development (using [uv](https://docs.astral.sh/uv/)):

```bash
git clone https://github.com/derens99/vapix-python.git
cd vapix-python
uv sync
```

## Quick start

```python
from vapix_python import VapixAPI

with VapixAPI("192.168.0.90", "root", "your-password") as api:
# Current pan/tilt/zoom
pan, tilt, zoom = api.ptz.get_current_position()

# Move the camera
api.ptz.absolute_move(pan=90, tilt=0, zoom=500, speed=50)
api.ptz.go_home(speed=100)

# Geolocation
position = api.geolocation.get_position()
print(position["lat"], position["lon"])

# Device parameters
brand = api.get_parameters(group="Brand")
```

### Connection options

```python
api = VapixAPI(
"cam.example.com",
"root",
"your-password",
timeout=10, # per-request timeout in seconds
secure=True, # use HTTPS
verify_ssl=False, # or a path to a CA bundle
auth_method="digest" # or "basic"
)
```

### Error handling

```python
from vapix_python import VapixAPI, VapixAuthenticationError, VapixRequestError

try:
with VapixAPI("192.168.0.90", "root", "wrong") as api:
api.ptz.get_current_position()
except VapixAuthenticationError:
print("Bad credentials")
except VapixRequestError as exc:
print(f"Camera unreachable or returned an error: {exc}")
```

## Development

The project uses [uv](https://docs.astral.sh/uv/) for dependency management:

```bash
uv sync # create .venv and install the package + dev dependencies
uv run ruff check . # lint
uv run pytest # run the test suite (no camera required)
uv build # build sdist and wheel
```

`pip install -e ".[dev]"` also works if you prefer plain pip.

## Migrating from 0.1.x

Import from the package root — the old CamelCase module paths were removed
(keeping them silently corrupted the package namespace when both import
styles were used in one process):

```python
from vapix_python.VapixAPI import VapixAPI
from vapix_python.VapixAPI import VapixAPI # 0.1.x — no longer works
from vapix_python import VapixAPI # 0.2.0
```

# Initialize the API caller with the base URL
vapix_api = VapixAPI(os.environ.get('host'), os.environ.get('user'), os.environ.get('password'))
Notable fixes in 0.2.0:

print(vapix_api.ptz.get_current_ptz())
```
- Request timeouts are now actually applied (previously the `timeout` argument was silently ignored, so calls could hang forever).
- `PTZControl.rename_preset_number(number, name)` now sends the number and name in the correct fields (they were swapped).
- `PTZControl.ptz_enabled(channel)` now actually queries the given channel (`info=1&camera=<channel>`; previously the channel was sent as the `info` value).
- PTZ commands the camera rejects with an `Error: ...` body now raise `VapixResponseError` instead of silently returning success.
- Geolocation responses are parsed robustly (namespaced XML supported, no stray `print()` output) and camera-reported errors raise `VapixResponseError`.
- Errors are raised as `vapix_python` exception types; `VapixRequestError` still subclasses `requests.RequestException`, so existing `except requests.RequestException:` handlers keep working.
- HTTP 401 **and** 403 raise `VapixAuthenticationError` (bad credentials vs. insufficient privileges).
54 changes: 54 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[build-system]
# hatchling >= 1.27 is needed for the PEP 639 license / license-files fields
requires = ["hatchling>=1.27"]
build-backend = "hatchling.build"

[project]
name = "vapix-python"
dynamic = ["version"]
description = "Python wrapper for the Axis Communications VAPIX camera API"
readme = "README.md"
license = "MIT"
license-files = ["LICENSE"]
requires-python = ">=3.9"
authors = [{ name = "derens99" }]
keywords = ["axis", "vapix", "camera", "ptz", "ip-camera"]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Multimedia :: Video :: Capture",
"Topic :: Software Development :: Libraries",
]
dependencies = ["requests>=2.28"]

[project.urls]
Homepage = "https://github.com/derens99/vapix-python"
Issues = "https://github.com/derens99/vapix-python/issues"

[dependency-groups]
dev = ["pytest>=7", "ruff>=0.4"]

[tool.hatch.version]
path = "src/vapix_python/__init__.py"

[tool.hatch.build.targets.wheel]
packages = ["src/vapix_python"]

[tool.ruff]
line-length = 100
target-version = "py39"
src = ["src", "tests"]

[tool.ruff.lint]
select = ["E", "F", "W", "I", "UP", "B", "SIM"]

[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "-q"
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

51 changes: 0 additions & 51 deletions src/vapix_python/GeolocationAPI.py

This file was deleted.

Loading
Loading