Awesome Python Typing
Collection of awesome Python types, stubs, plugins, and tools to work with them.
Contents
- Static type checkers
- Dynamic type checkers
- Stub packages
- Additional types
- Backports and improvements
- Tools
- Integrations
- Articles
- Communities
- Related
Full list of typed projects on PyPi is here.
Static type checkers
- mypy - Optional static typing (PEP 484).
- pyanalyze - Extensible static analyzer and type checker.
- pycharm - IDE for Professional Developers.
- pyre - Performant type-checker.
- pyright - Fast type checker meant for large Python source bases. It can run in a “watch” mode and performs fast incremental updates when files are modified.
- pytype - Tool to check and infer types - without requiring type annotations.
Dynamic type checkers
- beartype - Unbearably fast
O(1)
runtime type-checking in pure Python. - pydantic - Data parsing using Python type hinting. Supports dataclasses.
- pytypes - Provides a rich set of utilities for runtime typechecking.
- strongtyping - Decorator which checks whether the function is called with the correct type of parameters.
- typeguard - Another one runtime type checker.
- typical - Data parsing and automatic type-coercion using type hinting. Supports dataclasses, standard classes, function signatures, and more.
Stub packages
- asgiref - ASGI specification, provides asgiref.typing module with type annotations for ASGI servers.
- boto3-stubs - Stubs for boto3.
- botostubs - Gives you code assistance for any boto3 API in any IDE.
- data-science-types - Stubs for numpy, pandas, and matplotlib.
- django-stubs - Stubs for Django.
- djangorestframework-stubs - Stubs for DRF.
- grpc-stubs - Stubs for grpc.
- lxml-stubs - Stubs for lxml.
- ordered-set-stubs - Stubs for OrderedSet.
- PyQt5-stubs - Stubs for PyQt5.
- pyspark-stubs - Stubs for PySpark.
- pythonista-stubs - Stubs for Pythonista.
- sqlalchemy-stubs - Stubs for SQLAlchemy.
- sqlalchemy2-stubs - Official stubs and mypy plugin for SQLAlchemy.
- torchtyping - Enhanced type annotations for pytorch.
- typeshed - Collection of library stubs, with static types.
- wsgitypes - Typing for WSGI application implementers. These are not stub files, they're interfaces you mark support for to help typecheck WSGI conformance.
Additional types
- meiga - Simple, typed and monad-based Result type.
- option - Rust like Option and Result types.
- phantom-types - Phantom types.
- returns - Make your functions return something meaningful, typed, and safe.
- safetywrap - Fully typesafe, Rust-like Result and Option types.
- typet - Length-bounded types, dynamic object validation.
Backports and improvements
- typed-ast - Modified fork of CPython's ast module that parses
# type:
comments. - typing-extensions - Backported and experimental type hints.
- typing-utils - Backport 3.8+ runtime typing utils(for eg: get_origin) & add issubtype & more.
- typingplus - Backport support, dynamic is_instance and cast for abstract types.
Tools
Linters
- flake8-annotations-complexity - Plugin for flake8 to validate annotations complexity.
- flake8-annotations - Plugin for flake8 to check for presence of type annotations in function definitions.
- flake8-pyi - Plugin for Flake8 that provides specializations for type hinting stub files.
- flake8-type-checking - Plugin to help you guard any type-annotation-only import correctly.
- flake8-typing-imports - Plugin which checks that typing imports are properly guarded.
- flake8-typing-only-imports - flake8 plugin that helps identify which imports to put into type-checking blocks, and how to adjust your type annotations once imports are moved.
- wemake-python-styleguide - The strictest and most opinionated Python linter ever.
Testing
- pytest-mypy-plugins - Pytest plugin for testing mypy types, stubs, and plugins.
- pytest-mypy-testing - Pytest plugin to test mypy static type analysis.
- pytest-mypy - Mypy static type checker plugin for Pytest.
Working with types
- com2ann - Tool for translation of type comments to type annotations.
- merge-pyi - Part of pytype toolchain, applies stub files onto source code.
- mypy-protobuf - Tool to generate mypy stubs from protobufs.
- mypy-silent - Silence mypy by adding or removing code comments.
- mypyc - Compiles mypy-annotated, statically typed Python modules into CPython C extensions.
- retype - Another tool to apply stubs to code.
- pep585-upgrade - Pre-commit hook configured to automatically upgrade your type hints to the new native types implemented in PEP 585.
- typing-inspect - The typing_inspect module defines experimental API for runtime inspection of types defined in the
typing
module. - typing-json - Lib for working with typed objects and JSON.
Helper tools to add annotations to existing code
- autotyper - Automatically add simple return type annotations for functions (bool, None, Optional).
- monkeytype - Collects runtime types of function arguments and return values, and can automatically generate stub files or even add draft type annotations directly to your code based on the types collected at runtime.
- pyannotate - Insert annotations into your source code based on call arguments and return types observed at runtime.
- pyre infer - Pyre has a powerful feature for migrating codebases to a typed format. The infer command-line option ingests a file or directory, makes educated guesses about the types used, and applies the annotations to the files.
- pytest-annotate - Pyannotate plugin for pytest.
- pytest-monkeytype - MonkeyType plugin for pytest.
- pytype annotate-ast - A work-in-progress tool to annotate the nodes of an AST with their Python types.
- type4py - Deep Similarity Learning-Based Type Inference.
- typilus - A deep learning algorithm for predicting types in Python. Also available as a GitHub action
Mypy plugins
- kubernetes-typed - Plugin for kubernetes CRD type checking.
- loguru-mypy - Plugin for loguru support.
- mypy-zope - Plugin for zope.interface support.
- mypy/plugins - Plugins already integrated into mypy.
- numpy - Plugin for NumPy support.
- pynamodb-mypy - Plugin for PynamoDB support.
Integrations
- emacs-flycheck-mypy - Mypy integration for Emacs.
- linter-mypy - Mypy integration for Atom.
- mypy-playground - Online playground for mypy.
- mypy-pycharm-plugin - Mypy integration for PyCharm.
- pylance - PyRight integration for VSCode.
- vim-mypy - Mypy integration for Vim.
- nbQA - Run type checkers (e.g. Mypy) on Jupyter Notebooks.
Articles
PEPs
- PEP-3107 - Function Annotations.
- PEP-482 - Literature Overview for Type Hints.
- PEP-483 - The Theory of Type Hints.
- PEP-484 - Type Hints.
- PEP-526 - Syntax for Variable Annotations.
- PEP-544 - Protocols: Structural subtyping (static duck typing).
- PEP-557 - Data Classes.
- PEP-560 - Core support for typing module and generic types.
- PEP-561 - Distributing and Packaging Type Information.
- PEP-563 - Postponed Evaluation of Annotations.
- PEP-585 - Type Hinting Generics In Standard Collections.
- PEP-586 - Literal Types.
- PEP-589 - TypedDict: Type Hints for Dictionaries with a Fixed Set of Keys.
- PEP-591 - Adding a final qualifier to typing.
- PEP-593 - Flexible function and variable annotations.
- PEP-604 - Complementary syntax for Union[].
- PEP-612 - Parameter Specification Variables.
- PEP-613 - Explicit Type Aliases.
Third-party articles
- 1-minute guide to real constants in Python - Full tutorial about
Final
constants and inheritance. - Simple dependent types in Python - Full tutorial about
Literal
types. - Testing mypy stubs, plugins, and types - Full tutorial about testing mypy types.
- PyTest MonkeyType Introduction - Type Annotate an existing Python Django Codebase with MonkeyType.
- The state of type hints in Python - As of May 2018.
- Type hints cheat sheet - Cheat sheet on writing type annotations by MyPy team.
- Typechecking Django and DRF - Full tutorial about type-checking django.
- Type Check Your Django Application - An article based on two recent talks on adding type checks to Django.
- typing - Official Python documentation for
typing
module.
Communities
- python/typing - Official typing gitter chat.
- TypedDjango - Official organisation gitter chat.
- PythonRu#typing - Russian slack chat (invites are here) about types.
Related
- awesome-python - Curated list of awesome Python frameworks, libraries, software and resources.
- python-typecheckers - List of Python type checkers: static and runtime.