5 ms·
The creator of FastAPI and pydantic-sqlalchemy has recently released a new library: SQLModel. https://sqlmodel.tiangolo.com https://sqlmodel.tiangolo.com It is
by smoe 5y ago
The creator of FastAPI and pydantic-sqlalchemy has recently released a new library: SQLModel.
https://sqlmodel.tiangolo.com https://sqlmodel.tiangolo.com
It is a thin layer on top of Pydantic and SQLAlchemy. I haven't used it yet, so can't speak out of experience, but I think it is basically exactly what you describe.
- shroompasta 5y agolooks promising. At first sight it seems like you still have to write a "schema" for the SQLModel based on your SQLALchemy model - so basically, two sources of truth. If you edit your SQLAlchemy model, you'll also have to edit your SQLModel. sqlalchemy-marshmallow allows you to build your schema based on your SQLAlchemy model. Other than that, I'm still somewhat intrigued. Thanks for the suggestion.
- fantod 5y agoI think SQLModel actually exists precisely so that you don't have to do that. According to [1]: > That class Hero is a SQLModel model... But at the same time, it is a SQLAlchemy model... And at the same time, it is also a Pydantic model [1] https://sqlmodel.tiangolo.com/#sqlalchemy-and-pydantic https://sqlmodel.tiangolo.com/#sqlalchemy-and-pydantic
- shroompasta 5y agoAh, I must've missed something in the first lookaround. looks good.
- smoe 5y ago> so basically, two sources of truth. As I understood you don't, as SQLModel inherits from sqlalchemy ORM base classes. From the user guide, this is an example how to define the model and generate the table. class Hero(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str secret_name: str age: Optional[int] = None engine = create_engine(sqlite_url, echo=True) SQLModel.metadata.create_all(engine)
- shroompasta 5y agoYeah, that was my bad. Went by a bit too quickly. looks good.
- pedrovhb 5y agoNow we just need an integrated admin panel and templating engine and we'll have reinvented Django.
- deleted 5y ago[deleted]
- prometheon1 5y agoThe templating part seems to be somewhat taken care of already: https://fastapi.tiangolo.com/advanced/templates/ https://fastapi.tiangolo.com/advanced/templates/