Skip to main content

URST (Universal Reliable Serial Transport) for MicroPython

License

URST for MicroPython is a professional-grade implementation of the Universal Reliable Serial Transport (URST) protocol. It provides reliable, error-checked, and fragmented data transmission over unreliable serial (UART/XBee) connections, specifically optimized for MicroPython devices like the Raspberry Pi Pico and ESP32.

Key Features

  • Reliable Delivery: Strict stop-and-wait ARQ (Automatic Repeat Request) with configurable timeouts and retries.
  • MicroPython Optimized: Native support for machine.UART and utime.ticks_ms() for precise timing on hardware.
  • Hardware Agnostic: Works on Desktop Python (via pyserial) and MicroPython seamlessly.
  • Error Detection: Robust CRC-16/CCITT_FALSE validation for every frame.
  • Robust Framing: Uses COBS (Consistent Overhead Byte Stuffing) for zero-byte-free encoding, ensuring unambiguous frame delimiting via 0x00.
  • Message Fragmentation: Automatically handles messages larger than the physical MTU (up to 8KB+ reassembly).
  • Connection Handshake: Built-in capability negotiation and sequence synchronization.
  • Simple API: Clean send() and read() interface that abstracts away the complexity of serial framing and retransmission.

Installation

For MicroPython Devices

Option A — Source install via mip (simplest):

mpremote mip install github:simonl65/URST-mpy

Option B — Pre-compiled .mpy (smallest flash footprint, fastest startup):

Pre-compiling with mpy-cross reduces the package from ~19.7 KB to ~6.4 KB on flash and eliminates the parse-and-compile step at boot time.

# 1. Install mpy-cross (once)
pip install mpy-cross

# 2. Clone the repo and build
git clone https://github.com/simonl65/urst-mpy.git
cd urst-mpy
make mpy          # produces dist/urst/*.mpy

# 3. Deploy the compiled files to your device
mpremote cp -r dist/urst :

Option C — Copy source directly:

Copy the urst/ directory from this repository to the root of your MicroPython device's filesystem.

For Desktop Development

If you want to use it on your PC (e.g., for testing or gateway applications), install pyserial first:

pip install pyserial

Quick Start (MicroPython)

import urst
import machine
import time

# 1. Initialize UART on your device (e.g., Raspberry Pi Pico)
uart = machine.UART(0, baudrate=57600, tx=machine.Pin(0), rx=machine.Pin(1))

# 2. Initialize URST with the UART object
transport = urst.Urst(uart)

# 3. Send a message (automatically handles framing, CRC, and ACK waiting)
# It will fragment large data into ~194 byte chunks automatically.
transport.send(b"Hello from Pico!")

# 4. Read a complete message (handles reassembly of fragments)
while True:
    message = transport.read()
    if message:
        print(f"Received: {message.decode()}")
    time.sleep(0.1)

Quick Start (Desktop Python)

from urst import Urst

# Initialize URST on your serial port (requires pyserial)
transport = Urst(port="/dev/ttyUSB0", baud=57600)

transport.send(b"Hello from Desktop!")
message = transport.read()

Protocol Architecture

URST follows a strictly layered architecture to ensure separation of concerns:

┌───────────────────────────────────┐
│    Handler Layer (Application)    │  User API: send(), read()
├───────────────────────────────────┤
│     Protocol Layer (Reliable)     │  CONNECT/ACK/NAK, Retransmission
├───────────────────────────────────┤
│     Transport Layer (Framing)     │  Frame Type, Sequence Numbers
├───────────────────────────────────┤
│    Codec Layer (Encoding/IO)      │  COBS, CRC, UART (machine/pyserial)
└───────────────────────────────────┘

For full technical details, please refer to the URST Specification.

Development

Setup

This project uses uv for local development and testing.

git clone https://github.com/simonl65/urst-mpy.git
cd urst-mpy
uv sync

Running Tests

If using UV:

uv run pytest

If you aren't using UV you should set PYTHONPATH to ensure the tests find the package correctly:

PYTHONPATH=. pytest

Linting & Formatting

uv run ruff check .
uv run ruff format .

License

This project is licensed under the Sustainable Use License (SUL-1.0). See the LICENSE.md file for details.


Author: Simon R. Lincoln (oss@codeability.co.uk)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

urst_mpy-1.1.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

urst_mpy-1.1.1-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file urst_mpy-1.1.1.tar.gz.

File metadata

  • Download URL: urst_mpy-1.1.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Zorin OS","version":"18","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for urst_mpy-1.1.1.tar.gz
Algorithm Hash digest
SHA256 cdb9d3dab3293d07faf42d3d1fb90b4c6492ece21f30be52f2c95b16836a649a
MD5 4c2f0bd0a33daa97572159befa8d73f1
BLAKE2b-256 3187fd9600920759a27ed256555d91e5fec336e3be79186f5eb93eeff393deba

See more details on using hashes here.

File details

Details for the file urst_mpy-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: urst_mpy-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Zorin OS","version":"18","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for urst_mpy-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5ae1b3718e6367182cecd46d37f0871942d41665aa2e8ce91617c424ed89f52c
MD5 e45df521c589bf2103ed2e84b58ea938
BLAKE2b-256 6dde4a48d92cef4706c8909dae3465981a3121c87b6ab4b44d9f43d84f5414d2

See more details on using hashes here.

Release history Release notifications | RSS feed

3.2.0

2 files

3.1.3

2 files

3.1.2

2 files

3.1.1

2 files

3.1.0

2 files

3.0.1

2 files

3.0.0

2 files

2.0.0

2 files

1.1.2

2 files

This release

1.1.1 This release

2 files

1.1.0

2 files

1.0.3

2 files

1.0.2

2 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