Skip to main content

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

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.

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 sqlmodel_default = 50004;
  string sqlmodel_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;
}

Then express fields like:

map<string, string> import_metadata = 7 [
  (example.sqlmodel.sa_type) = "sqlmodel.JSON"
];

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

protoc_gen_sqlmodel-0.2.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

protoc_gen_sqlmodel-0.2.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file protoc_gen_sqlmodel-0.2.0.tar.gz.

File metadata

  • Download URL: protoc_gen_sqlmodel-0.2.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for protoc_gen_sqlmodel-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2d1a6e39f08e6292303c051050878aef1f8f8a0375b92ae50fe0c89030f6b804
MD5 2606d57d30629b5761f69bbb1899372c
BLAKE2b-256 16c896ee0b1c96c87d154c6cb38ae3462050c73a5414680ed07e02963a62c47c

See more details on using hashes here.

Provenance

The following attestation bundles were made for protoc_gen_sqlmodel-0.2.0.tar.gz:

Publisher: publish.yml on river-studio-net/protoc-gen-sqlmodel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file protoc_gen_sqlmodel-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for protoc_gen_sqlmodel-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d677fcbc7e6dbf237b0c85ce19c365af8b08f179e67fc70bb1e494a2e718993e
MD5 d0c7631eaa35178b7c9d3bc4662291a7
BLAKE2b-256 b2808d4fc67e977b6d5df5d269e9b5772cf0297d1d53d43c13dc88d8859cd579

See more details on using hashes here.

Provenance

The following attestation bundles were made for protoc_gen_sqlmodel-0.2.0-py3-none-any.whl:

Publisher: publish.yml on river-studio-net/protoc-gen-sqlmodel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

This release

0.2.0 This release

2 files

0.1.1

2 files

0.1.0

2 files

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