Skip to main content

Tools to convert SQLAlchemy models to Pydantic models

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.post2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: alchemista-0.1.0.post2.tar.gz
  • Upload date:
  • Size: 4.3 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.post2.tar.gz
Algorithm Hash digest
SHA256 49199670fab53fe018019ce72c7aa199b188aeea88e1e8db15c9f4a73c54097f
MD5 a5bfad83b46526a5d9ccdc6f8186522e
BLAKE2b-256 29dbb952f36e90546eb5cd318debaa6d86de897037f10047159aaa6e7eefc724

See more details on using hashes here.

File details

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

File metadata

  • Download URL: alchemista-0.1.0.post2-py3-none-any.whl
  • Upload date:
  • Size: 4.7 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.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 931218ba53a0c9f50b791e1b39a9152bb5e251a99a7b2c1545959a3aae15201f
MD5 f6fecedae19ddd2be19c2559d0749e79
BLAKE2b-256 b24ec0301e3bbb63b96a01f989ca24558c2e3b7aa9500fbfc6803ba535591fe0

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