PIfunc - Protocol Interface Functions

## What is PIfunc?

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.

### Write Once, Run Anywhere

Implement your logic once and expose it via multiple protocols simultaneously. No duplicate code, no inconsistencies.

### Zero Boilerplate

Forget about writing boilerplate code for different protocols. Add a single decorator and you're done.

### Type Safety

Leverage Python's type hints for automatic validation and conversion across all protocols.

## Supported Protocols

PIfunc gives you the freedom to use the right protocol for each use case without changing your implementation.

HTTP

### HTTP/REST

Perfect for web clients and general API access

gRPC

### gRPC

Ideal for high-performance microservices

MQTT

### MQTT

Great for IoT devices and pub/sub patterns

WS

### WebSocket

Real-time bidirectional communication

GQL

### GraphQL

Flexible queries with precise data retrieval

## Get Started in Minutes

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:

- HTTP: `POST http://localhost:8080/api/calculator/add` with body `{"a": 5, "b": 3}`
- gRPC: Call the method `add` with parameters `a=5, b=3`
- MQTT: Publish to topic `calculator/add` with payload `{"a": 5, "b": 3}`
- WebSocket: Send event `calculator.add` with data `{"a": 5, "b": 3}`
- ... all from the same codebase!

Full Documentation More Examples

## Why Developers Love PIfunc

### DRY Code

Don't Repeat Yourself. Implement business logic once, not for each protocol.

### Rapid Development

Build and deploy faster with drastically reduced boilerplate code.

### Consistent APIs

Ensure consistency across all your endpoints and protocols.

### Future Proof

Add new protocols as they emerge without rewriting your services.

### Hot Reload

Change code and see updates immediately without restarting servers.

### Production Ready

Built for real-world applications with monitoring and scaling in mind.