Metadata-Version: 2.1
Name: alchemista
Version: 0.1.0.post2
Summary: Tools to convert SQLAlchemy models to Pydantic models
Home-page: https://github.com/ggabriel96/alchemista
License: MIT
Author: Gabriel Galli
Author-email: ggabriel96@hotmail.com
Requires-Python: >=3.6.2,<4.0.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Dist: SQLAlchemy (>=1.4.14,<2.0.0)
Requires-Dist: importlib-metadata (>=1.6.0,<4.0.0); python_version < "3.8"
Requires-Dist: pydantic (>=1.8.1,<2.0.0)
Project-URL: Repository, https://github.com/ggabriel96/alchemista
Description-Content-Type: text/markdown

# Alchemista

Tools to generate Pydantic models from SQLAlchemy models.

Still experimental.

## How to use

Quick example:

```python
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.

