pydantic
mypy
| pydantic | mypy | |
|---|---|---|
| 183 | 130 | |
| 26,209 | 20,084 | |
| 2.3% | 0.7% | |
| 9.8 | 9.9 | |
| 5 days ago | 6 days ago | |
| Python | Python | |
| MIT License | GNU General Public License v3.0 or later |
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.
pydantic
- Python Design Patterns for Clean Architecture
Pydantic Documentation
- I built binary serializer for Pydantic models that's up to 7× smaller than JSON
Found in issue where maintainer answered that they are only going to support JSON
https://github.com/pydantic/pydantic/discussions/4097
- Dict Unpacking in Python
- A Practical Guide on Structuring LLM Outputs with Pydantic
The solution? Leverage Pydantic, a Python library that enables runtime data validation using type annotations.
- Loading Pydantic models from JSON without running out of memory
Pydantic author here. We have plans for an improvement to pydantic where JSON is parsed iteratively, which will make way for reading a file as we parse it. Details in https://github.com/pydantic/pydantic/issues/10032.
Our JSON parser, jiter (https://github.com/pydantic/jiter) already supports iterative parsing, so it's "just" a matter of solving the lifetimes in pydantic-core to validate as we parse.
This should make pydantic around 3x faster at parsing JSON and significantly reduce the memory overhead.
- Advanced Pydantic: Generic Models, Custom Types, and Performance Tricks
Across this five-post series, we’ve journeyed from Pydantic’s basics—type validation and nested models—to advanced integrations with FastAPI, SQLAlchemy, and scalable techniques. You’ve learned how to build declarative, type-safe models, handle complex APIs, and optimize performance. To deepen your knowledge, explore the Pydantic documentation, contribute to the open-source project, or experiment with real-world use cases. Check out our GitHub repo for code samples and a Pydantic cheat sheet. Thank you for joining us—happy coding!
- Getting Started with Pydantic: Type-Safe Data Models in Python
To dive deeper, check out the Pydantic documentation for advanced features like nested models, custom validators, and settings management. Happy coding!
- Resumindo características da linguagem Python
- FastAPI, Pydantic, Psycopg3: the holy trinity for Python web APIs
Pydantic is bundled with FastAPI and is excellent for modelling, validating, and serialising API responses.
- Pydantic Settings + AWS the easy way
Pydantic Settings is a python library that extends 🚀 Pydantic for dealing with settings management.
mypy
- A "Frozen" Dictionary for Python
- "Final names and attributes" https://github.com/python/mypy/pull/5522
- Type hints in Python (4)
Hashable cannot be used for an iterator even it's immutable according to the issue.
- Type hints in Python (2)
I reported the strange behaviour as the issue.
- Type hints in Python (1)
is used with the type checkers such as mypy, pyright, pyre-check, pytype, etc.
- Baby's First Type Checker
It's not so bad here, but with a big enough language, and more complicated algorithms, it gets unwieldy.
That said, I agreed here that visitors are useful when you need to say traverse all string literals in an AST, at arbitrary depths: https://lobste.rs/s/jdgjjt/visitor_pattern_considered_pointl...
---
A sign that this issue isn't settled is that two of the more complex type checkers make opposite decisions
- MyPy uses visitors extensively - https://github.com/python/mypy/tree/master/mypy
- TypeScript mostly uses switch/case functions - https://github.com/microsoft/TypeScript/blob/main/src/compil...
I'd be interested in analysis of why that is, but I suspect it's mainly style
- Ty: An fast Python type checker and language server, written in Rust
https://github.com/python/mypy/blob/501a07b45af8e44eda665e53...
Also did you know mypy ignores typing of class decorators? You simply can't return a different type other than type[thisclass].
- Mypy – an optional static type checker for Python
- You Need Subtyping
To expand on this, you could be maintaining a list of Cats, call a function which accepts a list of Animals, and that function could append a Dog without causing a type error.
https://github.com/python/mypy/issues/4976 is an interesting discussion on this in Python: should a TypedDict be allowed where a dict argument is accepted? The basic consensus is no, because then one could modify the dict, adding keys that wouldn't be allowed in the specific TypedDict.
But this means that often you have to do cast(dict, my_typed_dict) to be able to interop with third party libraries that (quite naturally) believed that by typing their arguments as accepting a dict, they'd be accepting all dict-like things.
- Top Tools for Static Analysis Help in Your Python Projects
Mypy:
- What I wish I knew about Python when I started
Hynek Schlawack, a well-known Pythonista and open source contributor, has recommended not to run mypy as part of your pre-commit workflows. And Shantanu Jain, a CPython core developer and mypy maintainer, has an excellent write-up of some of the gotchas that come with running mypy as a pre-commit hook. By default, mypy runs in an isolated environment, meaning it won't have access to your project's virtual environment and therefore won't be able to fully analyze type hints when your code makes use of dependencies. Additionally, pre-commit hooks only pass the changed/staged files by default, whereas mypy needs to see the entire repository to function correctly. I've also noticed nesting your code under other folders (like my backend/ directory) can also cause problems.
What are some alternatives?
msgspec - A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML
ruff - An extremely fast Python linter and code formatter, written in Rust.
pyparsing - Python library for creating PEG parsers
pyright - Static Type Checker for Python
typeguard - Run-time type checker for Python
black - The uncompromising Python code formatter