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.
๐ 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 metadataAlert: Alert notifications with severity levelsSystemStatus: 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
- Events: Structured data with automatic metadata (UUID, timestamp)
- Messages: Direct point-to-point communication
- 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
-
Fork the repository
-
Clone your fork:
git clone https://github.com/yourusername/robosapiens-clientlibraries.git -
Create a feature branch:
git checkout -b feature/amazing-feature -
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
- Make your changes
- Add/update tests
- Update documentation
- Ensure all tests pass
- 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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
705ae82ff4bce790b1c8c548ee1665868e67a2596d1fc8961f5e7b2500d20af6
|
|
| MD5 |
561d2f4bac9c225f8193250687bb8a4d
|
|
| BLAKE2b-256 |
8f1c4059eacae20f5562571ec5a3472a2773fd643131053a3d92b606d89ddf25
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f59dd022b4ef6ad89a5be35fd11233671119b70ce26f167a38c5689e54835992
|
|
| MD5 |
372a79dd71d35546276587c3296e3211
|
|
| BLAKE2b-256 |
3eb80e327239b33a4095265c8e63171bd74257f6dd529d9641f6f56bb0bbb237
|