Skip to main content

Python SDK for the Universal Matrix Inter-Communication Protocol (UMICP) with native type support and tool discovery

Project description

UMICP Python SDK

PyPI version Python Versions License

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 envelope
  • EnvelopeBuilder: Fluent envelope builder
  • Matrix: Matrix operations
  • OperationType: Operation enum (CONTROL, DATA, ACK, ERROR, REQUEST, RESPONSE)
  • PayloadType: Payload type enum
  • EncodingType: Encoding type enum

Transport

  • WebSocketClient: Async WebSocket client
  • WebSocketServer: Async WebSocket server
  • HttpClient: HTTP/2 client
  • HttpServer: HTTP/2 server

Peer

  • WebSocketPeer: Multiplexed peer
  • PeerConnection: Peer connection management
  • PeerInfo: Peer metadata
  • HandshakeProtocol: Handshake utilities

Advanced

  • EventEmitter: Async event system
  • ServiceDiscovery: Service registry
  • ConnectionPool: Connection pooling
  • Compression: Data compression utilities
  • CompressionType: 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


Download files

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

Source Distribution

umicp_sdk-0.3.0.tar.gz (43.8 kB view details)

Uploaded Source

Built Distribution

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

umicp_sdk-0.3.0-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

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

Hashes for umicp_sdk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 61c8797fdb26c27fb1d7a09695d20a4ac7a77227eede781d1b0e03f47b0c8428
MD5 4a73a95b9b9003c6c6c20f761ee03036
BLAKE2b-256 7e0012bb511a4b80bed441666f18eac828b6fad09e836d0ea7168271911337b4

See more details on using hashes here.

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

Hashes for umicp_sdk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6c2b0ce1f7dde1a7989fa9835b177da4208f7ca3b50f4678fc62416fa000016
MD5 f748943c86bd124242edae0c0f6321d1
BLAKE2b-256 61d41f8188e6be75b275ef9ff12ba29be100b7ae877fb5427816e7fea407549c

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