Generate pydantic models from SQLAlchemy models
Project description
sqlapydantic
Generate Pydantic Model from SQLAlchemy Model
This package is helpful while building web apps with FastAPI and SQLAlchemy. It generates Pydantic Model from SQLAlchemy Model.
Installation
To install,
pip install sqlapydantic
Quickstart
You may use generate_models function directly to generate Pydantic Model from SQLAlchemy Model. It takes Generator's init arguments and init a Generator class.
Examples:
from sqlapydantic import generate_model
generate_model(models=[MyModel], base_model=CustomBaseModel)
from sqlapydantic import Generator
generator = Generator(base_model=CustomBaseModel)
generator.generate_from_module(models=my_models_module, output_path="schemas.py")
Generator Class takes following init arguments
split_models: Whether to split models into Base, Create, Update and Read models. Default isFakse.base_model: Base model to inherit from. Default isBaseModelfrompydantic.restrict_fields: Which takes asetof fields to restrict. Default isNone. This is useful when you want to restrict some fields to be readonly such as id, created_at, updated_at.indentation: Indentation to use in generated code.
RoadMap
- Strict typing, such as using
conintfor limitingIntegersize andconstrforStringlength. - Probably, generate relationships as well.
Project details
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 sqlapydantic-0.0.4.tar.gz.
File metadata
- Download URL: sqlapydantic-0.0.4.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6ff737c740c2b10e481890e1ae6891bca1910758d5c646334580584471ac888
|
|
| MD5 |
af7ee52f35141cff12c81f0d2a578a80
|
|
| BLAKE2b-256 |
7cea46a2040dc4479d7e21ed0fef9d0e084edfffe99ac105f94b783a220e4523
|
File details
Details for the file sqlapydantic-0.0.4-py3-none-any.whl.
File metadata
- Download URL: sqlapydantic-0.0.4-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7839ca3c78965ab5fddeccfe3e991c7c3e846d178b9a9490546374bb3ab3b9a0
|
|
| MD5 |
1b99136c9deb9c9953bf4bdbfcd4c7b4
|
|
| BLAKE2b-256 |
8dfd71196f5e36f4167de7c424de02b7531e2129b8317491e0ba2f1256b32ef1
|