[HN Gopher] Pydantic
       ___________________________________________________________________
        
       Pydantic
        
       Author : marinesebastian
       Score  : 56 points
       Date   : 2022-01-22 21:24 UTC (1 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | JPKab wrote:
       | We use this extensively as probably half of the Python
       | programmers on HN do. It's great, but there are plenty of
       | alternatives out there as well, especially for performance. Our
       | specific use case is IO limited so it's perfect for that.
        
         | jamil7 wrote:
         | Care to list some? I disabled it on a few endpoints of our
         | backend because the performance was awful for GeoJSON.
        
           | lazypenguin wrote:
           | https://www.attrs.org/en/stable/ would be the main
           | alternative
        
             | hackandtrip wrote:
             | Are those alternatives faster according to benchmark?
             | 
             | In my experience, the bottleneck is either: - JSON parsing
             | and dumping; the solution for me is ORJSON, fantastic
             | wrapper to use fast JSON serialisation for most common
             | fields, and also datetime. - Validation - if you choose to
             | validate your data, pydantic can indeed be slow... But it's
             | not Pydantic the problem, but the validation that you apply
             | to your data.
        
             | johnwheeler wrote:
             | Marshmallow is another if you're talking schemas,
             | validation, and json serialization.
        
       | dang wrote:
       | Past related threads:
       | 
       |  _PEP 563, PEP 649 and the future of pydantic and FastAPI_ -
       | https://news.ycombinator.com/item?id=26826158 - April 2021 (150
       | comments)
       | 
       |  _Show HN: Pydantic - Data validation using Python 3.6 type
       | hinting_ - https://news.ycombinator.com/item?id=14477222 - June
       | 2017 (27 comments)
        
       | oars wrote:
       | Fantastic project, but if you're looking for speed this isn't it.
        
         | bredren wrote:
         | What do you look to for a more balanced speed / feature set?
        
       | Starlevel001 wrote:
       | Using mkdocs for any Python project is automatically a massive
       | red flag. No thanks!
        
         | metadat wrote:
         | HN Guidelines state, among other things worth noting [1]:
         | 
         | > Please don't complain about tangential annoyances--things
         | like article or website formats, name collisions, or back-
         | button breakage. They're too common to be interesting.
         | 
         | [1] https://news.ycombinator.com/newsguidelines.html
        
       | shroompasta wrote:
       | 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 wrote:
         | The creator of FastAPI and pydantic-sqlalchemy has recently
         | released a new library: SQLModel. 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 wrote:
           | looks 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.
        
       | null_deref wrote:
       | Using Pydantic, FastAPI and OpenAPI generator tool was a decision
       | which increased my speed of writing code by a lot. Plus it didn't
       | hurt, that FastAPI has an excellent documentation (highly
       | recommend the part that describes using FastAPI with SQLAlchemy).
        
         | hackandtrip wrote:
         | Love FastAPI for lot of concepts that it helped to make
         | mainstream, such as typing-based-validation, but its
         | documentation is lacking.
         | 
         | I love the tutorials, but an API reference is just as
         | important; I may not want to check out long tutorials about
         | things I already read, but check a detailed description of each
         | function would be super helpful - other frameworks such as
         | Sanic have it.
         | 
         | I think it's in the roadmap, kudos for that, and hope that it
         | will get a few more maintainers to speed up the process
        
         | BerislavLopac wrote:
         | OpenAPI generation is cool, but using the OpenAPI as the
         | specification of even better. ;)
        
       ___________________________________________________________________
       (page generated 2022-01-22 23:00 UTC)