Python bindings for the Red Giant Transport Protocol — stateless, receiver-driven, chunk-based transport over UDP and raw Ethernet
Project description
rgtp — Python bindings for the Red Giant Transport Protocol
RGTP is a stateless, receiver-driven, chunk-based, pre-encrypted, Merkle-verified, FEC-protected data transport protocol over UDP and raw Ethernet.
This package provides Python 3.9+ bindings via ctypes, with full asyncio async/await support.
Installation
pip install rgtp
The package requires librgtp to be installed on your system. See the
main repository for build instructions.
Set RGTP_LIB_PATH to point to the library if it is not on the default search path:
export RGTP_LIB_PATH=/usr/local/lib/librgtp.so
pip install rgtp
Quick Start
Expose data (server side)
import rgtp
rgtp.init()
with rgtp.Socket() as sock:
data = open("large-file.bin", "rb").read()
with rgtp.expose(sock, data) as surface:
exposure_id = surface.exposure_id()
print(f"Exposure ID: {exposure_id.hex()}")
# distribute exposure_id and key out-of-band to pullers
# Serve pull requests until done
while True:
rgtp.poll(surface, timeout_ms=1000)
rgtp.cleanup()
Pull data (client side)
import rgtp
rgtp.init()
with rgtp.Socket() as sock:
surface = rgtp.pull_start(sock, ("192.168.1.10", 9000), exposure_id)
with surface:
chunks = {}
while surface.progress() < 1.0:
data, chunk_index = rgtp.pull_next(surface)
chunks[chunk_index] = data
rgtp.cleanup()
Async/await
import asyncio
import rgtp
async def expose_file(path: str) -> None:
rgtp.init()
data = open(path, "rb").read()
with rgtp.Socket() as sock:
surface = await rgtp.async_expose(sock, data)
with surface:
print(f"Exposure ID: {surface.exposure_id().hex()}")
while True:
rgtp.poll(surface, timeout_ms=100)
asyncio.run(expose_file("large-file.bin"))
CLI
The package installs two command-line tools:
# Expose a file
rgtp-expose large-file.bin --port 9000
# Pull a file
rgtp-pull 192.168.1.10:9000 <exposure-id-hex> output.bin
API Reference
Library lifecycle
rgtp.init() # Must be called once before any other function
rgtp.cleanup() # Release all global resources
rgtp.version() # Returns version string e.g. "1.0.0"
rgtp.strerror(code) # Human-readable error description
Socket
sock = rgtp.Socket() # Create and bind a UDP socket
sock.close() # Destroy socket (also called by context manager)
Exposer
surface = rgtp.expose(sock, data: bytes) -> rgtp.Surface
rgtp.poll(surface, timeout_ms=100) # Serve pull requests
surface.exposure_id() -> bytes # 16-byte Exposure_ID
surface.progress() -> float # Always 0.0 for exposer
surface.close() # Zeroize key and free
Puller
surface = rgtp.pull_start(sock, (host, port), exposure_id: bytes)
data, chunk_index = rgtp.pull_next(surface, buf_size=65536)
surface.progress() -> float # [0.0, 1.0]
Async wrappers
surface = await rgtp.async_expose(sock, data)
data, idx = await rgtp.async_pull_next(surface, buf_size=65536)
Exceptions
try:
rgtp.init()
except rgtp.RgtpError as e:
print(e.code) # e.g. -4 (RGTP_ERR_CRYPTO_INIT)
print(e.message) # human-readable description
Error Codes
| Code | Constant | Meaning |
|---|---|---|
| 0 | RGTP_OK |
Success |
| -1 | RGTP_ERR_NOMEM |
Memory allocation failed |
| -2 | RGTP_ERR_INVALID_ARG |
Invalid argument |
| -3 | RGTP_ERR_SOCKET |
Socket operation failed |
| -4 | RGTP_ERR_CRYPTO_INIT |
Crypto library init failed |
| -5 | RGTP_ERR_ENCRYPT |
AEAD encryption failed |
| -6 | RGTP_ERR_DECRYPT |
AEAD decryption failed |
| -7 | RGTP_ERR_AUTH_FAIL |
Authentication tag mismatch |
| -8 | RGTP_ERR_MERKLE_FAIL |
Merkle proof verification failed |
| -9 | RGTP_ERR_FEC_FAIL |
FEC decoding failed |
| -10 | RGTP_ERR_TRUNCATED |
Packet truncated |
| -11 | RGTP_ERR_CHUNK_INDEX_OOB |
Chunk index out of bounds |
| -12 | RGTP_ERR_TIMEOUT |
Operation timed out |
| -13 | RGTP_ERR_RATE_LIMITED |
Rate limit exceeded |
| -14 | RGTP_ERR_NOT_SUPPORTED |
Feature not supported |
| -15 | RGTP_ERR_INTERNAL |
Internal invariant violation |
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rgtp-1.0.0.tar.gz.
File metadata
- Download URL: rgtp-1.0.0.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d34293230d43fa9745d8461bda69bf08182dac53f2a4669b5716e22e3458e143
|
|
| MD5 |
e35121d8c9938619e76a6e55937e0106
|
|
| BLAKE2b-256 |
a46bbe3469981c0001ac9a473c94aac6b17d2b7dac2b10ae116614534f434687
|
File details
Details for the file rgtp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: rgtp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56308f7af4ce5eff054fab6843067fb2677891645737c6d0c995cd34a7b301c3
|
|
| MD5 |
2e1dd6a3e977998af2ca458de960368a
|
|
| BLAKE2b-256 |
a3bdd6042d6c142c296006ca23c02fcc89b578dc64920e46388de9869428ed5c
|