SQLModelGenerator
SQLModelGenerator is a CLI tool that automatically generates SQLModel models (including enums) directly from a Postgres database via SQLAlchemy introspection.
Features
- 🚀 Automatic model & enum generation from your live Postgres database
- ⚙️ Configurable: exclusions, naming rules, type overrides, and more
- 🗄️ Postgres support: arrays, JSONB, enums, relationships, and more
- 🔗 Relationship inference: detects and generates foreign key relationships
- 🖥️ CLI interface: built with Typer
- 👐 Open-source & commercial friendly: MIT license, use for any purpose
Installation
From PyPI (recommended):
pip install sqlmodelgenerator
For local development:
python -m venv .venv
.venv/Scripts/activate # On Windows
# Or: source .venv/bin/activate # On macOS/Linux
pip install -e .[dev]
Usage
Place a config file named sqlmodelgenerator.yaml, sqlmodelgenerator.yml, or sqlmodelgenerator.toml in your project root, or specify one with --config.
# With default config file in current directory
sqlmodelgenerator generate
sqlmodelgenerator inspect
# Or specify a config file
sqlmodelgenerator generate --config path/to/config.yaml
sqlmodelgenerator inspect --config path/to/config.yaml
Configuration
Supported config formats: YAML or TOML. Example:
database_url: postgresql://user:pass@localhost:5432/mydb
output_dir: models
enum_output_path: enums
exclude_tables: [alembic_version]
exclude_columns: []
field_type_overrides: {}
relationship_mode: full
cleanup_old_files: true
See example.sqlmodelgenerator.yaml or example.sqlmodelgenerator.toml for all options.
Example Output
# models/user.py
from sqlmodel import SQLModel, Field, Relationship
from enums.user_status import UserStatus
from typing import Optional
class User(SQLModel, table=True):
id: int = Field(primary_key=True)
name: str
status: UserStatus
profile_id: Optional[int] = Field(default=None, foreign_key="profile.id")
profile: Optional[Profile] = Relationship(back_populates="user")
Development & Testing
- All tests are in the
tests/directory. - Run tests:
pytest - Coverage:
pytest --cov=src/sqlmodelgenerator - Linting:
flake8 src/ tests/ - Type checking:
mypy src/ tests/ - Formatting:
black src/ tests/
Contributing
We welcome contributions of all kinds! To get started:
- Fork the repository and create your branch from
main. - Install dependencies:
python -m venv .venv .venv/Scripts/activate # On Windows # Or: source .venv/bin/activate # On macOS/Linux pip install -e .[dev]
- Write tests for your changes (see
tests/directory). - Lint and format your code:
black src/ tests/ flake8 src/ tests/ mypy src/ tests/
- Open a pull request with a clear description of your changes.
Code style:
Community & Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Contact: opensource@finatic.dev
If you have questions, ideas, or need help, open an issue or start a discussion!
License
MIT License — free for personal, open-source, or commercial use. See LICENSE.
Developed by Finatic.dev — Contributions welcome!
Metadata
Release files for sqlmodelgenerator 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sqlmodelgenerator-0.1.0.tar.gz | 17.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sqlmodelgenerator-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.9 kB
Release files / sqlmodelgenerator-0.1.0.tar.gz
| Download URL | sqlmodelgenerator-0.1.0.tar.gz |
|---|---|
| Size | 17.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a854400228a36b1d53654c31c289d04bcc1b12ab5bff79cf5c61f34173cc4633
|
|
BLAKE2b-256 checksum How to use checksums |
a6bb181ebba63978478a584459a312e644a5a16e69dfb45ff41deaabdee543a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / sqlmodelgenerator-0.1.0-py3-none-any.whl
| Download URL | sqlmodelgenerator-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a60c94b1284f527c17bb4724a717d6e697cd7a2b7d21b5572a37eac61c394b0c
|
|
BLAKE2b-256 checksum How to use checksums |
1bd3a31155d7b7d5c3aa4f04fc10b8f3e17bf2a42b7c0d0d49b3cd8c9ac952db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for sqlmodelgenerator 0.1.0
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.