Skip to main content

Inter-Process Communication (IPC) library for Python with type safety

Project description

ipcx-typed

PyPI - Python Version CodeQL Tests PyPI version License

A powerful, type-safe inter-process communication library for Python with type safety

🌟 Features

  • ✨ Simple and intuitive API for IPC communication
  • 🔒 Type-safe request/response handling with Pydantic models
  • 🪶 Lightweight and efficient
  • 📦 Efficient data serialization
  • 🔌 Easy integration with any Python application

📦 Installation

Choose your preferred installation method:

# Using pip (recommended)
pip install ipcx-typed

# Using poetry
poetry add ipcx-typed

# Using pipenv
pipenv install ipcx-typed

Requirements

  • Python 3.9 or higher
  • aiohttp >= 3.11.16
  • pydantic >= 2.11.3

🚀 Quick Start

Here's a minimal example to get you started:

from pydantic import BaseModel
from ipcx import Server, Client

# Define your data model
class Message(BaseModel):
    content: str

# Server
async def run_server():
    server = Server(host="localhost", port=8080)
    
    @server.route(param_model=Message, return_model=Message)
    async def echo(request: Message) -> Message:
        return Message(content=f"Echo: {request.content}")
    
    await server.start()

# Client
async def run_client():
    client = Client(host="localhost", port=8080)
    response = await client.request(
        "echo",
        Message(content="Hello, World!"),
        Message
    )
    print(response.content)  # Output: Echo: Hello, World!

Basic Usage

Here's a simple calculator example demonstrating the usage of ipcx:

from pydantic import BaseModel
from ipcx import Server, Client
from typing import List

# Define your data models
class AddRequest(BaseModel):
    numbers: List[float]

class AddResponse(BaseModel):
    sum: float

# Server
async def run_server():
    server = Server(host="localhost", port=8080)
    
    @server.route(param_model=AddRequest, return_model=AddResponse)
    async def add(request: AddRequest) -> AddResponse:
        result = sum(request.numbers)
        return AddResponse(sum=result)
    
    await server.start()

# Client
async def run_client():
    client = Client(host="localhost", port=8080)
    
    # Make a request
    numbers = [1.5, 2.5, 3.5, 4.5]
    response = await client.request(
        "add",
        AddRequest(numbers=numbers),
        AddResponse
    )
    print(f"Sum: {response.sum}")  # Output: Sum: 12.0

Advanced Usage

Type-Safe Routes with Pydantic

from pydantic import BaseModel

class StatsRequest(BaseModel):
    numbers: List[float]

class StatsResponse(BaseModel):
    min: float
    max: float
    average: float

@server.route(param_model=StatsRequest, return_model=StatsResponse)
async def stats(request: StatsRequest) -> StatsResponse:
    if not request.numbers:
        raise ValueError("Empty list provided")
    
    return StatsResponse(
        min=min(request.numbers),
        max=max(request.numbers),
        average=sum(request.numbers) / len(request.numbers)
    )

Error Handling

try:
    response = await client.request("stats", StatsRequest(numbers=[]), StatsResponse)
except Exception as e:
    print(f"Error: {e}")

Example Use Cases

  1. Microservices Architecture

    • Communication between different service components
    • Load balancing and service discovery
  2. Distributed Computing

    • Task distribution and result collection
    • Worker pool management
  3. Application Integration

    • Connecting different parts of your application
    • Plugin systems and extensions
  4. Real-time Data Processing

    • Stream processing
    • Event-driven architectures

🤝 Contributing

We welcome contributions! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please read our Contributing Guidelines for more details.

📄 License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

💬 Support

Need help? Here are some ways to get support:

🔗 Links

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

ipcx_typed-0.1.2.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

ipcx_typed-0.1.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file ipcx_typed-0.1.2.tar.gz.

File metadata

  • Download URL: ipcx_typed-0.1.2.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1012-azure

File hashes

Hashes for ipcx_typed-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e334114c3ed7e3ee8590064ec49efb2b54176ed025a05e65ddaf8aba3638c34d
MD5 775eb98cfa4b7fcbe5ca3d073e84ad2f
BLAKE2b-256 79a0b39dc638f9a6440ff1307d1ca6badad5a42ef76f75a8262b905d05e05e83

See more details on using hashes here.

File details

Details for the file ipcx_typed-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: ipcx_typed-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1012-azure

File hashes

Hashes for ipcx_typed-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bdeab3f368236b913e07a0fa8e2e384e0223cfab659442862ce6a807eaf1dff1
MD5 f54fcf63e1b568689a98cb33a608c8bc
BLAKE2b-256 560ff2d19211fa601e0d762b8e2a1a9b4a17277e697b69d22d52887b2f830cce

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