Skip to main content

USMP — Unified Secure Multi-transport Protocol (Python SDK)

PyPI version Python Versions License

Say goodbye to the "IoT Security Gap"! USMP is a lightweight, secure, and developer-friendly session protocol designed to bring end-to-end encrypted, mutually authenticated tunnels to ESP32, Arduino, and Python.

USMP sits between raw sockets (no security) and full TLS/DTLS (too heavy and resource-intensive for microcontrollers) — giving any constrained device a hardened, encrypted session with forward secrecy in just three function calls.

pip install usmp

Key Capabilities

  • Mutual Authentication: Both device and server verify identity using HMAC-SHA256 and a Pre-Shared Key (PSK).
  • Perfect Forward Secrecy: Ephemeral X25519 key exchange generates a fresh session key for every connection.
  • Mandatory AEAD Encryption: AES-256-GCM or ChaCha20-Poly1305. No unencrypted fallback modes.
  • Multi-Transport: Production-ready support for both TCP and UDP (with CoAP-style RTT estimation and loss recovery).
  • Built-in CLI Dev / Echo Server: Instant zero-code test server with ANSI colored badges and diagnostic payload inspection.
  • Developer-Friendly Ergonomics:
    • session.print(data) — Terminal payload inspector (auto UTF-8 vs hex dump with device ID badge and timestamps).
    • session.recv_str() — Direct UTF-8 string reception with unicode fallback handling.
    • session.send(str | bytes) — Native polymorphic payload transmission.
    • session.is_connected & session.info — Clean session state inspection.
  • Dynamic Fragmentation: Transparently fragments and reassembles payloads up to ~1.8 KB across 452-byte frames.
  • Replay Protection & Hardening: Monotonic 32-bit sequence numbers, deterministic nonces (seq || session_id[0..7]), and automatic 60-second brute-force lockout.

Quickstart

1. Instant CLI Dev / Echo Server (Zero-Code)

Test your Arduino or ESP32 hardware immediately without writing Python server code:

# Launch instant echo server with colored ANSI logs and payload inspection:
usmp-server --echo --port 9000 --psk "usmp-dev-psk-change-me-before-prod"

# Or generate a cryptographically secure 32-byte hex PSK:
usmp-server --generate-psk

Note: You can also invoke the server via Python module execution:
python -m usmp.server --echo --port 9000 --psk "..."

2. Embedded Async Python Server

Embed a custom high-performance server in your application using asyncio:

import asyncio
from usmp import USMPServer, USMPSession, USMPProtocol, ConnectionClosedError

PSK = b"usmp-dev-psk-change-me-before-prod"

server = USMPServer(host="0.0.0.0", port=9000, psk=PSK, protocol=USMPProtocol.TCP)

@server.on_session
async def handle_device(session: USMPSession):
    print(f"Device connected: {session.device_id} ({session.info})")
    try:
        while session.is_connected:
            # Direct string or raw binary reception
            text = await session.recv_str()
            
            # Built-in terminal payload inspector with ANSI badges & timestamps
            session.print(text)
            
            # Send encrypted reply (accepts str or bytes natively)
            await session.send(f"Echo: {text}")
    except ConnectionClosedError:
        print(f"Device disconnected: {session.device_id}")

async def main():
    print("Starting USMP server on port 9000...")
    await server.serve()

if __name__ == "__main__":
    asyncio.run(main())

3. Python Async Client

Connect to a remote USMP gateway from another Python service or test script:

import asyncio
from usmp import USMPClient, USMPProtocol

async def main():
    client = USMPClient(
        host="127.0.0.1",
        port=9000,
        psk=b"usmp-dev-psk-change-me-before-prod",
        protocol=USMPProtocol.TCP,
    )
    await client.connect()
    
    # Send string or bytes natively
    await client.send("Hello from Python client!")
    
    # Receive response
    reply = await client.recv_str(timeout=5.0)
    print(f"Server replied: {reply}")
    
    await client.disconnect()

if __name__ == "__main__":
    asyncio.run(main())

4. ESP32 Arduino Client (C++)

Pair your Python server with an ESP32 running Arduino:

#include <USMP.h>

#define SERVER_IP "192.168.1.100"
#define WIFI_SSID "YourNetwork"
#define WIFI_PASS "YourPassword"

static const uint8_t PSK[] = "usmp-dev-psk-change-me-before-prod";
USMPClient usmp(PSK, sizeof(PSK) - 1);

void setup() {
  Serial.begin(115200);

  // Connect WiFi and establish encrypted session (TCP or UDP)
  auto transport = USMP::TCP(SERVER_IP).wifi(WIFI_SSID, WIFI_PASS);
  if (!usmp.begin(transport)) {
    Serial.printf("Connection failed: %s (error %d)\n",
                  usmp.lastErrorString(), usmp.lastError());
    return;
  }

  // Idiomatic Arduino Print interface (zero-heap line buffering!)
  usmp.print("Telemetry: temp=");
  usmp.print(24.5);
  usmp.println("C status=OK");
}

void loop() {
  usmp.maintain(); // Keeps session alive and auto-reconnects in background

  if (usmp.available()) {
    String msg = usmp.read();
    Serial.println("Received: " + msg);
  }
}

Terminal Payload Inspector (session.print)

The Python SDK includes a built-in terminal inspector tailored for IoT debugging:

raw = await session.recv()
session.print(raw)
  • UTF-8 Payloads: Formats as a clean timestamped message with the device ID badge:

    [14:23:05] [DE:AD:BE:EF:00:01] Telemetry: temp=24.5C status=OK
    
  • Binary Payloads: Automatically falls back to an organized hex dump with length header:

    [14:23:05] [DE:AD:BE:EF:00:01] BINARY (8 bytes):
      0000: 01 02 a3 f4 00 00 ff 10
    

Cryptographic Handshake

Device                               Server
  │                                     │
  │── HELLO (device_id, pub_C) ────────►│
  │◄─ CHALLENGE (nonce, pub_S) ─────────│
  │── HELLO_ACK (HMAC-SHA256) ─────────►│
  │◄─ SESSION_OK (session_id) ──────────│
         ↓  Session Key Derived  ↓
  │════ DATA (AES-256-GCM / Poly1305) ═►│
  │◄═══ DATA (AES-256-GCM / Poly1305) ══│

Session keys are derived via:

HKDF-SHA256(
    ikm  = X25519(priv_C, pub_S),
    salt = nonce,
    info = "usmp-v2" || pub_C || pub_S
)

Ecosystem & Ports

  • ESP-IDF Component (ESP32): Available on ESP Component Registry (idf.py add-dependency "metaloomlabs/usmp").
  • Arduino Library (ESP32): Available via Arduino Library Manager or packaged release ZIP (usmp-1.3.0-arduino.zip).
  • Core C Engine: Zero-dependency portable C core supporting custom microcontroller targets (STM32, Linux, RTOS).

License

USMP is open-source software licensed under the Apache 2.0 License.


USMP™ • Developed by Metaloom

Metadata

Release files for usmp 1.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 usmp 1.3.0
File Size Uploaded Provenance Actions
usmp-1.3.0.tar.gz 33.2 kB Without provenance Details for usmp-1.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 71.7 kB

Release files / usmp-1.3.0.tar.gz

Download URL usmp-1.3.0.tar.gz
Size 33.2 kB
Tags Source
SHA-256 checksum
How to use checksums
eb7e11802e7f25a59107a3af5d71995d460fdefbeac448e91c1fe6d70203af26
BLAKE2b-256 checksum
How to use checksums
f979bb76a9346c8cf57000339efaefedc93a3aca4b6b33b6cf87d41cc73ceedb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.21

Release files / usmp-1.3.0-py3-none-any.whl

Download URL usmp-1.3.0-py3-none-any.whl
Size 38.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
efd294b25643295d0d2f1df5d14ac6362b750bdde9ef27ed2f10111f02a620a5
BLAKE2b-256 checksum
How to use checksums
3f9c3276ea22868afcca89d22c06be3d0d45bee787631e30b4415c517db28226
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.21

Security for usmp 1.3.0

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