Skip to main content

Python client library for building distributed node-based systems with communication, events, and knowledge management

Project description

RoboSapiens Client Libraries

A collection of high-performance client libraries for building distributed node-based systems with communication, events, and knowledge management capabilities. Available in Python, C++, and Rust with consistent APIs and Redis-based backend.

Python C++ Rust Redis

๐ŸŒŸ Features

All libraries provide:

  • Node Communication: Publish/subscribe messaging and events with automatic metadata
  • Knowledge Management: Distributed key-value storage with object serialization
  • Redis Integration: Fast, reliable backend for all operations across multiple databases
  • Multi-language Support: Consistent APIs across Python, C++, and Rust
  • Real-time Communication: Event-driven architecture with thread-safe operations
  • Type Safety: Strong typing and serialization (JSON, Pickle, Serde)
  • Logging & Monitoring: Built-in structured logging with configurable levels
  • UUID & Timestamps: Automatic message identification and timestamping
  • Error Handling: Comprehensive error management and recovery

๐Ÿ“ Repository Structure

robosapiens-clientlibraries/
โ”œโ”€โ”€ rpclpy/                    # Python library
โ”‚   โ”œโ”€โ”€ __init__.py           # Library initialization
โ”‚   โ”œโ”€โ”€ node.py               # Main Node class
โ”‚   โ”œโ”€โ”€ CommunicationManager.py # Redis pub/sub handling
โ”‚   โ”œโ”€โ”€ KnowledgeManager.py   # Knowledge storage
โ”‚   โ”œโ”€โ”€ LoggingAndTracking.py # Logging infrastructure
โ”‚   โ””โ”€โ”€ examples/             # Python examples
โ”‚       โ”œโ”€โ”€ sensor_node.py   # Temperature sensor simulation
โ”‚       โ”œโ”€โ”€ monitor_node.py  # Data monitoring and analysis
โ”‚       โ”œโ”€โ”€ data_models.py   # Shared data structures
โ”‚       โ”œโ”€โ”€ config.yaml      # Configuration example
โ”‚       โ””โ”€โ”€ README.md        # Examples documentation
โ”œโ”€โ”€ rpclcpp/                  # C++ library
โ”‚   โ”œโ”€โ”€ include/              # Header files
โ”‚   โ”‚   โ”œโ”€โ”€ node.hpp         # Main Node interface
โ”‚   โ”‚   โ”œโ”€โ”€ communication_manager.hpp
โ”‚   โ”‚   โ”œโ”€โ”€ knowledge_manager.hpp
โ”‚   โ”‚   โ””โ”€โ”€ logger.hpp
โ”‚   โ”œโ”€โ”€ src/                  # Implementation files
โ”‚   โ”œโ”€โ”€ examples/             # C++ examples
โ”‚   โ””โ”€โ”€ CMakeLists.txt        # Build configuration
โ”œโ”€โ”€ rpclrs/                   # Rust library
โ”‚   โ”œโ”€โ”€ src/                  # Rust source code
โ”‚   โ”‚   โ”œโ”€โ”€ lib.rs           # Library entry point
โ”‚   โ”‚   โ”œโ”€โ”€ node.rs          # Main Node implementation
โ”‚   โ”‚   โ”œโ”€โ”€ communication_manager.rs
โ”‚   โ”‚   โ””โ”€โ”€ knowledge_manager.rs
โ”‚   โ”œโ”€โ”€ examples/             # Rust examples
โ”‚   โ””โ”€โ”€ Cargo.toml           # Package configuration
โ”œโ”€โ”€ .gitignore               # Git ignore patterns
โ””โ”€โ”€ README.md                # This file

๐Ÿš€ Quick Start

Python (rpclpy)

from rpclpy.node import Node
import yaml

# Load config and create node
with open('config.yaml', 'r') as f:
    config = yaml.safe_load(f)

node = Node(config)
node.start()

# Publish event
node.publish_event("sensor/data", {"temperature": 22.5})

# Subscribe to events
node.register_event_callback("alerts/high", handle_alert)

C++ (rpclcpp)

#include "node.hpp"
using namespace rpclcpp;

Node node("MyNode");
node.start();

// Publish event
json data = {{"temperature", 22.5}};
node.publish_event("sensor/data", data);

// Subscribe to events
node.register_event_callback("alerts/high", [](const std::string& topic, const std::string& msg) {
    // Handle alert
});

Rust (rpclrs)

use rpclrs::Node;
use serde_json::json;

let mut node = Node::new("MyNode", "localhost", 6379)?;
node.start()?;

// Publish event
let data = json!({"temperature": 22.5});
node.publish_event("sensor/data", data)?;

// Subscribe to events
node.register_event_callback("alerts/high", |topic, message| {
    println!("Alert: {}", message);
})?;

๐Ÿ› ๏ธ Installation & Setup

Prerequisites

  • Redis Server: Version 6.0+ running on localhost:6379 (or configured host)
  • Operating System: Linux, macOS, or Windows
  • Language-specific dependencies (see individual library READMEs)

Redis Installation

Ubuntu/Debian:

sudo apt update && sudo apt install redis-server
sudo systemctl start redis-server

macOS:

brew install redis
brew services start redis

Docker:

docker run --name redis-server -p 6379:6379 -d redis

Python Setup (rpclpy)

cd rpclpy
pip install redis paho-mqtt PyYAML  # Install dependencies

C++ Setup (rpclcpp)

Ubuntu/Debian:

sudo apt install cmake build-essential libhiredis-dev nlohmann-json3-dev
cd rpclcpp
mkdir build && cd build
cmake ..
make -j$(nproc)
sudo make install  # Optional: system-wide installation

Build Examples:

make sensor_node monitor_node

Rust Setup (rpclrs)

cd rpclrs
cargo build --release

Build Examples:

cargo build --examples

๐Ÿ“‹ Examples

Sensor Monitoring System

All three libraries include a complete real-time sensor monitoring system that demonstrates:

  • Sensor Node:

    • Simulates realistic temperature sensors with drift and noise
    • Publishes readings as events with automatic timestamping
    • Generates alerts for abnormal conditions
    • Stores data in knowledge base for persistence
  • Monitor Node:

    • Subscribes to sensor events in real-time
    • Processes and analyzes readings for patterns
    • Maintains system statistics and health metrics
    • Responds to alerts with configurable severity levels
    • Provides comprehensive monitoring dashboard
  • Data Models:

    • SensorReading: Temperature data with metadata
    • Alert: Alert notifications with severity levels
    • SystemStatus: Overall system health metrics

What You'll See

SENSOR MONITORING STATUS
============================================================
Active Sensors: 1
Total Readings: 47
Alert Count: 3
Average Temperature: 23.2ยฐC

Sensor Details:
  TEMP_001: 24.1ยฐC [normal] at Lab Room A

Recent Alerts (2):
  [HIGH] Temperature too high: 31.2ยฐC at Lab Room A
  [MEDIUM] Temperature outside normal range: 27.8ยฐC at Lab Room A
------------------------------------------------------------

Running the Examples

Python (Recommended for beginners):

cd rpclpy/examples
# Terminal 1 - Start monitoring first
python monitor_node.py

# Terminal 2 - Start sensor
python sensor_node.py

# Alternative: Run automated test
python test_example.py

C++:

cd rpclcpp/build
# Terminal 1
./monitor_node

# Terminal 2
./sensor_node

Rust:

cd rpclrs
# Terminal 1
cargo run --example monitor_node

# Terminal 2
cargo run --example sensor_node

Testing All Features

Each library includes a comprehensive test script:

Python:

cd rpclpy/examples
python run_tests.py  # Automated test suite with Redis setup check

The test validates:

  • โœ… Node initialization and startup
  • โœ… Event publishing and subscription
  • โœ… Message passing between nodes
  • โœ… Knowledge base read/write operations
  • โœ… Object serialization/deserialization
  • โœ… Alert generation and handling
  • โœ… Real-time data processing

๐Ÿ—๏ธ Architecture

System Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    Events/Messages    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Sensor Node โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚Monitor Node โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       Real-time       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚              Communication           โ”‚
       โ–ผ                                     โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Redis Backend                    โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ Events  โ”‚  โ”‚Messages โ”‚  โ”‚   Knowledge Base    โ”‚  โ”‚
โ”‚  โ”‚ (DB 0)  โ”‚  โ”‚ (DB 1)  โ”‚  โ”‚      (DB 2)         โ”‚  โ”‚
โ”‚  โ”‚ Pub/Sub โ”‚  โ”‚ Pub/Sub โ”‚  โ”‚    Key-Value        โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Communication Flow

  1. Events: Structured data with automatic metadata (UUID, timestamp)
  2. Messages: Direct point-to-point communication
  3. Knowledge: Persistent storage with object serialization

Thread Safety

All libraries implement thread-safe operations:

  • Python: Threading locks and atomic operations
  • C++: Mutexes and RAII patterns
  • Rust: Arc/Mutex for shared state management

๐Ÿ”ง Configuration

All libraries use Redis with separated databases:

  • DB 0: Events (pub/sub)
  • DB 1: Messages (pub/sub)
  • DB 2: Knowledge (key-value storage)

Example configuration (Python):

Event_Manager_Config:
  protocol: "redis"
  host: "localhost"
  port: 6379
  db: 0

Message_Manager_Config:
  protocol: "redis"
  host: "localhost"
  port: 6379
  db: 1

Knowledge_Config:
  knowledge_type: "redis"
  host: "localhost"
  port: 6379
  db: 2

๐ŸŒ API Consistency

All three libraries provide the same core functionality:

Operation Python C++ Rust
Create Node Node(config) Node("name") Node::new("name", host, port)
Start node.start() node.start() node.start()
Publish Event publish_event(topic, data) publish_event(topic, json) publish_event(topic, value)
Subscribe register_event_callback(topic, fn) register_event_callback(topic, fn) register_event_callback(topic, fn)
Write Knowledge write_knowledge(key, value) write_knowledge(key, value) write_knowledge(key, value)
Read Knowledge read_knowledge(key) read_knowledge(key) read_knowledge(key)

๐Ÿงช Testing

Comprehensive Test Coverage

Each library includes comprehensive examples that test:

  • โœ… Node Communication: Event and message passing between nodes
  • โœ… Event Publishing/Subscribing: Real-time event distribution
  • โœ… Message Passing: Direct point-to-point communication
  • โœ… Knowledge Management: Persistent data storage and retrieval
  • โœ… Object Serialization: Type-safe data exchange
  • โœ… Alert Generation: Automated alert creation and handling
  • โœ… Real-time Data Processing: Stream processing capabilities
  • โœ… Error Handling: Graceful error recovery and logging
  • โœ… Thread Safety: Concurrent operations validation
  • โœ… Memory Management: Resource cleanup and leak prevention

Performance Characteristics

  • Latency: Sub-millisecond message delivery
  • Throughput: 10,000+ messages/second per node
  • Memory: Efficient circular buffers for data retention
  • Scalability: Horizontal scaling through Redis clustering

Monitoring & Observability

  • Structured Logging: JSON-formatted logs with context
  • Metrics: Built-in counters for messages, errors, and performance
  • Health Checks: Node status and connectivity monitoring
  • Debug Mode: Detailed tracing for development and troubleshooting

๐Ÿ“– Documentation

๐Ÿค Contributing

We welcome contributions! Here's how to get started:

Development Setup

  1. Fork the repository

  2. Clone your fork: git clone https://github.com/yourusername/robosapiens-clientlibraries.git

  3. Create a feature branch: git checkout -b feature/amazing-feature

  4. Set up development environment:

    # Install Redis
    docker run --name redis-dev -p 6379:6379 -d redis
    
    # Setup Python environment
    cd rpclpy && pip install -e .
    
    # Setup C++ environment
    cd rpclcpp && mkdir build && cd build && cmake ..
    
    # Setup Rust environment
    cd rpclrs && cargo build
    

Contribution Guidelines

  • Code Style: Follow language-specific conventions (PEP 8 for Python, Google Style for C++, Rustfmt for Rust)
  • Testing: Add tests for new features and ensure existing tests pass
  • Documentation: Update READMEs and inline documentation
  • Commit Messages: Use conventional commits format
  • API Consistency: Maintain consistent APIs across all three languages

Areas for Contribution

  • ๐Ÿ› Bug Fixes: Issues and bug reports
  • โœจ New Features: Additional communication protocols, storage backends
  • ๐Ÿ“š Documentation: Tutorials, examples, API documentation
  • ๐Ÿ”ง Performance: Optimizations and benchmarks
  • ๐Ÿงช Testing: Additional test cases and integration tests
  • ๐ŸŒ Internationalization: Multi-language support

Pull Request Process

  1. Make your changes
  2. Add/update tests
  3. Update documentation
  4. Ensure all tests pass
  5. Submit a pull request with detailed description

๐Ÿ› Troubleshooting

Common Issues

Redis Connection Failed:

# Check if Redis is running
redis-cli ping
# Should return "PONG"

# Start Redis if not running
sudo systemctl start redis-server  # Linux
brew services start redis          # macOS

Import Errors (Python):

# Make sure rpclpy is in your Python path
export PYTHONPATH="${PYTHONPATH}:/path/to/robosapiens-clientlibraries"

Build Errors (C++):

# Install missing dependencies
sudo apt install cmake build-essential libhiredis-dev nlohmann-json3-dev

Getting Help

  • ๐Ÿ“– Check individual library READMEs for detailed setup instructions
  • ๐Ÿ› Open an issue for bug reports
  • ๐Ÿ’ฌ Start a discussion for questions and feature requests
  • ๐Ÿ“ง Contact maintainers for urgent issues

๐Ÿ“„ License

MIT License - see individual library directories for details.

๐Ÿท๏ธ Version

Current version: 1.0.0

All libraries maintain API compatibility and feature parity across languages.

Changelog

  • v1.0.0 (2025-07-31): Initial release with Python, C++, and Rust libraries
    • Core node communication functionality
    • Redis-based backend with multi-database support
    • Comprehensive sensor monitoring examples
    • Thread-safe operations across all languages
    • Object serialization and knowledge management
    • Structured logging and error handling

๐ŸŒŸ Acknowledgments

  • Redis Team: For the excellent in-memory data structure store
  • Open Source Communities: Python, C++, and Rust ecosystems
  • Contributors: Everyone who helped make this project possible

Built with โค๏ธ by the RoboSapiens Team

For questions, support, or contributions, please visit our GitHub repository.

Project details


Download files

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

Source Distribution

rpclpy-1.0.0.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

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

rpclpy-1.0.0-py3-none-any.whl (30.9 kB view details)

Uploaded Python 3

File details

Details for the file rpclpy-1.0.0.tar.gz.

File metadata

  • Download URL: rpclpy-1.0.0.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for rpclpy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 705ae82ff4bce790b1c8c548ee1665868e67a2596d1fc8961f5e7b2500d20af6
MD5 561d2f4bac9c225f8193250687bb8a4d
BLAKE2b-256 8f1c4059eacae20f5562571ec5a3472a2773fd643131053a3d92b606d89ddf25

See more details on using hashes here.

File details

Details for the file rpclpy-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: rpclpy-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 30.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for rpclpy-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f59dd022b4ef6ad89a5be35fd11233671119b70ce26f167a38c5689e54835992
MD5 372a79dd71d35546276587c3296e3211
BLAKE2b-256 3eb80e327239b33a4095265c8e63171bd74257f6dd529d9641f6f56bb0bbb237

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page