skillfed

django-types

Type stubs for Django

django-types v0.24.0 1.1M downloads/30d#4,409 on PyPI341
Permissive license MIT Active released

What it is and what it does

django-types is a type stub package that adds static type information for Django, enabling type checkers like mypy and pyright to understand Django's API. It was forked from django-stubs specifically to remove the mypy plugin dependency, which means it works with multiple type checkers and avoids crashes caused by Django configuration issues.

The package helps developers annotate Django models, querysets, managers, and HTTP request objects with proper types. It includes guidance for common patterns like foreign key relationships, related managers, and authenticated request handlers. Since Django's ORM classes don't support runtime subscripting (e.g., QuerySet[MyModel]), the stubs document workarounds using string annotations or a companion monkeypatch utility.

Use it for:

  • Add type hints to Django ORM models so foreign keys and related managers are properly typed for IDE autocomplete and type checking
  • Enable pyright or other non-mypy type checkers to validate Django code without plugin crashes
  • Annotate view functions with typed HttpRequest subclasses to enforce authentication requirements at the type level
  • Catch type errors in Django querysets and manager calls during development rather than at runtime

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides type stubs for Django to enable static type checking with mypy, pyright, and other type checkers without requiring a mypy plugin.

Yes. django-types is actively maintained, has no known vulnerabilities, low install friction, and is essential for any Django project using static type checking. The MIT license is permissive. Install it if you use type checkers with Django; it's a standard practice for modern Django development.

Install

django-types on PyPI

pip

pip install django-types

uv

uv add django-types

poetry

poetry add django-types

Installing django-types

Before you install

Low install friction with a single runtime dependency (types-psycopg2). Actively maintained with recent releases; last commit 2026-06-23 and latest release 2026-04-22.

License in practice

MIT license permits commercial and private use with minimal restrictions; suitable for most projects.

Quickstart

pip install django-types

# In your Django model:
from typing import Optional
from django.db import models

class User(models.Model):
    team_id: Optional[int]
    team = models.ForeignKey('Team', null=True, on_delete=models.SET_NULL)

Requires Python 3.10 or later. QuerySet and Manager generics do not support subscripting at runtime; use string annotations or django_stubs_ext.monkeypatch() as a workaround.

Verify before relying

  • Whether type coverage is complete for all Django ORM features and edge cases
  • Performance impact of type checking with these stubs on typical Django projects

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 1 — types-psycopg2
Maintenance actively maintained — 114 days since the last release
Last repo commit
First released
Downloads 1,069,134/month — #4,409 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: django_types-0.24.0-py3-none-any.whl

Keywords: django, mypy, stubs, types

Tags

django type stubsdjango type checkingdjango mypy typesdjango pyright supportdjango static typingdjango type hintsdjango orm type annotations
type-stubsdjangostatic-typing

More Application Frameworks packages