- β¨ 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
Choose your preferred installation method:
# Using pip (recommended)
pip install ipcx-typed
# Using poetry
poetry add ipcx-typed
# Using pipenv
pipenv install ipcx-typed
- Python 3.9 or higher
- aiohttp >= 3.11.16
- pydantic >= 2.11.3
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!
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
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)
)
try:
response = await client.request("stats", StatsRequest(numbers=[]), StatsResponse)
except Exception as e:
print(f"Error: {e}")
-
Microservices Architecture
- Communication between different service components
- Load balancing and service discovery
-
Distributed Computing
- Task distribution and result collection
- Worker pool management
-
Application Integration
- Connecting different parts of your application
- Plugin systems and extensions
-
Real-time Data Processing
- Stream processing
- Event-driven architectures
We welcome contributions! Here's how you can help:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Please read our Contributing Guidelines for more details.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Need help? Here are some ways to get support:
- π Found a bug? Open an issue
- π‘ Have a feature request? Submit it here
- π Contact: Create a discussion