Add your description here
Project description
Convert Sqlalchmey ORM Classes to Pydantic models
An Sqlalchemy ORM Model
class Pokemon(Base):
__tablename__ = "pokemon"
id: Mapped[int] = mapped_column(primary_key=True)
species: Mapped[str] = mapped_column(String(50), nullable=False)
level: Mapped[int] = mapped_column(Integer, default=1)
poke_type: Mapped[str] = mapped_column(String(20))
trainer_id: Mapped[Optional[int]] = mapped_column(ForeignKey("trainer.id"), nullable=True)
evolution_id: Mapped[Optional[int]] = mapped_column(ForeignKey("pokemon.id"))
evolution: Mapped[Optional["Pokemon"]] = relationship()
owner: Mapped[Optional["Trainer"]] = relationship(back_populates="pokemons")
items: Mapped[List[PokemonHasItem]] = relationship(back_populates="pokemon")
Usage
from sa2pydantic import sa2pydantic
# Create an Pydantic Create Model for Post Method
PokemonCreate = sa2pydantic(Pokemon,
name_call=lambda sa: f"{sa.__name__.title()}Create",
exclude_primarykey=True,
exclude_rel=True,
)
# <class 'sa2pydantic.core.PokemonCreate'>
# species: default=PydanticUndefined, annotation=<class 'str'>
# level: default=1, annotation=<class 'int'>
# poke_type: default=PydanticUndefined, annotation=<class 'str'>
# Create an Pydantic Output Model for Get Method
PokemonOut = sa2pydantic(Pokemon,
name_call=lambda sa: f"{sa.__name__.title()}Out")
# <class 'sa2pydantic.core.PokemonOut'>
# id: default=PydanticUndefined, annotation=<class 'int'>
# species: default=PydanticUndefined, annotation=<class 'str'>
# level: default=1, annotation=<class 'int'>
# poke_type: default=PydanticUndefined, annotation=<class 'str'>
# trainer_id: default=PydanticUndefined, annotation=typing.Optional[int]
# evolution_id: default=PydanticUndefined, annotation=typing.Optional[int]
# evolution: default=None, annotation=typing.Optional[sa2pydantic.core.PokemonOut]
# owner: default=None, annotation=typing.Optional[sa2pydantic.core.TrainerOut]
# items: default=[], annotation=list[sa2pydantic.core.PokemonhasitemOut]
# Create an Pydantic Output Model with all fields as optional with default value
PokemonOutOptional: PY_MODEL = sa2pydantic(Pokemon,
name_call=lambda sa: f"{sa.__name__.title()}OutOptional",
override_optional=True,
override_default_value=None)
# <class 'sa2pydantic.core.PokemonOutOptional'>
# id: default=None, annotation=typing.Optional[int]
# species: default=None, annotation=typing.Optional[str]
# level: default=None, annotation=typing.Optional[int]
# poke_type: default=None, annotation=typing.Optional[str]
# trainer_id: default=None, annotation=typing.Optional[int]
# evolution_id: default=None, annotation=typing.Optional[int]
# evolution: default=None, annotation=typing.Optional[sa2pydantic.core.PokemonOutOptional]
# owner: default=None, annotation=typing.Optional[sa2pydantic.core.TrainerOutOptional]
# items: default=[], annotation=typing.Optional[list[sa2pydantic.core.PokemonhasitemOutOptional]]
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 sa2pydantic-0.1.0.tar.gz.
File metadata
- Download URL: sa2pydantic-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
394b08000d6a0284b2d794da05c60df7ce8c36a2301fea1d69790c0d513ec3c9
|
|
| MD5 |
5bffa40613ac6ae5ae40db2fdae36aef
|
|
| BLAKE2b-256 |
c723de3895ffeb35dd6433157acee9c28e25075eb132f6c77d613ac8a8a9da6e
|
Provenance
The following attestation bundles were made for sa2pydantic-0.1.0.tar.gz:
Publisher:
publish.yml on JawaClass/sa2pydantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sa2pydantic-0.1.0.tar.gz -
Subject digest:
394b08000d6a0284b2d794da05c60df7ce8c36a2301fea1d69790c0d513ec3c9 - Sigstore transparency entry: 1115704577
- Sigstore integration time:
-
Permalink:
JawaClass/sa2pydantic@2529bfc31eba837315429c17c9940fbf2d73782b -
Branch / Tag:
refs/tags/alpha - Owner: https://github.com/JawaClass
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2529bfc31eba837315429c17c9940fbf2d73782b -
Trigger Event:
release
-
Statement type:
File details
Details for the file sa2pydantic-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sa2pydantic-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a2bddab7b6633c1819c0d1f4fee8df9fc5be763b3cbde0610857bba8cd752dd
|
|
| MD5 |
92cd91e0b8aeb73dee2b0b5250d3863c
|
|
| BLAKE2b-256 |
1f5390acdb3cfb2088657b52ea19de2197a14319db0ad0922cc01d04e08378f6
|
Provenance
The following attestation bundles were made for sa2pydantic-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on JawaClass/sa2pydantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sa2pydantic-0.1.0-py3-none-any.whl -
Subject digest:
4a2bddab7b6633c1819c0d1f4fee8df9fc5be763b3cbde0610857bba8cd752dd - Sigstore transparency entry: 1115704631
- Sigstore integration time:
-
Permalink:
JawaClass/sa2pydantic@2529bfc31eba837315429c17c9940fbf2d73782b -
Branch / Tag:
refs/tags/alpha - Owner: https://github.com/JawaClass
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2529bfc31eba837315429c17c9940fbf2d73782b -
Trigger Event:
release
-
Statement type: