Contributors Wanted  🀝We’re actively seeking contributors to help build packages for major application transports like gRPC, MQTT, GraphQL, Server-Sent Events (SSE), and more. Our Core, HTTP, and WebSocket packages are production-ready and serve as excellent reference implementations. If you’re interested in contributing, please reach out on GitHub!

Package Status

Production Ready βœ…

  • polyflux-core - Core building blocks and shared components (comprehensive test coverage)
  • polyflux-http - HTTP client and server with ASGI integration (120 tests)
  • polyflux-websocket - WebSocket client and server with broadcasting (277 tests)

In Development 🚧

  • polyflux-grpc - gRPC client and server implementation
  • polyflux-mqtt - MQTT client and broker for IoT applications
  • polyflux-graphql - GraphQL client and server implementation
  • polyflux-sse - Server-Sent Events client and server
  • polyflux-kafka - Apache Kafka client for distributed streaming
Use the production-ready packages as reference implementations when building new protocol packages.

Prerequisites

  • Python 3.12+ - Required for modern type annotations and PEP 695 generics
  • uv - Primary package and environment manager
  • Git - Version control
Important: Always use uv for all Python operations. Never use system Python, pip, or direct commands.

Setup & Installation

1. Clone and Setup

git clone https://github.com/greysonlalonde/polyflux.git
cd polyflux

2. Environment and Dependencies

# Create and activate virtual environment (handled automatically by uv)
uv sync --all-groups

# Verify installation
uv run python --version  # Should be 3.12+

3. Install Pre-commit Hooks

uv run pre-commit install

Development Workflow

Core Commands

# Run full quality check (required before committing)
./scripts/lint-and-test.sh

# Check specific path
./scripts/lint-and-test.sh packages/http/

# Run only tests
./scripts/test-all-packages.sh

Quality Standards

All code must meet these standards:
  1. 🎨 Code Formatting - Consistent style with ruff format
  2. πŸ” Linting - Clean code with ruff check
  3. πŸ›‘οΈ IDE Support - Full autocomplete and error detection
  4. βœ… Tests - All tests must pass
  5. πŸ“‹ Pre-commit - Hooks must pass on every commit

Creating New Packages

Package Generation

Use the automated package creator:
# Basic package
uv run scripts/create-package.py grpc

# With dependencies
uv run scripts/create-package.py mqtt asyncio-mqtt "paho-mqtt==1.6.1"

# Custom class name
uv run scripts/create-package.py grpc --class-name GRPC "grpcio>=1.50.0"
This creates a complete package structure with:
  • Client and server implementations
  • Configuration setup
  • Message types
  • Error handling with validation
  • Comprehensive test framework
  • Documentation templates

Generated Package Structure

packages/new-package/
β”œβ”€β”€ src/polyflux/new_package/
β”‚   β”œβ”€β”€ __init__.py                 # Package exports
β”‚   β”œβ”€β”€ client/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ base.py                 # Unified client implementation (all protocols)
β”‚   β”‚   └── configurable.py        # Configuration schema
β”‚   β”œβ”€β”€ server/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ base.py                 # Unified server implementation (all protocols)
β”‚   β”‚   β”œβ”€β”€ configurable.py        # Server configuration
β”‚   β”‚   β”œβ”€β”€ exceptions.py           # Server-specific exceptions  
β”‚   β”‚   β”œβ”€β”€ types.py                # Server-specific types
β”‚   β”‚   └── utils.py                # Protocol-specific utility functions
β”‚   └── shared/
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ protocol_data_unit.py   # PDU definitions
β”‚       β”œβ”€β”€ types.py                # Shared type definitions
β”‚       └── utils.py                # Shared utility functions
β”œβ”€β”€ tests/                          # Comprehensive test suite
β”œβ”€β”€ pyproject.toml                  # Package configuration
└── README.md                       # Package documentation

Code Standards

Interface Design βœ…

from typing import Protocol, runtime_checkable, Any
from polyflux.core import BaseExchange
from polyflux.core.shared.contracts.protocol_data_unit import Inbound

@runtime_checkable
class GrpcClient(BaseExchange[Inbound], Protocol):
    """gRPC-specific client protocol."""
    
    async def call_method(self, service: str, method: str, **kwargs: Any) -> bool:
        """Call gRPC method."""
        ...
    
    async def disconnect(self) -> None:
        """Close gRPC connection."""
        ...

class GrpcClientImpl(GrpcClient):
    """Concrete gRPC client implementation."""
    
    async def exchange(self, **kwargs: Any) -> Inbound:
        # Implementation here
        ...

Configuration Setup βœ…

from typing import TypedDict, NotRequired
from polyflux.core import BaseConfigSchema

class GrpcConfigSchema(BaseConfigSchema):
    host: str  # Required
    port: int  # Required
    timeout: NotRequired[float]  # Optional (inherited)
    ssl_enabled: NotRequired[bool]  # Optional
    credentials: NotRequired[dict[str, str]]  # Optional

Anti-Patterns ❌

# Bad: Missing type annotations
def connect_grpc(host):
    return grpc_client.connect(host)

# Bad: Not using protocols
class GrpcClient:
    def call_method(self, method):
        pass

# Bad: Hardcoded configuration
class Client:
    def __init__(self):
        self.timeout = 30  # Should be configurable

Testing

Test Structure

# Run all tests
./scripts/test-all-packages.sh

# Run specific package tests
uv run pytest packages/http/tests/ -v

# Run with coverage
uv run pytest packages/http/tests/ --cov=polyflux.http

# Run specific test
uv run pytest packages/http/tests/test_client.py::test_http_exchange -v

Test Categories

  • Unit Tests - Individual component testing
  • Integration Tests - End-to-end client/server scenarios
  • Interface Tests - Implementation validation
  • Configuration Tests - Setup validation
  • Reliability Tests - Error handling and circuit breaker patterns
  • External Service Tests - Real service integration (with fallbacks)

Writing Tests

Use production-ready packages as examples for test patterns:
import pytest
from polyflux.http import HttpClient, HttpClientConfigSchema

@pytest.mark.asyncio
async def test_http_client_exchange():
    """Test HTTP client exchange functionality."""
    config: HttpClientConfigSchema = {
        "base_url": "https://httpbin.org",
        "timeout": 10.0
    }
    
    client = HttpClient()
    client.configure(config)
    
    async with client:
        response = await client.exchange(
            target="/get",
            method="GET"
        )
        
        assert response["status_code"] == 200
        assert b"httpbin" in response["data"]

# WebSocket test example (from production package)
from polyflux.websocket import WebSocketClient

@pytest.mark.asyncio
async def test_websocket_client_exchange():
    """Test WebSocket client exchange functionality."""
    async with WebSocketClient() as client:
        await client.connect("wss://echo.websocket.org")
        
        response = await client.exchange(
            target="wss://echo.websocket.org",
            message_type="text",
            data="Hello WebSocket!"
        )
        
        assert response["message_type"] == "text"
        assert "Hello WebSocket!" in response["data"]

Build and Release

Building Packages

# Build all packages
./scripts/build-all.sh

# Build specific package
cd packages/http && uv build

# Publish (maintainers only)
./scripts/publish.sh

Version Management

# Bump version across all packages
./scripts/bump-version.sh 0.2.0

# Check for dead code
./scripts/check-dead-and-duplicate.sh

Contributing Guidelines

Pull Request Process

  1. Fork and Branch
    git checkout -b feature/grpc-implementation
    
  2. Follow Standards
    • Implement using Protocol-first design
    • Add comprehensive type annotations
    • Write tests for all functionality
    • Update documentation
  3. Quality Checks
    # Must pass before submitting PR
    ./scripts/lint-and-test.sh
    
  4. Commit Guidelines
    feat(grpc): implement gRPC client with service discovery
    
    - Add GrpcClient protocol implementation
    - Implement async context manager support
    - Add service discovery and load balancing
    - Include comprehensive type annotations
    - Add reliability patterns with circuit breaker
    
    Closes #123
    

Review Checklist

  • Protocol Design - Uses @runtime_checkable Protocol classes
  • IDE Support - Full autocomplete and error detection
  • Configuration - Simple setup for all components
  • Error Handling - Comprehensive exception hierarchy
  • Tests - Unit, integration, and protocol conformance tests
  • Documentation - Updated README and API documentation
  • Quality - All linting, formatting, and type checks pass

Code Review Standards

  • Interface Implementation - Must implement all required interfaces
  • Type Annotations - Every function, method, and variable must be typed
  • Error Handling - Proper exception hierarchy and error propagation
  • Async Patterns - Proper async/await usage and context managers
  • Documentation - Clear docstrings and usage examples

IDE Configuration

PyCharm Setup

  1. Interpreter: Use the .venv created by uv
  2. Source Roots: Mark all src/ directories as source roots
  3. Type Checking: Enable mypy plugin/inspections
  4. Formatting: Configure ruff as the formatter

VS Code Setup

{
  "python.defaultInterpreterPath": ".venv/bin/python",
  "python.linting.mypyEnabled": true,
  "python.formatting.provider": "ruff",
  "python.linting.ruffEnabled": true
}

Debugging and Troubleshooting

Common Issues

Getting Help

Architecture Guidelines

Package Design Principles

  1. Interface-First - Always define interfaces before implementation
  2. IDE Support - Complete autocomplete and error detection
  3. Async Native - Built for async/await from the ground up
  4. Configuration - Simple setup for all components
  5. Reliability - Circuit breaker patterns and graceful error handling
  6. Testability - Comprehensive test coverage with protocol conformance tests

Extending Polyflux

When creating new protocol packages:
  1. Study Existing - Review the HTTP and WebSocket packages as reference implementations
  2. Protocol Analysis - Understand the target protocol’s characteristics
  3. Message Design - Create appropriate message structures
  4. Error Hierarchy - Design protocol-specific exception classes
  5. Configuration - Create simple configuration setup
  6. Testing Strategy - Plan unit, integration, and conformance tests
The goal is to provide developers with a consistent, type-safe, and protocol-agnostic interface for any communication protocol.