Skip to main content

dbml-builder

Generates Pydantic and SQLAlchemy from a DBML file.

This package is for users wanting to use their data model represented in DBML in production. dbml-builder accomplishes this by:

  1. Generating Pydantic and SQLAlchemy code.
  2. Verifying existing generated code to see if it matches the specified version and has not been changed since creation.

Currently, there doesn't seem to be a good solution for code generation with DBML in Python hence the creation of dbml-builder. Additionally, large software systems tend to break as Pydantic schemas are modified which is the reason why the package includes verification functionality.

dbml-builder is new and actively developed. If you have any feature requests or issues, please submit them here.

Installation

Install using pip:

pip install dbml_builder

Usage

Generate your ORM and schemas by running:

model-build generate ./project.dbml ./generated

or call generate_models directly in Python code.

You can check to if the model code is still valid by running:

model-build check v0.9.3 ./generated

or call verify directly in Python code.

Note that the version is what is specified in the note for a given project in DBML.

Example

Suppose we have a project:

>> ls
src/  LICENSE  poetry.lock  data-model.dbml  pyproject.toml

where src contains your code for your python project.

We can automatically generate code using:

pip install dbml_builder
model-build generate ./data-model.dbml ./src/generated

We can now submit src/generated to version control and use the generated code in a module:

from generated.schema import SOME_PYDANTIC_SCHEMA
from generated.orm import SOME_SQLALCHEMY_TABLE

We can also ensure the generated code is not changed by placing a check in our code:

# src/main.py
from dbml_builder import verify

verify('v0.1.0', '../data-model.dbml')

Metadata

Release files for dbml-builder 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dbml-builder 0.4.1
File Size Uploaded Provenance
dbml_builder-0.4.1.tar.gz 5.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dbml-builder 0.4.1
File Interpreter ABI Platform
dbml_builder-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.5 kB

Release files / dbml_builder-0.4.1.tar.gz

Download URL dbml_builder-0.4.1.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5ddbfa8f0906c689c40c0f142c19c23549c1dc4daba725d097222dcbe5b42bdf
BLAKE2b-256 checksum
How to use checksums
067967d66ab2f108d7db035f6bfcc600b9d45fd504770d93a94a237189e69b4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.10.9 Linux/6.2.1-arch1-1

Release files / dbml_builder-0.4.1-py3-none-any.whl

Download URL dbml_builder-0.4.1-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f9c9f5a950f9378fe98e9df3ed73661a8d8759dd0d3628b16bf6f9547e8287fe
BLAKE2b-256 checksum
How to use checksums
b04c083374df35b5a812430bdbe4dceaf7fdc0474319e3a37403857715f373ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.10.9 Linux/6.2.1-arch1-1

Security for dbml-builder 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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