Skip to main content

QRES Python Bindings

Resource-Aware Decentralized Node Mesh for Edge Computing

High-performance Python bindings to qres_core (Rust) enabling deterministic Byzantine-tolerant compression, multimodal fusion, and P2P gossip for IoT and edge AI applications.

PyPI Python 3.8+ License


Features

  • ✅ Deterministic Compression: Q16.16 fixed-point math (no floating-point non-determinism)
  • ✅ Byzantine Tolerance: Coordinate-wise trimmed mean, reputation system (tolerates 30% attackers)
  • ✅ Multimodal Fusion: TAAF (Temporal Attention-Guided Adaptive Fusion) with sparse spiking
  • ✅ Energy Efficiency: TWT scheduling, regime-aware silence (82% radio sleep time)
  • ✅ No Heap Allocations: no_std compatible core, <1 KB per-node overhead
  • ✅ Cross-Platform: x86_64, ARM64, ARM32, RISC-V, WASM

Performance:

  • 4.98x–31.8x compression vs. federated learning (dataset-dependent)
  • ~99% bandwidth reduction (8 KB/day vs. 2.3 GB/day typical FL baseline)
  • <30 epochs to consensus (100-node swarms, verified)

Installation

From PyPI (Recommended)

pip install qres-raas

From Source (Development)

Requires Rust 1.75+ and maturin:

# Clone repository
git clone https://github.com/CavinKrenik/QRES_RaaS.git
cd QRES_RaaS/bindings/python

# Install maturin
pip install maturin

# Build and install (development mode)
maturin develop --release

# Or build wheel for distribution
maturin build --release

Dependencies

Core (always required):

pip install numpy scipy

Optional (for specific features):

# Lightweight features (CI testing)
pip install networkx gymnasium

# Full ML stack (local experimentation)
pip install torch sentence-transformers stable-baselines3 pandas matplotlib

Or install extras:

pip install qres-raas[ci]      # Lightweight
pip install qres-raas[ml]      # Full ML stack

Quick Start

Basic Compression

from qres import QRES_API

# Initialize API
api = QRES_API(mode="hybrid")  # "hybrid" = adaptive regime detection

# Compress data
data = b"Sensor readings: temperature=23.5C, humidity=65%"
compressed = api.compress(data, usage_hint="iot")

# Decompress (deterministic)
decompressed = api.decompress(compressed)

assert data == decompressed
print(f"Compression ratio: {len(data) / len(compressed):.2f}x")

Multimodal TAAF Fusion

from qres.multimodal import TAAFPredictor, observe_multimodal
import numpy as np

# Initialize predictor
predictor = TAAFPredictor(
    num_modalities=3,
    fusion_mode="attention",
    spike_threshold=2.0
)

# Observe sensor streams (temperature, humidity, pressure)
modality_values = [23.5, 65.0, 1013.0]
prediction, attention_weights = observe_multimodal(predictor, modality_values)

print(f"Prediction: {prediction:.2f}")
print(f"Attention:  {attention_weights}")

Swarm Node Participation

from qres.swarm_cli import SwarmNode, SwarmConfig

# Configure node
config = SwarmConfig(
    node_id="sensor_42",
    listen_address="/ip4/0.0.0.0/tcp/0",
    bootstrap_peers=["/ip4/192.168.1.10/tcp/4001"],
    reputation_initial=0.8,
    regime="Calm"
)

# Launch node
node = SwarmNode(config)
print(f"PeerID: {node.peer_id}")
print(f"DID: did:qres:{node.did_suffix}")

# Participate in gossip
# ... (see examples/python/03_swarm_node.py)

node.shutdown()

API Overview

qres.QRES_API

Main compression interface.

Methods:

  • compress(data: bytes, usage_hint: str = "auto") -> bytes
    • usage_hint: "auto", "iot", "text", "binary", "semantic"
  • decompress(compressed: bytes) -> bytes

Modes:

  • "hybrid": Adaptive regime detection
  • "fixed": Fixed predictor
  • "multimodal": TAAF fusion

qres.multimodal

Multimodal fusion and TAAF predictors.

Classes:

  • TAAFPredictor(num_modalities, fusion_mode, spike_threshold)
    • Temporal Attention-Guided Adaptive Fusion
  • LSTMPredictor(input_size, hidden_size, num_layers)
    • LSTM-based compression model

Functions:

  • observe_multimodal(predictor, modality_values) -> (prediction, attention_weights)

qres.swarm_cli

P2P swarm node management.

Classes:

  • SwarmNode(config) - libp2p-based gossip node
  • SwarmConfig(node_id, listen_address, bootstrap_peers, ...)

qres.persistent

Model persistence and serialization.

Classes:

  • ModelPersistence - Trait for storage backends (disk, cloud, IPFS)

Functions:

  • save_model(model, path: str)
  • load_model(path: str) -> model

Note: GeneStorage is deprecated (v21.0), use ModelPersistence instead.


Configuration

Feature Flags

When building from source, you can enable/disable features:

# Minimal (no ML dependencies)
maturin develop --release --no-default-features --features python

# Full (all features)
maturin develop --release --features python,ml

Environment Variables

  • QRES_LOG_LEVEL: DEBUG, INFO, WARN, ERROR (default: INFO)
  • QRES_DATA_DIR: Data directory for model checkpoints (default: ~/.qres)

Examples

See examples/python/ for comprehensive examples:

  1. 01_basic_compression.py - Core API usage
  2. 02_multimodal_taaf.py - Multimodal fusion (v20.0)
  3. 03_swarm_node.py - P2P gossip protocol
  4. 04_byzantine_defense.py - Cartel detection (v20.0.1)
  5. 05_regime_transitions.py - Entropy-driven state machine
  6. 06_persistent_state.py - Non-volatile recovery (v18.0.0)

Run all:

cd ../../examples/python
python 01_basic_compression.py
# ... etc

Performance & Benchmarks

Compression Ratios (Verified v20.0)

Dataset Ratio vs. FL Bandwidth Saved
SmoothSine 31.8x 96.9%
Wafer 4.98x 79.9%
ECG5000 4.98x 79.9%

Throughput (x86_64, i7-10700K)

Operation Time Throughput
compress() 100ns 10M ops/sec
decompress() 80ns 12M ops/sec
TAAF observe_multimodal() 500ns 2M obs/sec

Memory

  • Per-node overhead: <1 KB (Q16.16 fixed-point state)
  • Python bindings: ~25 MB (includes maturin runtime)

Troubleshooting

Import Errors

ImportError: No module named 'qres'

Solution: Install or rebuild bindings:

cd bindings/python
maturin develop --release

Rust Compilation Errors

error: failed to compile `qres_core`

Solution: Update Rust toolchain:

rustup update stable
rustup default stable

Missing Dependencies

ModuleNotFoundError: No module named 'torch'

Solution: Install optional dependencies:

pip install qres-raas[ml]

Or skip ML features:

pip install qres-raas[ci]  # Lightweight

Development

Running Tests

Requires pytest:

pip install pytest pytest-cov
pytest tests/ -v

Type Checking

Requires mypy and type stubs:

pip install mypy
mypy bindings/python/qres

Building Documentation

pip install sphinx sphinx-rtd-theme
cd docs
make html

Versioning

This package follows the core QRES version.

  • v21.0.0 (Current): Documentation restructure, INV-7 liveness
  • v20.0.1: Adaptive defense, regime hysteresis
  • v20.0.0: TAAF multimodal fusion, adaptive reputation exponent
  • v19.1.0: TWT integration, power management

See CHANGELOG.md for full history.


Contributing

Contributions welcome! See CONTRIBUTING.md.

Areas needing help:

  • Additional predictor implementations (Transformer, GRU)
  • Cloud storage backends (S3, Azure Blob)
  • Hardware-accelerated inference (ONNX Runtime, TensorRT)
  • Jupyter notebook tutorials

Citation

@software{qres2026,
  author = {Krenik, Cavin},
  title = {QRES: Resource-Aware Agentic Swarm},
  url = {https://github.com/CavinKrenik/QRES_RaaS},
  doi = {10.5281/zenodo.18474976},
  year = {2026}
}

Paper: RaaS: Resource-Aware Agentic Swarm


License

Dual-licensed under MIT or Apache-2.0, at your option.

Metadata

Release files for qres-raas 21.0.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 qres-raas 21.0.0
File Size Uploaded Provenance Actions
qres_raas-21.0.0.tar.gz 520.8 kB With provenance Details for qres_raas-21.0.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for qres-raas 21.0.0
File Interpreter ABI Platform Actions
qres_raas-21.0.0-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details for qres_raas-21.0.0-cp38-abi3-win_amd64.whl
qres_raas-21.0.0-cp38-abi3-manylinux_2_34_x86_64.whl CPython 3.8 abi3 Linux glibc 2.34+ x86-64 Details for qres_raas-21.0.0-cp38-abi3-manylinux_2_34_x86_64.whl
qres_raas-21.0.0-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details for qres_raas-21.0.0-cp38-abi3-macosx_11_0_arm64.whl

Total release size: 1.5 MB

Release files / qres_raas-21.0.0.tar.gz

Download URL qres_raas-21.0.0.tar.gz
Size 520.8 kB
Tags Source
SHA-256 checksum
How to use checksums
395fa60de8d03978bffa18258e816b57475063715b05fe74742245ee19844743
BLAKE2b-256 checksum
How to use checksums
8c1436ec8f2fb8c08dfbfc7c4ad53bfe41950815239940522bca98a6dbbee165
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 6, 2026.

Transparency log

Release files / qres_raas-21.0.0-cp38-abi3-win_amd64.whl

Download URL qres_raas-21.0.0-cp38-abi3-win_amd64.whl
Size 164.0 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
56c293e423587f3973144473fbed51a5527842cb2184b8a3265f7ffaeb669378
BLAKE2b-256 checksum
How to use checksums
d16e8afe549b8e6bc241bcccae7045d1dbbae04956ae2966128832061b04807c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 6, 2026.

Transparency log

Release files / qres_raas-21.0.0-cp38-abi3-manylinux_2_34_x86_64.whl

Download URL qres_raas-21.0.0-cp38-abi3-manylinux_2_34_x86_64.whl
Size 559.0 kB
Tags CPython 3.8 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
db30ed60d6e4bebf1eec27e8f33d0b5e40f07a6efd0a726958fd9773e657d71b
BLAKE2b-256 checksum
How to use checksums
ed8de7a297dced9ac38e8f932740bdcd34a35eac4135113b979f2e1eb4674a5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 6, 2026.

Transparency log

Release files / qres_raas-21.0.0-cp38-abi3-macosx_11_0_arm64.whl

Download URL qres_raas-21.0.0-cp38-abi3-macosx_11_0_arm64.whl
Size 256.1 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3be395db9d739dbb29bccd5c39661591c76b498d8fdca08148548f84282c24a5
BLAKE2b-256 checksum
How to use checksums
31afacc4eabb89546fb04e218b590ac82cd3ceb076c678c25c954f11166cd95b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 6, 2026.

Transparency log

Security for qres-raas 21.0.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.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for qres_raas-21.0.0.tar.gz

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 Feb 6, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

21.0.0 This release

4 release files Full provenance

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