aiohikvision
Asyncio library for Hikvision devices: ISAPI (cameras, recorders, door stations) and the SIP calls of video door stations. It is fully typed and has no Home Assistant dependency; its main user is Hikvision Virtual Indoor Station, which makes Home Assistant the indoor station of a door station.
pip install aiohikvision
Python 3.13 or newer.
A door station, over ISAPI
DoorStation is what a door station does for its indoor station, on one
authenticated link: what it is, its doors, its picture, and its speaker.
import asyncio
import os
import aiohttp
from aiohikvision import DoorStation
async def main() -> None:
async with aiohttp.ClientSession() as session:
door = DoorStation(
session,
os.environ["DOOR_HOST"],
os.environ["DOOR_USERNAME"],
os.environ["DOOR_PASSWORD"],
port=int(os.environ.get("DOOR_PORT", "80")),
)
info = await door.read_info()
print(info.identity.model, info.identity.firmware)
print("Doors:", info.doors, "Speaker:", info.talk)
# await door.open_door(1) # opens the lock of door 1
asyncio.run(main())
It also takes a snapshot (snapshot()), gives the RTSP address of the stream with
its sound (rtsp_url()), checks that the device answers (check()), and plays
G.711 through the speaker outside a call (talk(), a TwoWayAudio: one talk at a
time, a new one takes the speaker over).
Its calls, over SIP
The door station calls over SIP; its picture and sound are read over RTSP. The library is the SIP server of the door's VoIP line and the callee of its calls (why):
import asyncio
import os
from aiohikvision import CallServer, CallState, DoorCall, DoorRegistrar, DoorTransport
async def main() -> None:
door_ip = os.environ["DOOR_IP"] # the address its SIP packets come from
port = int(os.environ.get("SIP_PORT", "5060"))
transport = DoorTransport(local_addr=("0.0.0.0", port), allowed_hosts={door_ip})
tasks: set[asyncio.Task[object]] = set()
def changed(call: DoorCall) -> None:
print(call.state.value, call.callee, call.end_reason)
if call.state is CallState.RINGING:
# Refuse it: the door shows "busy". calls.answer(call.id) would answer
task = asyncio.get_running_loop().create_task(calls.reject(call.id))
tasks.add(task)
task.add_done_callback(tasks.discard)
calls = CallServer(
transport,
advertise=os.environ["MY_IP"], # this machine's address, as the door reaches it
on_change=changed,
registrar=DoorRegistrar(),
)
await calls.start()
try:
await asyncio.sleep(float(os.environ.get("SECONDS", "600")))
finally:
await calls.stop()
asyncio.run(main())
DoorTransport: UDP SIP that only hears the configured door stations, and drops theirjaKkeepalives quietly (on_keepalivetells they are alive).DoorRegistrar: accepts the REGISTER of the door's VoIP line, grants a shorter registration than it asks, and says when it registers and expires.CallServer/DoorCall: a call rings with 180 at once, then is answered, refused or hung up on command; every command names its call. Two answers at once give the call to the first. The answer is G.711 ata=ptime:40,a=sendonly,m=video 0.Talkback: the microphone to the door during a call:call.push(frame)takes 20 ms G.711 frames, and they leave as 40 ms RTP packets on an absolute clock, in bursts. The door slows its own audio when it receives 20 ms packets.aiohikvision.media.g711: reference µ-law and A-law encoders, identical to audioop on every sample, tones and 20 ms frames.
From a terminal
scripts/door_server.py runs the library as the server of a real door station,
with port 5060 free and the door's VoIP line pointing at this machine:
# Ring until the door gives up: the visitor hears the ringback
uv run python scripts/door_server.py --advertise <ha-ip> --door <door-ip> facade
# Answer after 5 s, talk in 1 kHz bursts (2 s on, 2 s off), hang up after 30 s
uv run python scripts/door_server.py --advertise <ha-ip> --door <door-ip> hybrid --answer-after 5
What the door station does
Measured on a DS-KD8003-IME1(B) with firmware V3.7.1 and V3.7.3: docs/DEVICE_FINDINGS.md. In short: point its VoIP line at your server, set its SIP audio to G.711 only (its Opus is non-standard), and expect it to cancel after its ring time (60 s) and hang up at its talk time (90 s by default).
Development
uv sync
uv run pytest --cov
uv run mypy
uv run ruff check . && uv run ruff format --check .
The tests never reach a device: they run against doubles of the measured ones
(tests/fakes), with anonymized answers. scripts/sip_probe.py is the measuring
tool of the findings; its captures stay out of the repository.
License
Apache License 2.0. The ISAPI subpackage comes from Hikvision Bridge, by yannik2480, under the same license: see NOTICE. Hikvision is a trademark of its owner; this project is not affiliated with it.
Metadata
Release files for aiohikvision 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aiohikvision-0.1.1.tar.gz | 171.8 kB | With provenance | Details for aiohikvision-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aiohikvision-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for aiohikvision-0.1.1-py3-none-any.whl |
Total release size: 275.1 kB
Release files / aiohikvision-0.1.1.tar.gz
| Download URL | aiohikvision-0.1.1.tar.gz |
|---|---|
| Size | 171.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
63156a69282b91ef6d99959f29258989d08c40b51c05b6f4035afbffa50e5bcd
|
|
BLAKE2b-256 checksum How to use checksums |
1233e92919d87e3688d2bc4b7ca049fcaa5c9755169e89fd70e28fa7ef8bae26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logRelease files / aiohikvision-0.1.1-py3-none-any.whl
| Download URL | aiohikvision-0.1.1-py3-none-any.whl |
|---|---|
| Size | 103.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1277aa38af56736023b927d11a8b30b616e2946f904ab87e88e83e3742eedfd8
|
|
BLAKE2b-256 checksum How to use checksums |
fcba035ab7fdfa43bc14b6a504b0d4f4bca602ecdb3d3b9530b8c2df21f34039
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logSecurity for aiohikvision 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for aiohikvision-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.