Metadata-Version: 2.4
Name: djangorestframework-stubs
Version: 3.17.0
Summary: PEP-484 stubs for django-rest-framework
Author: Maksim Kurnikov
Author-email: Maksim Kurnikov <maxim.kurnikov@gmail.com>
License-Expression: MIT
License-File: LICENSE.txt
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Classifier: Framework :: Django
Requires-Dist: django-stubs>=6.0.4
Requires-Dist: typing-extensions>=4.0
Requires-Dist: types-pyyaml
Requires-Dist: mypy>=1.13,<2.2 ; extra == 'compatible-mypy'
Requires-Dist: django-stubs[compatible-mypy] ; extra == 'compatible-mypy'
Requires-Dist: coreapi>=2.0.0 ; extra == 'coreapi'
Requires-Dist: types-markdown>=0.1.5 ; extra == 'markdown'
Requires-Dist: types-requests ; extra == 'requests'
Maintainer: Marti Raudsepp, Nikita Sobolev
Maintainer-email: Marti Raudsepp <marti@juffo.org>, Nikita Sobolev <mail@sobolevn.me>
Requires-Python: >=3.10
Project-URL: Homepage, https://github.com/typeddjango/djangorestframework-stubs
Project-URL: Funding, https://github.com/sponsors/typeddjango
Project-URL: Release notes, https://github.com/typeddjango/djangorestframework-stubs/releases
Provides-Extra: compatible-mypy
Provides-Extra: coreapi
Provides-Extra: markdown
Provides-Extra: requests
Description-Content-Type: text/markdown

<img src="https://mypy-lang.org/static/mypy_light.svg" alt="mypy logo" width="300px"/>

# pep484 stubs for Django REST framework

[![test](https://github.com/typeddjango/djangorestframework-stubs/actions/workflows/test.yml/badge.svg?branch=master&event=push)](https://github.com/typeddjango/djangorestframework-stubs/actions/workflows/test.yml)
[![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)
[![Gitter](https://badges.gitter.im/mypy-django/Lobby.svg)](https://gitter.im/mypy-django/Lobby)
[![StackOverflow](https://shields.io/badge/ask-stackoverflow-orange?logo=stackoverflow)](https://stackoverflow.com/questions/tagged/django-stubs?tab=Active)


Mypy stubs for [Django REST Framework](https://pypi.org/project/djangorestframework/).
Supports Python 3.10 and up.

## Installation

```bash
pip install djangorestframework-stubs[compatible-mypy]
```

To make mypy aware of the plugin, you need to add

```ini
[mypy]
plugins =
    mypy_drf_plugin.main
```

in your `mypy.ini` file.

## FAQ

### Model instance is inferred as `Any` instead of my `Model` class

When subclassing `ModelSerializer`, add a [type argument](https://peps.python.org/pep-0484/#generics) to type-hint the related model class, for example:

```python
class MyModelSerializer(serializers.ModelSerializer[MyModel]):
    class Meta:
        model = MyModel
        fields = ("id", "example")
```

Which means that methods where the model is being passed around will know the actual type of the model instead of being `Any`. The `instance` attribute on the above serializer will be `MyModel | typing.Sequence[MyModel] | None`.

## To get help

We have Gitter here: <https://gitter.im/mypy-django/Lobby>
If you think you have more generic typing issue, please refer to <https://github.com/python/mypy> and their Gitter.

## Contributing

This project is open source and community driven. As such we encourage contributions big and small. You can contribute by doing any of the following:

1. Contribute code (e.g. improve stubs, add plugin capabilities, write tests etc) - to do so please follow the [contribution guide](./CONTRIBUTING.md).
2. Assist in code reviews and discussions in issues.
3. Identify bugs and issues and report these

You can always also reach out in gitter to discuss your contributions!
