Skip to main content

lorawan-connection

Documentation · Building a device library

Backend-neutral LoRaWAN events and device collections for Python 3.12+. The base package has no runtime dependencies. Install the optional ChirpStack backend to connect to a server.

Feed inventory and live events into a vendor DeviceCollection. It creates supported models and reports them through device-added callbacks. Consumers then observe model state. The caller owns the network connection.

from lorawan_connection import Device, DeviceCollection, DeviceDescriptor, DeviceEvent


class Sensor(Device[float | None]):
    vendor_id = 123
    catalog_model_id = "known-model"

    def __init__(self, descriptor: DeviceDescriptor) -> None:
        super().__init__(descriptor, state=None)

    def handle_event(self, event: DeviceEvent) -> None:
        # Decode an event, assign self.state, then call self.notify().
        pass


class Sensors(DeviceCollection[Sensor]):
    DEVICES = (Sensor,)


sensors = Sensors(network_id="my-network")
stop = sensors.subscribe_device_added(lambda device: print(device.descriptor.name))
# Feed inventory and live events into sensors.handle_event(event).

The collection builds its catalog lookup from DEVICES. You can also pass classes at construction: DeviceCollection([Sensor], network_id="my-network"). The Device base supplies typed state, add_update_listener(), notify(), and cleanup. Listeners take no arguments and read the model's state after a complete update.

Install

pip install lorawan-connection

The quickstart replays a SenseCAP S2101 capture and prints 21.4 °C and 31.4% humidity.

Included

  • Read-only event and payload Protocols. Generated payloads can pass by reference.
  • Immutable descriptors and fixture dataclasses for every supported event payload.
  • A typed Device base with synchronous update listeners and explicit notifications.
  • A generic DeviceCollection with inventory replay, model replacement, and retirement.
  • Synchronous callback helpers with independent, idempotent unsubscribe functions.
  • Typed exports (py.typed), a tested SenseCAP example, and Astro/Starlight documentation.

The optional lorawan_connection.chirpstack backend supplies inventory and live events. The application owns its connection lifecycle; provisioning, QR parsing, and vendor decoders belong in separate libraries. The SenseCAP implementation under examples/ illustrates a separate device library.

Events are live notifications. The package does not persist history, reconnect a transport, or request replay after a gap. Providers report inventory before activity. Collections select models from catalog identity, never from names or payload guesses.

Device-library CLI

Pass the library's supported model classes to the shared helper:

from lorawan_connection.cli_helper import run
from my_sensors import Sensors

run(Sensors.DEVICES)

The helper discovers supported devices and prints their state. Models supply catalog identity, state, and update listeners through the shared Device base. Use --list for inventory or --json for machine-readable output.

pip install "lorawan-connection[chirpstack]"
python -m my_sensors --server https://chirpstack.example.com:443 --api-key-file /path/to/key

See the CLI guide and ChirpStack backend.

Migrating from 0.2

Rename model product_id to catalog_model_id. Replace state callbacks with add_update_listener(callback); callbacks take no arguments and read device.state. Models can inherit Device[StateT], initialize it with super().__init__(descriptor, state=initial_state), and call self.notify() after updating state. Declare DEVICES on the collection to replace manual lookup dictionaries.

Models now inherit Device[StateT]. Pass the network ID by keyword when constructing a collection: Sensors(network_id="my-network"). Existing _create_device() overrides remain available for custom matching.

Home Assistant

The Home Assistant guide covers provider subscriptions, discovery, config-entry lifecycle, and entities that observe library models. The provider API described there exists on the linked Core POC branch; it is not yet an upstream HA API.

Development

uv sync --group compatibility
uv run ruff check .
uv run ruff format --check .
uv run mypy
uv run pytest --cov --cov-report=term-missing
uv run python examples/replay.py
cd docs
npm ci
npm run build

CI tests Python 3.12, 3.13, and 3.14. Compatibility tests check the payload contracts against chirpstack-api==4.19.0. The optional backend uses the same bindings. The documentation build validates internal links and produces llms.txt.

The repository follows the packaging, documentation, and release approach of modbus-connection. The source version stays 0.0.0; the publish workflow sets the version from the release tag. See releasing for the first PyPI release setup.

Metadata

Release files for lorawan-connection 0.3.0

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

Source distribution (sdist)

Source distribution for lorawan-connection 0.3.0
File Size Uploaded
lorawan_connection-0.3.0.tar.gz 47.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lorawan-connection 0.3.0
File Interpreter ABI Platform
lorawan_connection-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 67.3 kB

Release files / lorawan_connection-0.3.0.tar.gz

Download URL lorawan_connection-0.3.0.tar.gz
Size 47.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c256320e01e86b404555e2849ed688462fca7e05626c3bb285b7e45fbcdb64f7
BLAKE2b-256 checksum
How to use checksums
230b604a38d39f6f2412e36fee38c6012c1a56635eeba892fb2bf94734fcbc44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log

Release files / lorawan_connection-0.3.0-py3-none-any.whl

Download URL lorawan_connection-0.3.0-py3-none-any.whl
Size 20.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f2d7fadf55d3878323799f435800e1d6ac7f80c13e943ff0cbbf5acf58590d15
BLAKE2b-256 checksum
How to use checksums
777bab85c861720ef48ce3a8413fd283361df1211a13a8b26d34b3c433aa2ec3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log

Release history Release notifications | RSS feed

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.14.1

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

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