turn your DB tables to python code
Project description
Schema Alchemist
Schema Alchemist is a Python library designed to facilitate the generation of SQLAlchemy and SQLModel schemas from existing database schemas. It provides tools to generate table definitions, column definitions, relationships, and more, making it easier to work with complex database schemas in Python.
Features
- Generate SQLAlchemy and SQLModel table definitions from existing database schemas.
- Support for various SQLAlchemy column types, including computed columns, identity columns, and more.
- Generate relationships between tables, including one-to-many, many-to-one, and many-to-many relationships.
- Support for generating enums and other constraints.
- Customizable options for naming conventions, including camel case and snake case.
- Ability to exclude specific tables from relationship generation.
Installation
You can install Schema Alchemist using pip:
pip install schema-alchemist
Usage
Basic Usage
To generate SQLAlchemy schemas from an existing database schema, you can use the CoreSchemaGenerator class:
from schema_alchemist.generators.schema_generators import CoreSchemaGenerator
from sqlalchemy import create_engine
from sqlalchemy.engine.reflection import Inspector
engine = create_engine('sqlite:///example.db')
inspector = Inspector.from_engine(engine)
reflected_data = inspector.reflect()
sorted_tables_and_fks = inspector.get_sorted_table_and_fkc_names()
generator = CoreSchemaGenerator(reflected_data, sorted_tables_and_fks)
schema = generator.generate()
print(schema)
Generating SQLModel Schemas
To generate SQLModel schemas, you can use the SQLModelSchemaGenerator class:
from schema_alchemist.generators.schema_generators import SQLModelSchemaGenerator
generator = SQLModelSchemaGenerator(reflected_data, sorted_tables_and_fks)
schema = generator.generate()
print(schema)
Contributing
Contributions are welcome! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request on GitHub.
License
Schema Alchemist is licensed under the MIT License. See the LICENSE file for more information.
Project details
Release history Release notifications | RSS feed
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 schema_alchemist-0.0.6.tar.gz.
File metadata
- Download URL: schema_alchemist-0.0.6.tar.gz
- Upload date:
- Size: 80.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a67a3f1dbf03e19d24261f1d3c5f7de686e11a27bfe6f5724a0e23ef8b2f182
|
|
| MD5 |
096ba9fa517a4c37948f4113be69d2a0
|
|
| BLAKE2b-256 |
ab8c16478ed65cf7b629b0b5824f0dd65f3016d6ddef4cd24e7073f5345736c3
|
File details
Details for the file schema_alchemist-0.0.6-py3-none-any.whl.
File metadata
- Download URL: schema_alchemist-0.0.6-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff8e9a3ef27523f83a76415171036419ec50b84b6cba809ed38119ee98004262
|
|
| MD5 |
208e0d2de5b70eb123288b0fe559f5a7
|
|
| BLAKE2b-256 |
b8e11016c8430ba4082d4d9e4f3321a5ada41ef326a573a77d1ee75104d80e5f
|