sqlalchemy-modelgen
Create sqlalchemy python model files by defining tables and columns in a yaml file or by specifying database url
Installation
pip install alchemy-modelgen
Usage
- Initialize modelgen folder:
- Create sqlalchemy model code from:
- Running alembic migrations:
- Alter table support:
- Change column type, length, add contraint, etc in the yaml file. Then run:
- The code that reads the structure of an existing database and generates the appropriate SQLAlchemy model code is based on agronholm/sqlacodegen's repository (Copyright (c) Alex Grönholm), license: MIT License
modelgen init -d /path/to/YOUR_FOLDER
cd /path/to/YOUR_FOLDER
(Option 1) yaml template:
For details on how to write the yaml file, please follow docs
modelgen createmodel --source yaml --path templates/example.yaml --alembic # path to your schema yaml file
(Option 2) existing database:
modelgen createmodel --source database --path mysql+mysqlconnector://root:example@localhost:3306/modelgen --outfile models/YOUR_FILENAME.py --alembic
modelgen migrate revision --autogenerate -m "COMMIT_MESSAGE" -p mysql+mysqlconnector://root:example@localhost:3306/modelgen
modelgen migrate upgrade head -p mysql+mysqlconnector://root:example@localhost:3306/modelgen
The arguments passed after modelgen migrate are based on alembic. Any command true for alembic can be used with modelgen migrate.
The database url can be passed using -p or --path argument, or can be set in the environment by the env var DATABASE_URI. If DATABASE_URI is set, -p or --path will be ignored
modelgen createmodel --source yaml --path templates/example.yaml --alembic
modelgen migrate revision --autogenerate -m "COMMIT_MESSAGE" -p mysql+mysqlconnector://root:example@localhost:3306/modelgen
modelgen migrate upgrade head -p mysql+mysqlconnector://root:example@localhost:3306/modelgen
Credits
Metadata
Release files for alchemy-modelgen 0.1.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| alchemy_modelgen-0.1.6.1-py3.8.egg | Legacy Egg format | - | - | Details for alchemy_modelgen-0.1.6.1-py3.8.egg |
| alchemy_modelgen-0.1.6.1-py3-none-any.whl | Python 3 | none | any | Details for alchemy_modelgen-0.1.6.1-py3-none-any.whl |
Total release size: 49.6 kB
Release files / alchemy_modelgen-0.1.6.1-py3.8.egg
| Download URL | alchemy_modelgen-0.1.6.1-py3.8.egg |
|---|---|
| Size | 32.3 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
162a3e92c19a72c1e0ae1e49b18dcf42b75d832793d8c0e0ef1ea89f820dce93
|
|
BLAKE2b-256 checksum How to use checksums |
b078a93aef3c13ad6c78322a477c2bd4ec4a7da6107dffa47de2f3871f89c252
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8
|
Release files / alchemy_modelgen-0.1.6.1-py3-none-any.whl
| Download URL | alchemy_modelgen-0.1.6.1-py3-none-any.whl |
|---|---|
| Size | 17.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ec2a1425759af37043edc4197eb7c1bf604cdb20c533a7db1edfe01181cf7e2e
|
|
BLAKE2b-256 checksum How to use checksums |
868908e6d7639745cb97cda14fe417edce1f34fb6674d044f0fcaf12305e2fbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8
|
Security for alchemy-modelgen 0.1.6.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.