Skip to main content

unetpy

unetpy is the modern Python wrapper for fjagepy. It exposes the low-level fjåge primitives alongside a batteries-included UnetSocket, Unet-specific message classes, and coordinate utilities.

Installation

From PyPI

pip install unetpy

From source

Clone the repository and install it in editable mode:

pip install -e '.[dev]'

This uses the pyproject.toml-based build powered by the standard setuptools backend.

Usage

Import the high-level API just like in unet.js:

from unetpy import (
    Gateway,
    AgentID,
    Performative,
    Message,
    MessageClass,
    UnetSocket,
    Protocol,
    Services,
    to_gps,
    to_local,
)
  • All fjåge primitives continue to be available, so legacy from unetpy import * snippets keep working.
  • Pre-defined message classes (DatagramReq, DatagramNtf, etc.) can be imported directly.
  • to_gps()/to_local() replicate the helper coordinate math from unet.js.

Pre-defined Messages and Services

Message classes mirror the UnetStack class hierarchy, so inheritance behaves exactly like it does on the modem. That means helper checks such as isinstance(rx, DatagramNtf) succeed even when rx is an RxFrameNtf. You can construct requests without manually calling MessageClass:

from unetpy import Gateway, Services, DatagramReq

gw = Gateway("localhost", 1100)
req = DatagramReq()
req.to = 31
req.protocol = 0
req.data = [1, 2, 3]
req.recipient = gw.agentForService(Services.DATAGRAM)
gw.send(req)

Working with UnetSocket

UnetSocket mirrors the JS implementation from unet.js, handling subscriptions, default addresses, and blocking receives on top of fjåge’s gateway:

from unetpy import Protocol, Services, DatagramNtf, UnetSocket

with UnetSocket("localhost", 1101) as sock:
    sock.bind(Protocol.USER)
    sock.connect(31, Protocol.USER)
    sock.send([0x01, 0x02, 0x03])

    sock.setTimeout(2000)
    ntf = sock.receive()
    if isinstance(ntf, DatagramNtf):
        print(f"Got datagram from {ntf.from_}: {ntf.data}")

    # Drop down to fjåge when you need shell access or raw agents
    gw = sock.getGateway()
    shell = gw.agentForService(Services.SHELL)
    print(shell.language)

Coordinate helpers

The coordinate math matches what unet.js exposes through toGps()/toLocal(), so you can use the same mission-planning tutorials in Python:

from unetpy import to_gps, to_local

origin = (1.25, 103.88)  # latitude, longitude
lat, lon = to_gps(origin, x=120.0, y=-45.0)
print(lat, lon)
print(to_local(origin, lat, lon))

Development

Run the unit tests with:

pytest

Documentation

Detailed documentation is available in the docs/ directory.

License

This project is licensed under the BSD 3-Clause License. See the LICENSE file for details.

Release files for unetpy 4.1.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 unetpy 4.1.1
File Size Uploaded
unetpy-4.1.1.tar.gz 22.7 kB Details

Built distribution (wheel)

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

Total release size: 39.7 kB

Release files / unetpy-4.1.1.tar.gz

Download URL unetpy-4.1.1.tar.gz
Size 22.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5041f2eb6d54a58f8119114b528ab58398b9cbed8ffd428ac739ba0cfa899fb6
BLAKE2b-256 checksum
How to use checksums
57075ebeaf7ac19d754f7f9e4c358d5efd170b55370e2e2b5c964ba13f60b573
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14

Release files / unetpy-4.1.1-py3-none-any.whl

Download URL unetpy-4.1.1-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ef032dad76965d16571b2c5c51bce572107db67349dfeae61c7cec228985850
BLAKE2b-256 checksum
How to use checksums
7b1ad522ee74573213586bdf23bd113166e3fb7928187f68e45f8321cf36f626
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14
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