FastProto is fast and efficient protobuf library for Python, built on the top of Rust.
Project description
FastProto
Fast, Pythonic Protocol Buffers — messages are plain, readable @dataclass
types, with all encoding and decoding handled by a compiled Rust core.
Google's Python protobuf generates opaque classes full of getters/setters and a
reflection API you have to learn. FastProto instead generates clean dataclasses
you can construct, compare, and repr() like any other — and does the wire work
in Rust.
- Idiomatic messages — generated code is a
@dataclasswith plain annotations (str,int,list[...],dict[...],| None); autocomplete, type checkers, andrepr()all just work. - Rust wire codec — encode/decode run in Rust via PyO3, not pure Python.
- Wire-compatible — bytes interoperate both ways with Google's reference
protobufruntime. - Standard toolchain — ships a
protocplugin; just add--fastproto_out.
Install
pip install fastproto # runtime (Python 3.12+)
pip install "fastproto[plugin]" # + the protoc code generator
Code generation also needs the protoc compiler itself — install it from your
package manager (brew install protobuf, apt install protobuf-compiler) or
the official releases.
Quick start
1. Define user.proto:
syntax = "proto3";
package example;
enum Role {
ROLE_UNSPECIFIED = 0;
ROLE_ADMIN = 1;
ROLE_USER = 2;
}
message Address {
string city = 1;
string street = 2;
}
message User {
int64 id = 1;
string name = 2;
optional string email = 3;
Role role = 4;
repeated string tags = 5;
Address address = 6;
map<string, int32> counters = 7;
}
2. Generate with protoc:
protoc --proto_path=. --fastproto_out=. user.proto
This writes user_pb.py — a plain, readable dataclass module:
# @generated by fastproto. DO NOT EDIT.
# source: user.proto
# pyright: reportUnknownVariableType=false
from dataclasses import dataclass, field
from enum import IntEnum
from fastproto import Message, Scalar, message
class Role(IntEnum):
ROLE_UNSPECIFIED = 0
ROLE_ADMIN = 1
ROLE_USER = 2
@message(_USER_DESCRIPTOR)
@dataclass(slots=True)
class User(Message):
id: Scalar.Int64 = 0
name: Scalar.String = ""
email: Scalar.String | None = None
role: Role = Role(0)
tags: list[Scalar.String] = field(default_factory=list)
address: "Address | None" = None
counters: dict[Scalar.String, Scalar.Int32] = field(default_factory=dict)
3. Use it like any dataclass:
from user_pb import Address, Role, User
user = User(
id=42,
name="Ada",
role=Role.ROLE_ADMIN,
tags=["vip", "beta"],
address=Address(city="London", street="Baker St"),
counters={"logins": 7},
)
data = user.to_bytes() # serialize to protobuf wire bytes
assert User.from_bytes(data) == user # and back
No SerializeToString() / ParseFromString() ceremony and no reflection — just
to_bytes() / from_bytes() on a dataclass you can build, compare, and print.
Type mapping
Each proto scalar maps to an alias under fastproto.Scalar. An alias is just
the underlying Python type (int, str, ...) tagged with Annotated[...], so
it type-checks as the base type while still recording the exact wire type.
| proto | Python | proto | Python |
|---|---|---|---|
double |
Scalar.Double |
fixed32 |
Scalar.Fixed32 |
float |
Scalar.Float |
fixed64 |
Scalar.Fixed64 |
int32 |
Scalar.Int32 |
sfixed32 |
Scalar.SFixed32 |
int64 |
Scalar.Int64 |
sfixed64 |
Scalar.SFixed64 |
uint32 |
Scalar.UInt32 |
bool |
Scalar.Bool |
uint64 |
Scalar.UInt64 |
string |
Scalar.String |
sint32 |
Scalar.SInt32 |
bytes |
Scalar.Bytes |
sint64 |
Scalar.SInt64 |
Composite fields: repeated T → list[T], map<K, V> → dict[K, V],
enum → IntEnum, and optional / message / oneof fields → T | None.
Semantics
- Presence (proto3): plain scalars use their zero value and are not nullable;
optionalscalars, message fields, andoneofmembers areT | Noneand track explicit presence (a set empty string is distinct from unset). An all-default message encodes tob"". oneof: members are plain optional fields; setting more than one raisesValueErrorat encode time.- References: sibling, self, and enum references resolve lazily on the first
to_bytes()/from_bytes()— nothing for you to wire up.
empty = User()
assert empty.to_bytes() == b"" and empty.email is None
User(phone="1", telegram="a").to_bytes() # ValueError: ... oneof ...
Contributing
See CONTRIBUTING.md for setup, project layout, and the release flow.
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastproto-0.1.3.tar.gz.
File metadata
- Download URL: fastproto-0.1.3.tar.gz
- Upload date:
- Size: 67.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cb38e902a7a888e780fccbf0fca0e5cd6380b5aef71ea26a6ac6ae25a16cabd
|
|
| MD5 |
93bf20fe68ed5f8f40af4247056c55ca
|
|
| BLAKE2b-256 |
adfad379ba9c643c411c67059b96c90c78a6667cc233ab74b287740742d9cd82
|
Provenance
The following attestation bundles were made for fastproto-0.1.3.tar.gz:
Publisher:
release.yml on pkozhem/fastproto
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastproto-0.1.3.tar.gz -
Subject digest:
6cb38e902a7a888e780fccbf0fca0e5cd6380b5aef71ea26a6ac6ae25a16cabd - Sigstore transparency entry: 2063598671
- Sigstore integration time:
-
Permalink:
pkozhem/fastproto@147e7a1f0c90d3506c021799c85c0fc3dd9a5cc4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pkozhem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@147e7a1f0c90d3506c021799c85c0fc3dd9a5cc4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file fastproto-0.1.3-cp312-abi3-win_amd64.whl.
File metadata
- Download URL: fastproto-0.1.3-cp312-abi3-win_amd64.whl
- Upload date:
- Size: 166.9 kB
- Tags: CPython 3.12+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
388ca0116c92bae42734f3d61506f70a9768533104e61d4b5fc1b931b6debe55
|
|
| MD5 |
31649ba14204a4b923a25667a182a401
|
|
| BLAKE2b-256 |
3a1b99172aff4a10c2099065b1cebf53fd858678ac01c3f3081e19033059b8d1
|
Provenance
The following attestation bundles were made for fastproto-0.1.3-cp312-abi3-win_amd64.whl:
Publisher:
release.yml on pkozhem/fastproto
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastproto-0.1.3-cp312-abi3-win_amd64.whl -
Subject digest:
388ca0116c92bae42734f3d61506f70a9768533104e61d4b5fc1b931b6debe55 - Sigstore transparency entry: 2063598803
- Sigstore integration time:
-
Permalink:
pkozhem/fastproto@147e7a1f0c90d3506c021799c85c0fc3dd9a5cc4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pkozhem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@147e7a1f0c90d3506c021799c85c0fc3dd9a5cc4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file fastproto-0.1.3-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fastproto-0.1.3-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 309.7 kB
- Tags: CPython 3.12+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7be1ea268c5b8cacd70309c888b190e71f67fd5006813e003d71eb76dee8a57
|
|
| MD5 |
36721f3578c122eb76f03a790e485817
|
|
| BLAKE2b-256 |
1756cd25b065634743a4f1638a3e5b971c779e60848520ec0fd69b55d25c3808
|
Provenance
The following attestation bundles were made for fastproto-0.1.3-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on pkozhem/fastproto
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastproto-0.1.3-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
b7be1ea268c5b8cacd70309c888b190e71f67fd5006813e003d71eb76dee8a57 - Sigstore transparency entry: 2063598742
- Sigstore integration time:
-
Permalink:
pkozhem/fastproto@147e7a1f0c90d3506c021799c85c0fc3dd9a5cc4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pkozhem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@147e7a1f0c90d3506c021799c85c0fc3dd9a5cc4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file fastproto-0.1.3-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: fastproto-0.1.3-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 306.5 kB
- Tags: CPython 3.12+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a422c21a250a3bca1d5995be150ca17201986e52a24a6beb73a915b61553a273
|
|
| MD5 |
aad91999009bea6c178272d6bde18dd5
|
|
| BLAKE2b-256 |
dae7b0312fab449bb3a24509d140963be86311618a36ab3db2d9493d0d4e3d5d
|
Provenance
The following attestation bundles were made for fastproto-0.1.3-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on pkozhem/fastproto
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastproto-0.1.3-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
a422c21a250a3bca1d5995be150ca17201986e52a24a6beb73a915b61553a273 - Sigstore transparency entry: 2063598778
- Sigstore integration time:
-
Permalink:
pkozhem/fastproto@147e7a1f0c90d3506c021799c85c0fc3dd9a5cc4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pkozhem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@147e7a1f0c90d3506c021799c85c0fc3dd9a5cc4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file fastproto-0.1.3-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.
File metadata
- Download URL: fastproto-0.1.3-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
- Upload date:
- Size: 532.0 kB
- Tags: CPython 3.12+, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4d61a41bd5a84aff4ae9814412d899e959117b43343f97c8f2fa455fd0ed00a
|
|
| MD5 |
16a2ffc81e96dd48d16dce329e920b86
|
|
| BLAKE2b-256 |
594f8338ce4cf4c701dc2aebefab5d32759c71639aef5803bf44d16748b98034
|
Provenance
The following attestation bundles were made for fastproto-0.1.3-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:
Publisher:
release.yml on pkozhem/fastproto
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastproto-0.1.3-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl -
Subject digest:
a4d61a41bd5a84aff4ae9814412d899e959117b43343f97c8f2fa455fd0ed00a - Sigstore transparency entry: 2063598711
- Sigstore integration time:
-
Permalink:
pkozhem/fastproto@147e7a1f0c90d3506c021799c85c0fc3dd9a5cc4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pkozhem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@147e7a1f0c90d3506c021799c85c0fc3dd9a5cc4 -
Trigger Event:
workflow_dispatch
-
Statement type: