GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - connectrpc/connect-py: The Python implementation of Connect: Protobuf RPC that works.

BranchesTags
Open more actions menu

Latest commit

 

History

545 Commits
545 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
conformance
conformance
 
 
connectrpc-fastapi
connectrpc-fastapi
 
 
connectrpc-grpchealth
connectrpc-grpchealth
 
 
connectrpc-grpcreflect
connectrpc-grpcreflect
 
 
connectrpc-otel
connectrpc-otel
 
 
docs
docs
 
 
example
example
 
 
protoc-gen-connectrpc
protoc-gen-connectrpc
 
 
scripts
scripts
 
 
src/connectrpc
src/connectrpc
 
 
test
test
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
AGENTS.md
AGENTS.md
 
 
CLAUDE.md
CLAUDE.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
DEVELOPMENT.md
DEVELOPMENT.md
 
 
LICENSE
LICENSE
 
 
MAINTAINERS.md
MAINTAINERS.md
 
 
README.md
README.md
 
 
RELEASE.md
RELEASE.md
 
 
buf.gen.yaml
buf.gen.yaml
 
 
codecov.yml
codecov.yml
 
 
conftest.py
conftest.py
 
 
connect-py.code-workspace
connect-py.code-workspace
 
 
poe_tasks.toml
poe_tasks.toml
 
 
prek.toml
prek.toml
 
 
pyproject.toml
pyproject.toml
 
 
renovate.json
renovate.json
 
 
uv.lock
uv.lock
 
 
zensical.toml
zensical.toml
 
 

Repository files navigation

The Connect logo

Connect for Python

PyPI version License Slack

Connect is the easiest way to build modern APIs.

Docs • API reference • Example • New to Connect?

Why Connect?

Building an API usually means writing the same types at least twice: once on the server, and once in every client. Connect makes this simple—define your API schema using Protobuf, and Connect generates type-safe server stubs and idiomatic client libraries in every major language, including for your frontend. All that's left to write is your business logic, in plain Python.

Connect already works with your current tech stack:

  • Connect is built on top of HTTP and speaks both Protobuf and JSON, so curl works out of the box.
  • It interoperates seamlessly with gRPC and gRPC-Web, and supports streaming as a first-class feature.
  • It runs on WSGI/ASGI. Build Connect APIs alongside your current API framework—all in the same app.

Features

  • Servers: WSGI and ASGI-ready (including Trio), use with any compatible server
  • Clients: Lightweight sync and async clients (including Trio), backed by pyqwest
  • Protocols: Supports Connect and gRPC-Web over HTTP/1.1 and HTTP/2, and gRPC over HTTP/2
  • Type safety: Fully type-annotated generated code
  • Streaming: Full support for server, client, and bidirectional streaming
  • Compression: Built-in support for gzip, brotli, and zstd
  • Middleware: Server- and client-side interceptors for telemetry, logging, etc.
  • Compliant: Verified using the official Connect conformance test suite

Getting started

Install the runtime library:

uv add connectrpc

For codegen, install buf and create buf.gen.yaml:

version: v2
plugins:
  - remote: buf.build/bufbuild/py
    out: gen
  - remote: buf.build/connectrpc/py
    out: gen
Local plugin setup

The example above uses remote plugins hosted on the Buf Schema Registry. To generate code entirely locally, install the relevant plugins:

uv add --dev protoc-gen-py protoc-gen-connectrpc

Now edit your buf.gen.yaml:

version: v2
plugins:
  - local: .venv/bin/protoc-gen-py
    out: gen
  - local: .venv/bin/protoc-gen-connectrpc
    out: gen
Compatibility with google-protobuf

Connect defaults to targeting protobuf-py as the Protocol Buffers implementation, but it also supports Google's Protocol Buffers for Python. Pass protobuf=google to the codegen plugin to use it.

version: v2
plugins:
  - remote: buf.build/protocolbuffers/python
    out: .
  - remote: buf.build/protocolbuffers/pyi
    out: .
  - remote: buf.build/connectrpc/py
    out: .
    opt: protobuf=google

If configuring a client for JSON codec, make sure to pass connectrpc.compat.google_protobuf_json_codec instead of connectrpc.codec.proto_json_codec.

Usage

A basic Connect server is easy to set up. Just import the stubs, subclass the generated service, and serve:

from connectrpc.request import RequestContext
from your_service_pb import HelloRequest, HelloResponse
from your_service_connect import HelloService, HelloServiceASGIApplication


class MyHelloService(HelloService):
    async def say_hello(
        self, request: HelloRequest, ctx: RequestContext
    ) -> HelloResponse:
        return HelloResponse(message=f"Hello, {request.name}!")


app = HelloServiceASGIApplication(MyHelloService())

# Run with any ASGI server, e.g. uvicorn:
# uvicorn server:app --port 8080

Client libraries are automatically generated for you. Here's what the async client looks like:

import asyncio

from your_service_pb import HelloRequest
from your_service_connect import HelloServiceClient


async def main():
    async with HelloServiceClient("https://api.example.com") as client:
        response = await client.say_hello(HelloRequest(name="World"))
        print(response.message)  # "Hello, World!"


if __name__ == "__main__":
    asyncio.run(main())

And the sync client:

from your_service_pb import HelloRequest
from your_service_connect import HelloServiceClientSync


def main():
    with HelloServiceClientSync("https://api.example.com") as client:
        response = client.say_hello(HelloRequest(name="World"))
        print(response.message)  # "Hello, World!"


if __name__ == "__main__":
    main()

Check out the docs for more detailed usage.

  • Streaming: Connect supports server-side, client-side, and bidirectional streaming.
  • Interceptors: Set up middleware for logging, observability, and metrics.
  • Other languages: Generate clients for use in other languages.

About

The Python implementation of Connect: Protobuf RPC that works.

connectrpc.com/docs/python/getting-started/

Topics

connectrpcgrpcprotobufprotocol-bufferspython

Resources

Readme
License

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

159 stars

Watchers

3 watching

Forks

22 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.