djangorestframework-stubs


Namedjangorestframework-stubs JSON
Version 3.14.5 PyPI version JSON
download
home_pagehttps://github.com/typeddjango/djangorestframework-stubs
SummaryPEP-484 stubs for django-rest-framework
upload_time2023-12-05 19:21:11
maintainerMarti Raudsepp
docs_urlNone
authorMaksim Kurnikov
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="http://mypy-lang.org/static/mypy_light.svg" alt="mypy logo" width="300px"/>

# pep484 stubs for Django REST framework

[![Build Status](https://travis-ci.com/typeddjango/djangorestframework-stubs.svg?branch=master)](https://travis-ci.com/typeddjango/djangorestframework-stubs)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![Gitter](https://badges.gitter.im/mypy-django/Lobby.svg)](https://gitter.im/mypy-django/Lobby)


Mypy stubs for [Django REST Framework](https://pypi.org/project/djangorestframework/).
Supports Python 3.8 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 `Union[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!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/typeddjango/djangorestframework-stubs",
    "name": "djangorestframework-stubs",
    "maintainer": "Marti Raudsepp",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "marti@juffo.org",
    "keywords": "",
    "author": "Maksim Kurnikov",
    "author_email": "maxim.kurnikov@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/cc/51/ef2f2196e81c261490e86c15b78f5a097d825b58f5ceb615bcece612eeb9/djangorestframework-stubs-3.14.5.tar.gz",
    "platform": null,
    "description": "<img src=\"http://mypy-lang.org/static/mypy_light.svg\" alt=\"mypy logo\" width=\"300px\"/>\n\n# pep484 stubs for Django REST framework\n\n[![Build Status](https://travis-ci.com/typeddjango/djangorestframework-stubs.svg?branch=master)](https://travis-ci.com/typeddjango/djangorestframework-stubs)\n[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)\n[![Gitter](https://badges.gitter.im/mypy-django/Lobby.svg)](https://gitter.im/mypy-django/Lobby)\n\n\nMypy stubs for [Django REST Framework](https://pypi.org/project/djangorestframework/).\nSupports Python 3.8 and up.\n\n## Installation\n\n```bash\npip install djangorestframework-stubs[compatible-mypy]\n```\n\nTo make mypy aware of the plugin, you need to add\n\n```ini\n[mypy]\nplugins =\n    mypy_drf_plugin.main\n```\n\nin your `mypy.ini` file.\n\n## FAQ\n\n### Model instance is inferred as `Any` instead of my `Model` class\n\nWhen subclassing `ModelSerializer`, add a [type argument](https://peps.python.org/pep-0484/#generics) to type-hint the related model class, for example:\n\n```python\nclass MyModelSerializer(serializers.ModelSerializer[MyModel]):\n    class Meta:\n        model = MyModel\n        fields = (\"id\", \"example\")\n```\n\nWhich 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 `Union[MyModel, typing.Sequence[MyModel], None]`.\n\n## To get help\n\nWe have Gitter here: <https://gitter.im/mypy-django/Lobby>\nIf you think you have more generic typing issue, please refer to <https://github.com/python/mypy> and their Gitter.\n\n## Contributing\n\nThis project is open source and community driven. As such we encourage contributions big and small. You can contribute by doing any of the following:\n\n1. Contribute code (e.g. improve stubs, add plugin capabilities, write tests etc) - to do so please follow the [contribution guide](./CONTRIBUTING.md).\n2. Assist in code reviews and discussions in issues.\n3. Identify bugs and issues and report these\n\nYou can always also reach out in gitter to discuss your contributions!\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "PEP-484 stubs for django-rest-framework",
    "version": "3.14.5",
    "project_urls": {
        "Homepage": "https://github.com/typeddjango/djangorestframework-stubs",
        "Release notes": "https://github.com/typeddjango/djangorestframework-stubs/releases"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1305c98a1e3d3824dc9a330df26827935b5d7559a5c01bcfca8e18ab645dc758",
                "md5": "b8ef49877724aab5e5d1910cfc78d0d1",
                "sha256": "43d788fd50cda49b922cd411e59c5b8cdc3f3de49c02febae12ce42139f0269b"
            },
            "downloads": -1,
            "filename": "djangorestframework_stubs-3.14.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b8ef49877724aab5e5d1910cfc78d0d1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 53481,
            "upload_time": "2023-12-05T19:21:09",
            "upload_time_iso_8601": "2023-12-05T19:21:09.215203Z",
            "url": "https://files.pythonhosted.org/packages/13/05/c98a1e3d3824dc9a330df26827935b5d7559a5c01bcfca8e18ab645dc758/djangorestframework_stubs-3.14.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cc51ef2f2196e81c261490e86c15b78f5a097d825b58f5ceb615bcece612eeb9",
                "md5": "66b0dd2c8d9ed484adebff869b657af6",
                "sha256": "5dd6f638aa5291fb7863e6166128a6ed20bf4986e2fc5cf334e6afc841797a09"
            },
            "downloads": -1,
            "filename": "djangorestframework-stubs-3.14.5.tar.gz",
            "has_sig": false,
            "md5_digest": "66b0dd2c8d9ed484adebff869b657af6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 34281,
            "upload_time": "2023-12-05T19:21:11",
            "upload_time_iso_8601": "2023-12-05T19:21:11.739481Z",
            "url": "https://files.pythonhosted.org/packages/cc/51/ef2f2196e81c261490e86c15b78f5a097d825b58f5ceb615bcece612eeb9/djangorestframework-stubs-3.14.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-05 19:21:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "typeddjango",
    "github_project": "djangorestframework-stubs",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "djangorestframework-stubs"
}
        
Elapsed time: 0.68144s