Twirp is a framework for service-to-service communication emphasizing simplicity and minimalism. It generates routing and serialization from API definition files and lets you focus on your application's logic instead of thinking about folderol like HTTP methods and paths and JSON.
Twirpy is a Python implementation of the Twirp framework. It currently supports Twirp Wire Protocol v7.
This repository contains:
- a protoc (aka the Protocol Compiler) plugin that generates sever and client code;
- a Python package with common implementation details.
The runtime library package contains common types like TwirpServer
and TwirpClient
that are used by the generated code.
Add the Twirp package to your Python project with:
pip install twirpy
You need to install protoc
, the Protocol Buffers compiler, and the protoc-gen-twirpy
protoc plugin to generate code.
First, install the Protocol Buffers compiler.
For installation instructions, see Protocol Buffer Compiler Installation documentation.
You can also use your package manager (e.g. brew install protobuf
on macOS).
Go the releases page, and download the protoc-gen-twirpy
binary for your platform.
Unzip the archive and move the binary to a directory in your PATH.
On macOS, you can use the following commands:
curl -L -o- \
https://github.com/Cryptact/twirpy/releases/latest/download/protoc-gen-twirpy-darwin-arm64.tar.gz \
| tar xz -C ~/.local/bin protoc-gen-twirpy
Use the protoc plugin to generate twirp server and client code.
protoc --python_out=. --pyi_out=. --twirpy_out=. example/rpc/haberdasher/service.proto
For more information on how to generate code, see the example.
We use hatch
to manage the development process.
To open a shell with the development environment, run: hatch shell
.
To run the linter, run: hatch fmt --check
or hatch fmt
to fix the issues.
- The initial version of twirpy was made from an internal copy of https://github.com/daroot/protoc-gen-twirp_python_srv
- The work done by Verloop on the initial versions of Twirpy.
- The
run_in_threadpool
method comes from https://github.com/encode/starlette