Python SDK for the Universal Matrix Inter-Communication Protocol (UMICP) with native type support and tool discovery
Project description
UMICP Python SDK
High-performance Python SDK for the Universal Matrix Inter-Communication Protocol (UMICP).
๐ Status: Production Release (v0.3.0)
| Component | Status | Description |
|---|---|---|
| Envelope System | โ Complete | Message envelope with JSON serialization |
| Matrix Operations | โ Complete | NumPy-powered matrix operations |
| WebSocket Client | โ Complete | Async WebSocket client |
| WebSocket Server | โ Complete | Async WebSocket server |
| HTTP/2 Client | โ Complete | HTTP/2 client with httpx |
| HTTP/2 Server | โ Complete | HTTP/2 server with aiohttp |
| Multiplexed Peer | โ Complete | Server + client architecture |
| Event System | โ Complete | Async event emitter |
| Service Discovery | โ Complete | Service registration and discovery |
| Connection Pooling | โ Complete | Generic connection pooling |
| Compression | โ Complete | GZIP/DEFLATE compression |
Current Progress: 100% Feature Complete โ
Python Version: 3.9+ required
Dependencies: Modern async stack (asyncio, websockets, httpx, aiohttp)
๐ฆ Installation
# Install from PyPI (recommended)
pip install umicp-sdk
# Or install specific version
pip install umicp-sdk==0.3.0
# Install from source
git clone https://github.com/hivellm/umicp
cd umicp/bindings/python
pip install -e .
# Install with dev dependencies
pip install -e ".[dev]"
PyPI Package: https://pypi.org/project/umicp-sdk/
Note: Package name follows PEP 625 (normalized as umicp_sdk internally)
Requirements
- Python 3.9+
- NumPy >= 1.24.0
- websockets >= 12.0
- httpx >= 0.27.0
- aiohttp >= 3.9.0
๐ฏ Quick Start
Basic Envelope Usage
from umicp_sdk import Envelope, EnvelopeBuilder, OperationType
# Create envelope
envelope = EnvelopeBuilder() \
.from_id("client-001") \
.to_id("server-001") \
.operation(OperationType.DATA) \
.capability("content-type", "application/json") \
.build()
# Serialize
json_str = envelope.to_json()
print(f"Envelope: {json_str}")
# Deserialize
received = Envelope.from_json(json_str)
print(f"From: {received.from_id}, To: {received.to_id}")
Matrix Operations
import numpy as np
from umicp_sdk import Matrix
matrix = Matrix()
# Vector operations
v1 = np.array([1.0, 2.0, 3.0, 4.0], dtype=np.float32)
v2 = np.array([5.0, 6.0, 7.0, 8.0], dtype=np.float32)
# Dot product
dot_result = matrix.dot_product(v1, v2)
print(f"Dot product: {dot_result.result}") # 70.0
# Cosine similarity
similarity = matrix.cosine_similarity(v1, v2)
print(f"Similarity: {similarity.similarity}")
# Matrix operations
m1 = np.array([[1, 2], [3, 4]], dtype=np.float32)
m2 = np.array([[5, 6], [7, 8]], dtype=np.float32)
result = matrix.multiply(m1, m2)
print(f"Product:\n{result.result}")
WebSocket Client
import asyncio
from umicp_sdk import WebSocketClient, Envelope, OperationType, EnvelopeBuilder
async def main():
# Create client
client = WebSocketClient("ws://localhost:8080")
# Connect
await client.connect()
print("Connected!")
# Send message
envelope = EnvelopeBuilder() \
.from_id("python-client") \
.to_id("server") \
.operation(OperationType.DATA) \
.capability("message", "Hello from Python!") \
.build()
await client.send(envelope)
print("Message sent!")
# Receive message
received = await client.receive()
if received:
print(f"Received: {received}")
# Disconnect
await client.disconnect()
asyncio.run(main())
Multiplexed Peer
import asyncio
from umicp_sdk import WebSocketPeer, EnvelopeBuilder, OperationType
async def main():
# Create peer
peer = WebSocketPeer("peer-001", port=8080)
# Start server
await peer.start()
print("Peer server started")
# Connect to another peer
await peer.connect_to_peer("ws://localhost:8081", "peer-002")
# Send to specific peer
envelope = EnvelopeBuilder() \
.from_id("peer-001") \
.to_id("peer-002") \
.operation(OperationType.DATA) \
.capability("message", "Hello Peer!") \
.build()
await peer.send_to_peer("peer-002", envelope)
# Broadcast to all peers
await peer.broadcast(envelope)
# Cleanup
await peer.disconnect()
asyncio.run(main())
Service Discovery
import asyncio
from umicp_sdk import ServiceDiscovery, ServiceInfo
async def main():
discovery = ServiceDiscovery()
await discovery.start()
# Register service
service = ServiceInfo(
id="my-service-001",
name="MyService",
version="1.0.0",
capabilities={"type": "processor", "language": "python"},
metadata={"description": "Example service"}
)
await discovery.register(service)
# Find services
services = await discovery.find_by_capability("type", "processor")
print(f"Found {len(services)} services")
# Cleanup
await discovery.stop()
asyncio.run(main())
Compression
from umicp_sdk import Compression, CompressionType
# Compress data
data = b"Hello, UMICP! " * 100
compressed = Compression.compress(data, CompressionType.GZIP)
print(f"Original: {len(data)} bytes, Compressed: {len(compressed)} bytes")
# Decompress
decompressed = Compression.decompress(compressed, CompressionType.GZIP)
assert decompressed == data
# Check if compression is beneficial
if Compression.is_beneficial(len(data), len(compressed)):
print("Compression saved space!")
# Get compression ratio
ratio = Compression.get_compression_ratio(len(data), len(compressed))
print(f"Compression ratio: {ratio:.2f}x")
โ Features
Core Features
- โ Envelope System: Type-safe message envelopes with JSON serialization
- โ Builder Pattern: Fluent API for envelope construction
- โ Hash Generation: SHA-256 envelope integrity
- โ Validation: Comprehensive field validation
Matrix Operations
- โ NumPy Integration: High-performance operations
- โ Vector Operations: Add, subtract, scale, dot product
- โ Matrix Operations: Add, multiply, transpose, determinant, inverse
- โ Similarity: Cosine similarity, L2 normalization
- โ Type Safety: Full type hints
Transport Layer
- โ WebSocket: Async client and server with websockets library
- โ HTTP/2: Client (httpx) and server (aiohttp)
- โ Auto-reconnect: Configurable reconnection logic
- โ Statistics: Message and byte counters
Advanced Features
- โ Multiplexed Peer: Server + multiple clients in one
- โ Auto-Handshake: HELLO โ ACK protocol
- โ Event System: Async event emitter with type-safe events
- โ Service Discovery: Registration, health tracking, capability matching
- โ Connection Pooling: Generic async pool with timeouts
- โ Compression: GZIP/DEFLATE with automatic size detection
Developer Experience
- โ Type Hints: Full type annotations for IDE support
- โ Async/Await: Modern asyncio patterns
- โ Error Handling: Custom exception hierarchy
- โ Documentation: Comprehensive docstrings
๐งช Testing
Test Suite
133 comprehensive tests with 97% code coverage:
- โ Unit Tests (100+): All core modules
- โ Integration Tests (10+): End-to-end workflows
- โ Async Tests (30+): Full asyncio coverage
- โ Advanced Tests (15+): Edge cases and error handling
- โ Compression Tests (18): GZIP/DEFLATE compression
Test Coverage by Module
| Module | Tests | Coverage |
|---|---|---|
| types.py | 12 | 100% |
| error.py | 7 | 100% |
| envelope.py | 24 | 94% |
| envelope_advanced.py | 17 | 95% |
| matrix.py | 27 | 99% |
| matrix_advanced.py | 20 | 98% |
| compression.py | 18 | 100% |
| events.py | 8 | 98% |
| discovery.py | 8 | 100% |
| pool.py | 10 | 90% |
| peer/* | 8 | 100% |
| transport/* | 10 | 95% |
| integration | 7 | N/A |
| Total | 133 | 97% |
Running Tests
# Install dev dependencies
pip install -e ".[dev]"
# Run all tests
pytest
# Run with coverage report
pytest --cov=umicp --cov-report=html
pytest --cov=umicp --cov-report=term-missing
# Run specific test file
pytest tests/test_envelope.py
pytest tests/test_matrix.py
pytest tests/test_integration.py
# Run by category
pytest -m "not integration" # Unit tests only
pytest -m integration # Integration tests only
# Verbose output
pytest -v
pytest -vv # Extra verbose
# Type checking
mypy umicp/
# Linting
ruff check umicp/
# Formatting
black umicp/
See TEST_REPORT.md for detailed test coverage report.
๐ API Reference
Core Classes
Envelope: Message envelopeEnvelopeBuilder: Fluent envelope builderMatrix: Matrix operationsOperationType: Operation enum (CONTROL, DATA, ACK, ERROR, REQUEST, RESPONSE)PayloadType: Payload type enumEncodingType: Encoding type enum
Transport
WebSocketClient: Async WebSocket clientWebSocketServer: Async WebSocket serverHttpClient: HTTP/2 clientHttpServer: HTTP/2 server
Peer
WebSocketPeer: Multiplexed peerPeerConnection: Peer connection managementPeerInfo: Peer metadataHandshakeProtocol: Handshake utilities
Advanced
EventEmitter: Async event systemServiceDiscovery: Service registryConnectionPool: Connection poolingCompression: Data compression utilitiesCompressionType: Compression algorithm enum (NONE, GZIP, DEFLATE, LZ4)CompressionError: Compression-specific exceptions
๐ง Development
# Clone repository
git clone https://github.com/hivellm/umicp
cd umicp/bindings/python
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in editable mode with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black umicp/ tests/
# Type check
mypy umicp/
# Lint
ruff check umicp/
๐ Roadmap
Completed โ
- โ Core envelope system with JSON serialization
- โ Matrix operations with NumPy (SIMD-accelerated)
- โ WebSocket transport (client/server) with auto-reconnect
- โ HTTP/2 transport (client/server)
- โ Multiplexed peer architecture
- โ Event system with async handlers
- โ Service discovery with capability matching
- โ Connection pooling with health checks
- โ Compression (GZIP/DEFLATE) with automatic size detection โญ v0.1.3
- โ Full type hints (PEP 561)
- โ Comprehensive error handling
- โ 133 tests with 97% coverage
Planned ๐
- ๐ LZ4 compression support
- ๐ TLS/SSL transport security
- ๐ Additional ML framework integrations (TensorFlow, PyTorch)
- ๐ Load balancing strategies
- ๐ Performance benchmarks
- ๐ Additional examples and tutorials
๐ Part of HiveLLM Ecosystem
UMICP Python bindings integrate with the HiveLLM ecosystem:
- Vectorizer: Semantic search with UMICP communication
- Task Queue: Workflow orchestration
- Agent Framework: Multi-agent systems
- Voxa: Voice AI with agent coordination
๐ License
MIT License - See LICENSE file for details.
๐ค Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Version: 0.2.2
Status: Production Release
Released: October 17, 2025
Python: 3.9+
PyPI: https://pypi.org/project/umicp-python/
Repository: https://github.com/hivellm/umicp
๐ Custom Endpoint Support (v0.2.2)
from umicp_sdk import HttpClient
# Method 1: Default endpoint (/message)
client = HttpClient("http://localhost:8000")
# Method 2: Custom endpoint (e.g., Vectorizer)
client = HttpClient("http://localhost:8000", path="/umicp")
# Method 3: Explicit path parameter
client = HttpClient(
base_url="http://localhost:8000",
path="/custom/endpoint"
)
Compatibility:
- Vectorizer: Use
path="/umicp" - Standard UMICP servers: Use default
path="/message"(or omit) - No breaking changes - fully backward compatible
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 umicp_sdk-0.3.0.tar.gz.
File metadata
- Download URL: umicp_sdk-0.3.0.tar.gz
- Upload date:
- Size: 43.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61c8797fdb26c27fb1d7a09695d20a4ac7a77227eede781d1b0e03f47b0c8428
|
|
| MD5 |
4a73a95b9b9003c6c6c20f761ee03036
|
|
| BLAKE2b-256 |
7e0012bb511a4b80bed441666f18eac828b6fad09e836d0ea7168271911337b4
|
File details
Details for the file umicp_sdk-0.3.0-py3-none-any.whl.
File metadata
- Download URL: umicp_sdk-0.3.0-py3-none-any.whl
- Upload date:
- Size: 28.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6c2b0ce1f7dde1a7989fa9835b177da4208f7ca3b50f4678fc62416fa000016
|
|
| MD5 |
f748943c86bd124242edae0c0f6321d1
|
|
| BLAKE2b-256 |
61d41f8188e6be75b275ef9ff12ba29be100b7ae877fb5427816e7fea407549c
|