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 DeviceCollection, DeviceDescriptor, DeviceEvent


class Sensor:
    vendor_id = 123
    product_id = "known-model"

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

    def handle_event(self, event: DeviceEvent) -> None:
        # Interpret events and update typed state here.
        pass

    def close(self) -> None:
        # Release model listeners and other model resources here.
        pass


SUPPORTED_MODELS = [Sensor]
DEVICE_MODELS: dict[tuple[int | None, str], type[Sensor]] = {
    (model.vendor_id, model.product_id): model for model in SUPPORTED_MODELS
}


class Sensors(DeviceCollection[Sensor]):
    def _create_device(self, descriptor: DeviceDescriptor) -> Sensor | None:
        model_class = DEVICE_MODELS.get(
            (descriptor.vendor_id, descriptor.catalog_model_id)
        )
        return model_class(descriptor) if model_class is not None else None


sensors = Sensors("my-network")
stop = sensors.subscribe_device_added(lambda device: print(device.descriptor.name))
# Feed all matching events into sensors.handle_event(event).
# Supported devices appear automatically when their inventory events arrive.

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 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 SUPPORTED_MODELS

run(SUPPORTED_MODELS)

The helper discovers supported devices and prints their state. Models supply catalog identity, a state property, and subscribe(callback) alongside their event lifecycle. 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.

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.2.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.2.0
File Size Uploaded
lorawan_connection-0.2.0.tar.gz 44.6 kB Details

Built distribution (wheel)

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

Total release size: 63.8 kB

Release files / lorawan_connection-0.2.0.tar.gz

Download URL lorawan_connection-0.2.0.tar.gz
Size 44.6 kB
Tags Source
SHA-256 checksum
How to use checksums
af5d6420e9823660532139a397a21a994e9ccb0a76373689728c4a4849aac218
BLAKE2b-256 checksum
How to use checksums
7c4e3c9d96eab7d1b81a64883126632469195a0ae5c466385ad51dc9da2794cc
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.2.0-py3-none-any.whl

Download URL lorawan_connection-0.2.0-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
619d0af6b828690237a913d7f41ae459cb9406ceed167dd30c396a30b36d1169
BLAKE2b-256 checksum
How to use checksums
951186de4bdf5e831045b12917bf97a91adc86830adb59cd2680503ee8ef1668
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

0.3.0

2 release files

This release

0.2.0 This release

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