msgspec VS attrs

Compare msgspec vs attrs and see what are their differences.

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
msgspec attrs
31 11
1,857 5,065
- 0.7%
8.9 9.2
25 days ago 13 days ago
Python Python
BSD 3-clause "New" or "Revised" License MIT License
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.

msgspec

Posts with mentions or reviews of msgspec. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-11-01.
  • Htmx, Rust and Shuttle: A New Rapid Prototyping Stack
    3 projects | news.ycombinator.com | 1 Nov 2023
  • Litestar 2.0
    4 projects | /r/Python | 29 Aug 2023
    Full support for validation and serialisation of attrs classes and msgspec Structs. Where previously only Pydantic models and types where supported, you can now mix and match any of these three libraries. In addition to this, adding support for another modelling library has been greatly simplified with the new plugin architecture
  • FastAPI 0.100.0:Release Notes
    12 projects | news.ycombinator.com | 7 Jul 2023
    > Maybe it was very slow before

    That is at least partly the case. I maintain msgspec[1], another Python JSON validation library. Pydantic V1 was ~100x slower at encoding/decoding/validating JSON than msgspec, which was more a testament to Pydantic's performance issues than msgspec's speed. Pydantic V2 is definitely faster than V1, but it's still ~10x slower than msgspec, and up to 2x slower than other pure-python implementations like mashumaro.

    Recent benchmark here: https://gist.github.com/jcrist/d62f450594164d284fbea957fd48b...

    [1]: https://github.com/jcrist/msgspec

  • Pydantic 2.0
    2 projects | news.ycombinator.com | 30 Jun 2023
    While it's definitely much faster than pydantic V1 (which is a huge accomplishment!), it's still not exactly what I'd call "fast".

    I maintain msgspec (https://github.com/jcrist/msgspec), a serialization/validation library which provides similar functionality to pydantic. Recent benchmarks of pydantic V2 against msgspec show msgspec is still 15-30x faster at JSON encoding, and 6-15x faster at JSON decoding/validating.

    Benchmark (and conversation with Samuel) here: https://gist.github.com/jcrist/d62f450594164d284fbea957fd48b...

    This is not to diminish the work of the pydantic team! For many users pydantic will be more than fast enough, and is definitely a more feature-filled tool. It's a good library, and people will be happy using it! But pydantic is not the only tool in this space, and rubbing some rust on it doesn't necessarily make it "fast".

  • Need help developing a high performance Redis ORM for Python
    2 projects | /r/Python | 23 May 2023
    https://github.com/jcrist/msgspec so I am using this instead of Pydantic.
  • Blog post: Writing Python like it’s Rust
    2 projects | /r/Python | 20 May 2023
    Another thing: why pyserde rather than stuff like msgspec? https://github.com/jcrist/msgspec
  • Show HN: Msgspec, a fast serialization/validation library for Python
    1 project | news.ycombinator.com | 11 May 2023
  • [Guide] A Tour Through the Python Framework Galaxy: Discovering the Stars
    14 projects | /r/coder_corner | 29 Apr 2023
    Try msgspec | Maat | turbo for fast serialization and validation
  • Pydantic V2 rewritten in Rust is 5-50x faster than Pydantic V1
    3 projects | news.ycombinator.com | 8 Apr 2023
    Congratulations to the team, Pydantic is an amazing library.

    If you find JSON serialization/deserialization a bottleneck, another interesting library (with much less features) for Python is msgspec: https://github.com/jcrist/msgspec

  • Starlite updates March '22 | 2.0 is coming
    14 projects | /r/Python | 26 Mar 2023
    This feature is yet to be released, but it will allow you to seamlessly use data modelled with for example Pydantic, SQLAlchemy, msgspec or dataclasses in your route handlers, without the need for an intermediary model; The conversion will be handled by the specific DTO "backend" implementation. This new paradigm also makes it trivial to add support for any such modelling library, by simply implementing an appropriate backend.

attrs

Posts with mentions or reviews of attrs. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-08-29.
  • Litestar 2.0
    4 projects | /r/Python | 29 Aug 2023
    Full support for validation and serialisation of attrs classes and msgspec Structs. Where previously only Pydantic models and types where supported, you can now mix and match any of these three libraries. In addition to this, adding support for another modelling library has been greatly simplified with the new plugin architecture
  • Ask HN: How can I get better at writing production-level Python?
    9 projects | news.ycombinator.com | 18 Jul 2023
  • Starlite updates March '22 | 2.0 is coming
    14 projects | /r/Python | 26 Mar 2023
    Pydantic is by far not the only library of its kind, with prominent members of the same class being attrs, cattrs or even plain dataclasses for some use cases.
  • Data Classification: Does Python still have a need for class without dataclass?
    2 projects | news.ycombinator.com | 14 Feb 2023
    Anything requiring e.g. setattr, getattr, delattr? Without looking far,

    https://github.com/python-attrs/attrs/blob/main/src/attr/_ma...

  • What new Python features are the most useful for you?
    2 projects | news.ycombinator.com | 19 Jan 2023
  • Why you should use Data Classes in Python
    2 projects | /r/Python | 16 Sep 2022
  • Python Built-In Functions to Know
    2 projects | news.ycombinator.com | 10 Mar 2022
    I was looking for an example of using locals() to "fill a data class from kwargs" or something similar to that. The example here doesn't use locals().

    That aside, I generally wouldn't use the kwargs approach shown in this example either. I'd use [dataclasses](https://docs.python.org/3/library/dataclasses.html ) or [attrs](https://www.attrs.org/) instead.

  • Building a Micro Business: What Services I Pay For
    16 projects | dev.to | 30 Dec 2021
    hynek: developer of attrs
  • Soap and REST at Odds (2017)
    1 project | news.ycombinator.com | 3 Aug 2021
    I continue to be surprised how easy it can be to consume a SOAP API with the right client libraries. Such as https://docs.python-zeep.org/en/master/ for Python. Now that's not to say it will always work, you can design a terrible API with any mechanism, no SOAP or REST client will help you if the other end has desided to succumb to madness and done something like turn their entire API into just "two endpoints" and driven by the payload content you post to the inbound endpoint, and you have to sit there polling the outbound endpoint with the inbound endpoints response ID because to find out what the eventual response is...

    But horror story aside, consuming a decent SOAP endpoint with a good client library can be practically magical.

    Between attrs (https://www.attrs.org/), cattrs (https://cattrs.readthedocs.io/), and the aforementioned zeep soap client I've got a serialisation pipeline from soap endpoint into an attrs dataclass with type hints and basic type validation down to a snippet so small it fits right here (type hints removed to minimise size).

      from zeep import helpers
  • PEP 661 -- Sentinel Values
    6 projects | /r/Python | 6 Jun 2021
    attrs has at least two.

What are some alternatives?

When comparing msgspec and attrs you can also consider the following projects:

pydantic - Data validation using Python type hints

itsdangerous - Safely pass trusted data to untrusted environments and back.

orjson - Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy

transitions - A lightweight, object-oriented finite state machine implementation in Python with many extensions

fastapi - FastAPI framework, high performance, easy to learn, fast to code, ready for production

pluginbase - A simple but flexible plugin system for Python.

mashumaro - Fast and well tested serialization library

Pychievements - The Python Achievements Framework!

MessagePack - MessagePack serializer implementation for Java / msgpack.org[Java]

Throttler - 🔀⏳ Easy throttling with asyncio support

marshmallow - A lightweight library for converting complex objects to and from simple Python datatypes.

blinker - A fast Python in-process signal/event dispatching system.