Skip to content

PyCharm SQLAlchemy Plugin

icon
Kotlin
icon
PyCharm

A PyCharm plugin that fixes type resolution for SQLAlchemy 2.0's Mapped[T] annotations. PyCharm incorrectly flags valid SQLAlchemy code as type errors — this plugin hooks into the IDE's type provider system to correctly resolve mapped attributes on both instances and classes, supporting features like @hybrid_property and @declared_attr. A weekend hack that picked up 20 stars on GitHub.

Features

Mapped Type Resolution

Correctly resolves Mapped[T] attributes: returns T on instances (for assignments) and InstrumentedAttribute[T] on classes (for query building). Handles inheritance and mixins.

Hybrid Property Support

Recognizes @hybrid_property and @declared_attr decorators, distinguishing between instance access (returns the value type) and class access (returns ColumnElement[T] for query expressions).

Binary Expression Fix

Fixes type checking for equality comparisons like Entity.column == value, which PyCharm incorrectly flags. Uses a type checker extension that hooks into PyCharm's internal evaluation to resolve the correct return type.