protoc-gen-sqlmodel
A protoc plugin for producing sqlmodel classes. Meant to manage multi-language projects with a single source of truth called protobuf. Generate SQLModel from your schema and manage your DB with alembic.
Install
Add to your project:
uv add protoc-gen-sqlmodel
Then configure like a regular buf plugin in a bug.gen.yaml file:
version: v2
inputs:
- directory: proto
plugins:
- local: protoc-gen-sqlmodel
out: gen
Usage
Run with protoc or (preferred) with uv run buf-generate.
Features
Table Models
To mark a model as a table, include the following extension in your proto files:
syntax = "proto3";
package example.sqlmodel;
import "google/protobuf/descriptor.proto";
// Marks a protobuf message as a SQLModel table.
extend google.protobuf.MessageOptions {
bool table = 50001;
}
And mark the message schema as:
syntax = "proto3";
package example.models;
import "sqlmodel_extensions.proto";
message Entity {
option (example.sqlmodel.table) = true;
}
The generated SQLModel will be marked as a table and you can use it directly with alembic for DB management.
Fields
To express field options add the following proto extensions to you fields:
syntax = "proto3";
package example.sqlmodel;
import "google/protobuf/descriptor.proto";
extend google.protobuf.FieldOptions {
string sa_type = 50002;
bool primary_key = 50003;
string default = 50004;
string default_factory = 50005;
string py_default = 50006;
bool index = 50007;
string foreign_key = 50008;
bool relationship = 50009;
string back_populates = 50010;
bool cascade_delete = 50011;
string on_delete = 50012;
string passive_deletes = 50013;
string link_model = 50014;
string server_default = 50015;
bool nullable = 50016;
bool pguuid7 = 50017;
}
Then express fields like:
message Category {
option (example.sqlmodel.table) = true;
string id = 1 [
(example.sqlmodel.default) = "None",
(example.sqlmodel.pguuid7) = true
];
map<string, string> category_details = 3 [
(example.sqlmodel.sa_type) = "sqlmodel.JSON"
];
repeated Channel channels = 4 [
(example.sqlmodel.relationship) = true,
(example.sqlmodel.back_populates) = "category"
];
// commune is many to one relationship
optional string commune_id = 5 [
(example.sqlmodel.default) = "None",
(example.sqlmodel.foreign_key) = "commune.id"
];
optional Commune commune = 6 [
(example.sqlmodel.relationship) = true,
(example.sqlmodel.back_populates) = "categories"
];
}```
### pguuid7
You may have noticed that we have an option called `pguuid7`. This option will result in the following field declared in the generated model:
```python
id: UUID = Field(sa_column=Column(UUID_(as_uuid=True), primary_key=True, nullable=False, server_default=text("uuidv7()")))
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 protoc_gen_sqlmodel-0.4.1.tar.gz.
File metadata
- Download URL: protoc_gen_sqlmodel-0.4.1.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a86ebdbe78a1f7c8492ceb5d1e4a7117301830f5b73b26304d550126516788f
|
|
| MD5 |
f38e22f256f0fcb1bee39371c1b05c42
|
|
| BLAKE2b-256 |
589c6b8f0ef9953ebfed99788b97860469ea8e1ef396eeb4376e8c345e595355
|
Provenance
The following attestation bundles were made for protoc_gen_sqlmodel-0.4.1.tar.gz:
Publisher:
publish.yml on river-studio-net/protoc-gen-sqlmodel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
protoc_gen_sqlmodel-0.4.1.tar.gz -
Subject digest:
4a86ebdbe78a1f7c8492ceb5d1e4a7117301830f5b73b26304d550126516788f - Sigstore transparency entry: 2828288871
- Sigstore integration time:
-
Permalink:
river-studio-net/protoc-gen-sqlmodel@4895ac0e3fa34228f1af67cf4192bd330f261611 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/river-studio-net
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4895ac0e3fa34228f1af67cf4192bd330f261611 -
Trigger Event:
push
-
Statement type:
File details
Details for the file protoc_gen_sqlmodel-0.4.1-py3-none-any.whl.
File metadata
- Download URL: protoc_gen_sqlmodel-0.4.1-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b88467b93f6a96d106a574f5b73cbbe7b3f39e22ec815ff9622a9ef82305cb8b
|
|
| MD5 |
2692629e77896b6b76f495e9d89c80e7
|
|
| BLAKE2b-256 |
93f779ce941019d327fe48da7c9c8f795470a11063e5dba25de4654badec29a1
|
Provenance
The following attestation bundles were made for protoc_gen_sqlmodel-0.4.1-py3-none-any.whl:
Publisher:
publish.yml on river-studio-net/protoc-gen-sqlmodel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
protoc_gen_sqlmodel-0.4.1-py3-none-any.whl -
Subject digest:
b88467b93f6a96d106a574f5b73cbbe7b3f39e22ec815ff9622a9ef82305cb8b - Sigstore transparency entry: 2828288962
- Sigstore integration time:
-
Permalink:
river-studio-net/protoc-gen-sqlmodel@4895ac0e3fa34228f1af67cf4192bd330f261611 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/river-studio-net
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4895ac0e3fa34228f1af67cf4192bd330f261611 -
Trigger Event:
push
-
Statement type: