Skip to main content

Muffin-GRPC

Tests Status PyPI Version

Muffin-GRPC is a plugin for the Muffin framework that brings gRPC support to your application.

Features

  • 📦 Automatically compiles .proto files to Python

  • ⚙️ Simplified gRPC server and client integration

  • 🔁 CLI commands to manage proto compilation and server lifecycle

  • 🧩 Automatically handles proto dependencies and import fixes

  • 🧪 Designed with asyncio and modern Python standards

Requirements

  • Python >= 3.10

  • grpcio

  • grpcio-tools

  • protobuf

  • muffin

Installation

Install via pip:

pip install muffin-grpc

Usage

Set up the plugin and attach it to your Muffin application:

from muffin import Application
from muffin_grpc import Plugin as GRPC

app = Application("example")
grpc = GRPC(default_channel="localhost:50051")
grpc.setup(app)

Create a helloworld.proto:

syntax = "proto3";

package helloworld;

service Greeter {
    rpc SayHello (HelloRequest) returns (HelloReply);
}

message HelloRequest {
    string name = 1;
}

message HelloReply {
    string message = 1;
}

Register the file:

grpc.add_proto("project_name/proto/helloworld.proto")

Compile proto files:

muffin project_name grpc_build

This generates:

  • helloworld_pb2.py — messages

  • helloworld_pb2_grpc.py — gRPC services

  • helloworld.py — bundled import helper

  • __init__.py — so the folder is importable

Now implement the Greeter service:

from .proto.helloworld import GreeterServicer, HelloReply, HelloRequest
import grpc.aio as grpc_aio

@grpc.add_to_server
class Greeter(GreeterServicer):

    async def SayHello(
        self, request: HelloRequest, context: grpc_aio.ServicerContext
    ) -> HelloReply:
        return HelloReply(message=f"Hello, {request.name}!")

Run the gRPC server:

muffin project_name grpc_server

Client example:

from .proto.helloworld import GreeterStub, HelloRequest
from aiohttp.web import Application, Response

@app.route("/")
async def index(request):
    name = request.url.query.get("name", "anonymous")
    try:
        async with grpc.get_channel() as channel:
            stub = GreeterStub(channel)
            response = await stub.SayHello(HelloRequest(name=name), timeout=10)
            return Response(text=response.message)

    except grpc_aio.AioRpcError as exc:
        return Response(text=exc.details())

Configuration

You can configure the plugin either via setup() or using GRPC_ prefixed settings in the Muffin app config.

Available options:

Name

Default value

Description

build_dir

None

Directory to store compiled files

server_listen

“[::]:50051”

gRPC server address

ssl_server

False

Enable SSL for server

ssl_server_params

None

Tuple of credentials for SSL server

ssl_client

False

Enable SSL for client

ssl_client_params

None

Tuple of credentials for SSL client

default_channel

“localhost:50051”

Default gRPC client target

default_channel_options

{}

Additional gRPC options

Via setup():

grpc.setup(app, server_listen="localhost:40000")

Or from config:

GRPC_SERVER_LISTEN = "localhost:40000"

CLI Commands

Build registered proto files:

muffin project_name grpc_build

Start the gRPC server:

muffin project_name grpc_server

Bug Tracker

Found a bug or have a suggestion? Submit an issue here: https://github.com/klen/muffin-grpc/issues

Contributing

Want to contribute? Pull requests are welcome! Development happens at: https://github.com/klen/muffin-grpc

License

Licensed under the MIT license.

Metadata

Release files for muffin-grpc 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for muffin-grpc 0.9.1
File Size Uploaded
muffin_grpc-0.9.1.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for muffin-grpc 0.9.1
File Interpreter ABI Platform
muffin_grpc-0.9.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.7 kB

Release files / muffin_grpc-0.9.1.tar.gz

Download URL muffin_grpc-0.9.1.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bf80bfc506fd887c78b047acbd2ebad7ef37c2ab5f3d15202bb90d0c4279fc1b
BLAKE2b-256 checksum
How to use checksums
a559439d0af07ba1eb995594b485a84c68d7e2ff5d7850764f16d3a0536b7eeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1018-azure

Release files / muffin_grpc-0.9.1-py3-none-any.whl

Download URL muffin_grpc-0.9.1-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a9a5e78a5ca6a34f8906a44667e654dd5d53a102cf308c9349973f4f44628902
BLAKE2b-256 checksum
How to use checksums
723e9e8371047c606537c87ba995fa673e3ba9b39125132e0e4ca5ca393954ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1018-azure

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

1 release file

0.2.0

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page