Skip to main content

Tools to convert SQLAlchemy models to Pydantic models

Reason this release was yanked:

Had an error in LICENSE

Project description

Alchemista

Tools to generate Pydantic models from SQLAlchemy models.

Still experimental.

How to use

Quick example:

from alchemista import sqlalchemy_to_pydantic
from sqlalchemy import Column, Integer, String, create_engine, select
from sqlalchemy.orm import declarative_base, sessionmaker


Base = declarative_base()
engine = create_engine("sqlite://", echo=True)


class Person(Base):
    __tablename__ = "people"

    id = Column(Integer, primary_key=True)
    age = Column(Integer)
    name = Column(String, nullable=False)


PersonPydantic = sqlalchemy_to_pydantic(Person)


Base.metadata.create_all(engine)
SessionMaker = sessionmaker(bind=engine)

person = PersonPydantic.construct(name="Someone", age=25)
with SessionMaker.begin() as session:
    session.add(Person(**person.dict()))

with SessionMaker.begin() as session:
    person_db = session.execute(select(Person)).scalar_one()
    person = PersonPydantic.from_orm(person_db)
    print(person)

License

This project is licensed under the terms of the MIT license.

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

alchemista-0.1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

alchemista-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file alchemista-0.1.0.tar.gz.

File metadata

  • Download URL: alchemista-0.1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.6.13 Linux/5.4.0-1046-azure

File hashes

Hashes for alchemista-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7c760f4b80e486756ba19193d465f052f96be597174f052e23d1f6065ef1301f
MD5 b6334852851a6e1be7aaaf2ffd51e7f4
BLAKE2b-256 78e56fd571ff7ae035786082ae62918ce8d7f3733cc871c6cecfb368532aed16

See more details on using hashes here.

File details

Details for the file alchemista-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: alchemista-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.6.13 Linux/5.4.0-1046-azure

File hashes

Hashes for alchemista-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4447dc49a2f425f631adb5b62ba22509b00da875018efae5a29a387bb7378df8
MD5 3b8ccda2cf8916190d4e771683db290f
BLAKE2b-256 2012fffe2caf6032290ec5e0c6fd8c0000c00e9f6ffc71559c20e6fd47dcf338

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page