Protocol Interface Functions
One function, every protocol. Everywhere.
PIfunc is a revolutionary framework that allows you to write your business logic once and expose it through multiple communication protocols without writing any additional code. With a single Python decorator, your functions become accessible via HTTP/REST, gRPC, MQTT, WebSocket, and GraphQL.
Implement your logic once and expose it via multiple protocols simultaneously. No duplicate code, no inconsistencies.
Forget about writing boilerplate code for different protocols. Add a single decorator and you're done.
Leverage Python's type hints for automatic validation and conversion across all protocols.
PIfunc gives you the freedom to use the right protocol for each use case without changing your implementation.
Perfect for web clients and general API access
Ideal for high-performance microservices
Great for IoT devices and pub/sub patterns
Real-time bidirectional communication
Flexible queries with precise data retrieval
Installation is simple:
pip install pifunc
Create your first multi-protocol function:
from pifunc import service, run_services
@service(
http={"path": "/api/calculator/add", "method": "POST"},
mqtt={"topic": "calculator/add"},
websocket={"event": "calculator.add"}
)
def add(a: int, b: int) -> int:
"""Adds two numbers."""
return a + b
if __name__ == "__main__":
run_services(
grpc={"port": 50051},
http={"port": 8080},
mqtt={"broker": "localhost", "port": 1883},
websocket={"port": 8081},
watch=True
)
Run your service:
python your_service.py
Now your 'add' function is simultaneously available through:
POST http://localhost:8080/api/calculator/add
with body {"a": 5, "b": 3}
add
with parameters a=5, b=3
calculator/add
with payload {"a": 5, "b": 3}
calculator.add
with data {"a": 5, "b": 3}
Don't Repeat Yourself. Implement business logic once, not for each protocol.
Build and deploy faster with drastically reduced boilerplate code.
Ensure consistency across all your endpoints and protocols.
Add new protocols as they emerge without rewriting your services.
Change code and see updates immediately without restarting servers.
Built for real-world applications with monitoring and scaling in mind.