I use attrs instead of pydantic

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • SonarQube - Static code analysis for 29 languages.
  • Scout APM - Less time debugging, more time building
  • SaaSHub - Software Alternatives and Reviews
  • mashumaro

    Fast and well tested serialization framework on top of dataclasses

    Having run into these issues with Pydantic, we've been using Mashumaro[1], which, while not having all the bells and whistles of Pydantic, has served us pretty well.

    1: https://github.com/Fatal1ty/mashumaro

  • datamodel-code-generator

    Pydantic model generator for easy conversion of JSON, OpenAPI, JSON Schema, and YAML data sources.

    had generally good experience creating typed wrappers for api's with json-schema-to-pydantic[0] converter

    [0] https://github.com/koxudaxi/datamodel-code-generator

  • SonarQube

    Static code analysis for 29 languages.. Your projects are multi-language. So is SonarQube analysis. Find Bugs, Vulnerabilities, Security Hotspots, and Code Smells so you can release quality code every time. Get started analyzing your projects today for free.

  • typing

    Python static typing home. Hosts the documentation and a user help forum.

    Mypy allows that because initial versions of PEP-484 allowed that. This has changed; here's the current wording on the PEP:

    > This is no longer the recommended behavior. Type checkers should move towards requiring the optional type to be made explicit.


  • pydantic

    Data parsing and validation using Python type hints

    >I didn't know about the performance differences. Sam Colvin strikes me as very thorough and the community is very involved, so I don't think the benchmarks claiming pydantic faster than attrs is wrong. I know pydantic uses cython under the hood (no idea what) - is it possible that environmental differences are causing the discrepancy?

    If I'm reading this issue right the benchamrks in the pydantic docs are misleading https://github.com/samuelcolvin/pydantic/pull/1568


  • cattrs

    Complex custom class converters for attrs.


    Cattrs has some problems with generics [1] [2]. Dacite and marshmallow-dataclasses don't support generics well either, with some issues around Union types.

    They do work well for simple python types but what I'd like to see is guarantee that the serialisation operation is completely reversible and if not raise warning/exception.

    [1] https://github.com/Tinche/cattrs/issues/149

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts