Mypy plugin and type stubs for SQLAlchemy to enable precise static type checking in Python.
SQLAlchemy-stubs is a mypy plugin and set of type stubs that provide precise static type checking for SQLAlchemy, a Python SQL toolkit and ORM. It solves the problem of typing SQLAlchemy's dynamic code patterns, allowing developers to catch type errors during development and improve code reliability. The project infers accurate types for model attributes, columns, and relationships, integrating seamlessly with mypy.
Python developers using SQLAlchemy who want to enhance code safety and maintainability through static type checking, particularly those working on larger codebases or teams where early error detection is critical.
Developers choose SQLAlchemy-stubs because it uniquely bridges SQLAlchemy's flexibility with rigorous static typing, offering precise type inference for common patterns without modifying SQLAlchemy itself. Its mypy plugin integration ensures compatibility and ease of adoption for existing mypy users.
Mypy plugin and stubs for SQLAlchemy
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Infers precise types for model attributes and columns, catching mismatches like assigning an int to a string column, as shown in the README example with User(id=42, name=42).
The mypy plugin understands SQLAlchemy's dynamic patterns, such as string-based relationship references, enabling seamless type checking without modifying SQLAlchemy code.
Allows static type checking to catch type errors during development, improving code reliability and reducing runtime bugs in SQLAlchemy-based applications.
Supports simple relationships with forward references via TYPE_CHECKING imports or string literals, making common ORM patterns type-safe without manual workarounds.
As an alpha-stage project, it lacks support for precise typing in key areas like table definitions and query results, limiting usefulness for complex SQLAlchemy usage.
The plugin is designed exclusively for mypy, so teams using alternative type checkers like Pyright cannot benefit without switching tools, creating vendor lock-in.
Requires enabling the plugin in mypy config files, adding an extra setup step compared to standard type stubs, which can be a barrier for quick adoption.