3 ms·
Looks great. I'm hesitant, however, since marshmallow-sqlalchemy provides full integration with your SQLAlchemy models, but pydantic-sqlalchemy only is for gen
by shroompasta 5y ago
Looks great.
I'm hesitant, however, since marshmallow-sqlalchemy provides full integration with your SQLAlchemy models, but pydantic-sqlalchemy only is for generating Pydantic models based on SQLAlchemy models, and it seems as if it's still experimental (Why does it have more stars? :thinking:)
Otherwise, just between pydantic and marshmallow for straight up validations, it seems Pydantic is more legible and easier to use at first sight.
Will switch if pydantic had full integration with SQLAlchemy.
And for those of you looking down on me for using ORMs (yes, i know some of you exist), I use both raw SQL and SQLAlchemy.
I find it multitudes easier to build models and deal with migrations in SQLAlchemy than writing scripts.
- smoe 5y agoThe 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/