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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: alchemista-0.1.0.post1.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.post1.tar.gz
Algorithm Hash digest
SHA256 73112ab708690542072d44cdaa5db6b0bd80837e125a3ae2fa59e73f20e80275
MD5 a9e06a9d0e66c15d5ad668cde2f427fc
BLAKE2b-256 774f7d40e94ab2c1c5c14cd275bdc35c56316ce1560c5070a4b8c02206d095b7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: alchemista-0.1.0.post1-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.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 7618dde30068bd9d0cd6aaa9227acf034c0f58f251147aa1f3164761d5734a7e
MD5 5140cf2855f508ba26234f4700b917da
BLAKE2b-256 1540d5325180871d26c7a2195bbc42a50591216f162e13cffb2bce02307bdb5a

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