Skip to main content

pandera-mypy

A mypy plugin that resolves Pandera DataFrameModel column attributes as str, eliminating false type errors when passing column names to polars.col() or any other str-expecting API.

The Problem

Pandera's DataFrameModel supports a convenient bare-type shorthand for column annotations, where a plain Python type is used instead of the full Series[T] form:

import pandera.polars as pa

class MySchema(pa.DataFrameModel):
    quantity: int   # shorthand for Series[int]
    label: str      # shorthand for Series[str]

At runtime, accessing a column attribute always returns its name as a plain str:

>>> MySchema.quantity
'quantity'
>>> MySchema.label
'label'

Without the plugin, mypy infers the declared type (int, str, …) rather than str, causing spurious errors when column names are passed to polars.col() or any other str-expecting API:

import polars as pl

pl.col(MySchema.quantity)
# ^ error: Argument 1 to "col" has incompatible type "int"; expected "str"

Series[T] annotations: Pandera's bundled stubs already type class-level attribute access as str for Series[T]-annotated columns across all supported versions (0.21.1-0.31.1). The plugin ensures uniform str inference when schemas mix Series[T] and bare-type annotations.

The Solution

This plugin overrides the inferred type of every column-annotated attribute on a DataFrameModel subclass to str, matching the actual runtime behaviour — no changes to your Pandera models required.

# With the plugin enabled:
pl.col(MySchema.quantity)         # ✅  no error
col_name: str = MySchema.quantity # ✅  no error

Installation

pip install pandera-mypy
# or with uv:
uv add pandera-mypy

Configuration

Add the plugin to your mypy configuration and that's it:

mypy.ini

[mypy]
plugins = pandera_mypy.plugin

pyproject.toml

[tool.mypy]
plugins = ["pandera_mypy.plugin"]

setup.cfg

[mypy]
plugins = pandera_mypy.plugin

Compatibility

Python Supported
3.10 ✅
3.11 ✅
3.12 ✅
3.13 ✅
3.14 ✅

Requires mypy >= 1.0.0 and works with both the Polars and Pandas backends of Pandera.

How It Works

The plugin implements mypy's get_class_attribute_hook (for MySchema.price style class-level access) and get_attribute_hook (for instance-level access).

For every attribute access, it checks whether:

  1. The owning class inherits from a Pandera DataFrameModel (detected via the MRO, so indirect subclasses work too).
  2. The attribute is annotated with a Pandera column type — either Series[T] or a bare type such as int.

When both conditions hold, the plugin replaces the inferred type with builtins.str.

Why get_class_attribute_hook?
Mypy routes class-level attribute access (e.g. MySchema.price) through get_class_attribute_hook in mypy.checkmember, not through get_attribute_hook. Using only get_attribute_hook would leave the common pl.col(MySchema.price) pattern uncorrected.

Development

# Install all dependencies including the dev group
uv sync --group dev

# Run the test suite with coverage
uv run pytest

# Type-check the plugin
uv run mypy src

# Lint (report only)
uv run ruff check .

# Lint and auto-fix
uv run ruff check --fix .

# Format
uv run ruff format .

# Check formatting without changing files
uv run ruff format --check .

# Verify the lockfile is up to date with pyproject.toml
uv lock --check

# Build the wheel and sdist
uv build

Metadata

Release files for pandera-mypy 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pandera-mypy 0.0.1
File Size Uploaded Provenance Actions
pandera_mypy-0.0.1.tar.gz 62.7 kB With provenance Details for pandera_mypy-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pandera-mypy 0.0.1
File Interpreter ABI Platform Actions
pandera_mypy-0.0.1-py3-none-any.whl Python 3 none any Details for pandera_mypy-0.0.1-py3-none-any.whl

Total release size: 69.6 kB

Release files / pandera_mypy-0.0.1.tar.gz

Download URL pandera_mypy-0.0.1.tar.gz
Size 62.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6c0f0b973327ad22c5f17489e65f1f1ccd22e048f95b910a473464029c23c6ab
BLAKE2b-256 checksum
How to use checksums
623529f409cbeb0d8d58504324ad9d9a4d1a8554855a8fdd91a3904e9b45723a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 10, 2026.

Transparency log

Release files / pandera_mypy-0.0.1-py3-none-any.whl

Download URL pandera_mypy-0.0.1-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c456c917b3f0ec56fa9e0e3d603996876fd74528d7f6f87b2a912325182eaca5
BLAKE2b-256 checksum
How to use checksums
16ef3ff6dd66e27216a63c3f65e0ffb0730e8ac74712db678c9d4e93328b4ce9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 10, 2026.

Transparency log

Security for pandera-mypy 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pandera_mypy-0.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page