Skip to main content

pyswann

An unofficial, environment-agnostic, pure Python client under development for Swann DVR/NVR hardware using the RaySharp client service on TCP port 9000.

This project is not affiliated with or endorsed by Swann or RaySharp. Protocol support has been tested against one Swann recorder and firmware version; other models and firmware may behave differently.

The project deliberately has no dependency on RaySharp's DLLs or shared libraries. Protocol behaviour is added only after it is supported by SDK source evidence and confirmed against the physical Swann recorder.

Current capability

The package currently provides:

  • a bounded asyncio TCP transport;
  • explicit connection/session state;
  • recorder-confirmed encrypted RaySharp login and response parsing;
  • a managed authenticated session with encrypted type-32 heartbeats and a single protocol reader;
  • framed, decrypted motion-alarm reception (891/191);
  • combined pedestrian/vehicle (PD+VD) decoding with explicit ON/OFF state (891/251);
  • a typed async event iterator currently yielding MotionEvent and PdVdEvent;
  • typed read-only recorder and channel metadata from the HTTP API;
  • lossless timestamped capture of every received byte;
  • a diagnostic CLI that runs anywhere Python 3.12 runs;
  • no dependency on any higher-level application framework; the library is intentionally standalone and reusable outside Home Assistant.

The physical recorder now confirms authentication, heartbeat maintenance, and automatic motion-report delivery. Parallel channel/status bitmasks are decoded into explicit per-channel ON/OFF transitions.

Only MotionEvent and PdVdEvent are currently implemented because those are the event types validated against the available test recorder. RaySharp devices may emit additional alarm families, but they remain unsupported until they can be captured and decoded reliably.

Managed client

The primary library API owns authentication, heartbeat maintenance, packet reading, and typed event dispatch for the lifetime of the context manager:

from swann import MotionEvent, PdVdEvent, SwannClient

client = SwannClient(
    "ip.address or hostname",
    username="admin",
    password="recorder-password",
)

async with client:
    info = client.device_info
    if info is not None:
        print(info.model, info.firmware_version, info.preferred_identifier)

    async for event in client.events():
        if isinstance(event, MotionEvent):
            print("motion", event.channel, event.active)
        elif isinstance(event, PdVdEvent):
            print("PD+VD", event.channel, event.active)

RaySharpClient remains available as a compatibility alias for existing callers; new code should use SwannClient.

PdVdEvent intentionally represents the combined DVR category. Controlled captures show that pedestrian and vehicle detections use the same wire subtype and alarm value, so the low-level library does not invent a distinction that the recorder does not transmit.

After authentication, client.device_info contains confirmed LoginRsp fields including model, recorder name, firmware version, serial number, MAC address, channel counts, and raw advertised push/control flags. The preferred stable identifier uses the serial number when present and otherwise falls back to the MAC address.

The managed client also collects supplementary HTTP metadata after TCP login. client.http_metadata contains the recorder model, hardware and software versions, storage/video details, and typed channel aliases, enabled states, and stream descriptions. HTTP failure is exposed as client.http_metadata_error and does not stop TCP event delivery. The HTTP API is metadata-only here; TCP port 9000 remains the authoritative event source.

Each ChannelMetadata also exposes mainstream_url and substream_url. These use explicit URL fields when a recorder returns them; otherwise they use the confirmed RaySharp RTSP path with the channel number formatted as 01, 02, and so on.

The client accepts an injected aiohttp.ClientSession when a caller already has one, but it never closes a caller-owned session. For standalone use, omitting websession creates an internal session which is closed with the client. The recorder HTTP flow uses Digest authentication plus the returned CSRF token and session cookie. Credentials are not logged, and the sensitive P2P identifier returned by the recorder is intentionally not included in SystemMetadata.

Configured alarm pages can be loaded over TCP with await client.refresh_alarm_configurations(). To request them automatically before managed event reading begins, construct the client with collect_alarm_configurations=True; the default is False so devices that do not implement optional parameter pages can still provide core events.

Diagnostic connection

Copy .env.example to .env, then replace the password value. .env is ignored by Git and loaded automatically by the diagnostic CLI:

cp .env.example .env
RAYSHARP_HOST=ip.address or hostname
RAYSHARP_PORT=9000
RAYSHARP_HTTP_PORT=85
RAYSHARP_USERNAME=admin
RAYSHARP_PASSWORD=your-recorder-password
RAYSHARP_LOGIN_VARIANT=crypto

Then run from the project directory:

py -m swann.cli --output captures/connection.jsonl

To write an authenticated TCP status snapshot for review, use --status-output. This reports recorder identity, channel names and availability, motion/recording/video-loss masks, and intelligent-analysis capabilities without writing credentials or the raw login request:

py -m swann.cli --status-output captures/status.json

The status snapshot can be combined with the raw JSON Lines capture:

py -m swann.cli --output captures/connection.jsonl --status-output captures/status.json

Existing exported environment variables take precedence over .env. Set PYSWANN_ENV_FILE to load a different file.

PowerShell environment variables are also supported:

$env:RAYSHARP_HOST = "ip.address or hostname"
$env:RAYSHARP_PORT = "9000"
$env:RAYSHARP_USERNAME = "admin"
$env:RAYSHARP_PASSWORD = "your-recorder-password"

py -m swann.cli --output captures\connection.jsonl

This sends the recorder-confirmed encrypted CryptoMsgLogin packet and then an encrypted heartbeat every five seconds. Password-bearing transmit packets are always omitted from logs and captures. Incoming motion reports are logged as human-numbered channel transitions while retaining both raw bitmasks.

See docs/protocol.md for established findings, observed packet layouts, and remaining protocol questions.

Metadata

Release files for pyswann 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyswann 0.0.1
File Size Uploaded Provenance Actions
pyswann-0.0.1.tar.gz 38.4 kB Without provenance Details for pyswann-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyswann 0.0.1
File Interpreter ABI Platform Actions
pyswann-0.0.1-py3-none-any.whl Python 3 none any Details for pyswann-0.0.1-py3-none-any.whl

Total release size: 72.7 kB

Release files / pyswann-0.0.1.tar.gz

Download URL pyswann-0.0.1.tar.gz
Size 38.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5b746bb063d23bdb3f416c60f3199cd3650f3af235158eca8975b57908d3d1ce
BLAKE2b-256 checksum
How to use checksums
29cd4324e78fa71e2d40810ec6b6690a5b4051d3cdf0b3c2f41e6515bb1f977e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / pyswann-0.0.1-py3-none-any.whl

Download URL pyswann-0.0.1-py3-none-any.whl
Size 34.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc41fffe0c4ef5f9d3c4e349c0687325bdc2450318bd6a2434f7cdf112123f26
BLAKE2b-256 checksum
How to use checksums
16ea5432f81b0a77af63371ae9089a178aad1f10e4331ca397c7ceeb684a35b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for pyswann 0.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page