Skip to main content

Type hinting package for django

Project description

Django_hint is a module to help you type hint your django project to work with different IDEs. It has been tested in PyCharm and with pylint in VSCode.

Notice: Python3.6 or later is required for this module


You can use the pip to install django_hint

pip3 install django_hint


The following use cases can be type hinted using django_hint to help your IDE recognize the type of variable.

  1. Database QuerySet
  2. WSGIRequest
  3. Django-Rest-Framework Token Authentication
  4. Model Class

As a bonus, all of the native python type hints such as List, Union, Optional etc. from typing module can be imported from django_hint

Database QuerySet

It is used to hint that the variable is an QuerySet object containing multiple objects whose nature we will determine.
You need to hint it to QueryType and pass the object type inside the []. Example:

from django_hint import QueryType

sample_query: QueryType[SampleModel] = SampleModel.objects.filter(name='sample')

The sample_query variable will be treated as a QuerySet. While looping through the objects, each object will be treated as a SampleModel


It is used to hint the nature of the request argument of the view (both function and class based). The request will be treated as a HttpRequest having the user variable attached to it. Example:

from django_hint import RequestType

def sample_view(request: RequestType):
    if request.user.is_authenticated:

Django-Rest-Framework Token Authentication

If you are using the token authentication of the Django-Rest-Framework, the request object will have a user variable and an auth variable of rest_framework.authtoken.models.Token instance. DRFTokenRequestType will hint the IDE of those two variables.

from django_hint import DRFTokenRequestType

def sample_view(request: DRFTokenRequestType):

Model Class

Django adds a few attributes to a Model instance which are not available in the models.Model and will not be available in your IDE. The most notable attribute is the Manager which is accessible via an attribute called objects.
To include these attributes in your IDE, You have to extend your model to the StandardModelType class of django_hint as well as models.Model and use it just like any other model class.
Note that StandardModeltype will NOT have any effect on your database and will NOT make new migrations on makemigrations command.

from django.db import models
from django_hint import StandardModelType

class SampleModel(models.Model, StandardModelType):
    """Just like any other model"""

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_hint-0.2.0.tar.gz (4.9 kB view hashes)

Uploaded source

Built Distribution

django_hint-0.2.0-py3-none-any.whl (7.1 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page