# Strawberry GraphQL Django integration
[](https://github.com/strawberry-graphql/strawberry-django/actions/workflows/tests.yml)
[](https://codecov.io/gh/strawberry-graphql/strawberry-django)
[](https://pypi.org/project/strawberry-graphql-django/)
[](https://pepy.tech/project/strawberry-graphql-django)

[**Docs**](https://strawberry.rocks/docs/django) | [**Discord**](https://strawberry.rocks/discord)
This package provides powerful tools to generate GraphQL types, queries,
mutations and resolvers from Django models.
Installing `strawberry-graphql-django` package from the python package repository.
```shell
pip install strawberry-graphql-django
```
## Supported Features
- [x] GraphQL type generation from models
- [x] Filtering, pagination and ordering
- [x] Basic create, retrieve, update and delete (CRUD) types and mutations
- [x] Basic Django auth support, current user query, login and logout mutations
- [x] Django sync and async views
- [x] Permission extension using django's permissioning system
- [x] Relay support with automatic resolvers generation
- [x] Query optimization to improve performance and avoid common pitfalls (e.g n+1)
- [x] Debug Toolbar integration with graphiql to display metrics like SQL queries
- [x] Unit test integration
## Basic Usage
```python
# models.py
from django.db import models
class Fruit(models.Model):
"""A tasty treat"""
name = models.CharField(
max_length=20,
)
color = models.ForeignKey(
"Color",
on_delete=models.CASCADE,
related_name="fruits",
blank=True,
null=True,
)
class Color(models.Model):
name = models.CharField(
max_length=20,
help_text="field description",
)
```
```python
# types.py
import strawberry_django
from strawberry import auto
from . import models
@strawberry_django.type(models.Fruit)
class Fruit:
id: auto
name: auto
color: 'Color'
@strawberry_django.type(models.Color)
class Color:
id: auto
name: auto
fruits: list[Fruit]
```
```python
# schema.py
import strawberry
import strawberry_django
from strawberry_django.optimizer import DjangoOptimizerExtension
from .types import Fruit
@strawberry.type
class Query:
fruits: list[Fruit] = strawberry_django.field()
schema = strawberry.Schema(
query=Query,
extensions=[
DjangoOptimizerExtension, # not required, but highly recommended
],
)
```
```python
# urls.py
from django.urls import include, path
from strawberry.django.views import AsyncGraphQLView
from .schema import schema
urlpatterns = [
path('graphql', AsyncGraphQLView.as_view(schema=schema)),
]
```
Code above generates following schema.
```graphql
"""
A tasty treat
"""
type Fruit {
id: ID!
name: String!
color: Color
}
type Color {
id: ID!
"""
field description
"""
name: String!
fruits: [Fruit!]
}
type Query {
fruits: [Fruit!]!
}
```
## Contributing
We use [poetry](https://github.com/sdispater/poetry) to manage dependencies, to
get started follow these steps:
```shell
$ git clone https://github.com/strawberry-graphql/strawberry-django
$ cd strawberry-django
$ python -m pip install poetry
$ make install
```
### Running tests
Using [make](Makefile) to run the tests:
```shell
$ make test
```
To run tests in parallel:
```shell
$ make test-dist
```
### Pre commit
We have a configuration for
[pre-commit](https://github.com/pre-commit/pre-commit), to add the hook run the
following command:
```shell
pre-commit install
```
Raw data
{
"_id": null,
"home_page": "https://github.com/strawberry-graphql/strawberry-django",
"name": "strawberry-graphql-django",
"maintainer": "Thiago Bellini Ribeiro",
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": "thiago@bellini.dev",
"keywords": "graphql, api, django, strawberry-graphql",
"author": "Lauri Hintsala",
"author_email": "lauri.hintsala@verkkopaja.fi",
"download_url": "https://files.pythonhosted.org/packages/2e/7e/90e1dc9db01f54dd2cec56867d5eb1d5feb7d549c6f6f54d7515bd371a8c/strawberry_graphql_django-0.65.1.tar.gz",
"platform": null,
"description": "# Strawberry GraphQL Django integration\n\n[](https://github.com/strawberry-graphql/strawberry-django/actions/workflows/tests.yml)\n[](https://codecov.io/gh/strawberry-graphql/strawberry-django)\n[](https://pypi.org/project/strawberry-graphql-django/)\n[](https://pepy.tech/project/strawberry-graphql-django)\n\n\n[**Docs**](https://strawberry.rocks/docs/django) | [**Discord**](https://strawberry.rocks/discord)\n\nThis package provides powerful tools to generate GraphQL types, queries,\nmutations and resolvers from Django models.\n\nInstalling `strawberry-graphql-django` package from the python package repository.\n\n```shell\npip install strawberry-graphql-django\n```\n\n## Supported Features\n\n- [x] GraphQL type generation from models\n- [x] Filtering, pagination and ordering\n- [x] Basic create, retrieve, update and delete (CRUD) types and mutations\n- [x] Basic Django auth support, current user query, login and logout mutations\n- [x] Django sync and async views\n- [x] Permission extension using django's permissioning system\n- [x] Relay support with automatic resolvers generation\n- [x] Query optimization to improve performance and avoid common pitfalls (e.g n+1)\n- [x] Debug Toolbar integration with graphiql to display metrics like SQL queries\n- [x] Unit test integration\n\n## Basic Usage\n\n```python\n# models.py\n\nfrom django.db import models\n\nclass Fruit(models.Model):\n \"\"\"A tasty treat\"\"\"\n name = models.CharField(\n max_length=20,\n )\n color = models.ForeignKey(\n \"Color\",\n on_delete=models.CASCADE,\n related_name=\"fruits\",\n blank=True,\n null=True,\n )\n\nclass Color(models.Model):\n name = models.CharField(\n max_length=20,\n help_text=\"field description\",\n )\n```\n\n```python\n# types.py\n\nimport strawberry_django\nfrom strawberry import auto\n\nfrom . import models\n\n@strawberry_django.type(models.Fruit)\nclass Fruit:\n id: auto\n name: auto\n color: 'Color'\n\n@strawberry_django.type(models.Color)\nclass Color:\n id: auto\n name: auto\n fruits: list[Fruit]\n```\n\n```python\n# schema.py\n\nimport strawberry\nimport strawberry_django\nfrom strawberry_django.optimizer import DjangoOptimizerExtension\n\nfrom .types import Fruit\n\n@strawberry.type\nclass Query:\n fruits: list[Fruit] = strawberry_django.field()\n\nschema = strawberry.Schema(\n query=Query,\n extensions=[\n DjangoOptimizerExtension, # not required, but highly recommended\n ],\n)\n```\n\n```python\n# urls.py\n\nfrom django.urls import include, path\nfrom strawberry.django.views import AsyncGraphQLView\n\nfrom .schema import schema\n\nurlpatterns = [\n path('graphql', AsyncGraphQLView.as_view(schema=schema)),\n]\n```\n\nCode above generates following schema.\n\n```graphql\n\"\"\"\nA tasty treat\n\"\"\"\ntype Fruit {\n id: ID!\n name: String!\n color: Color\n}\n\ntype Color {\n id: ID!\n \"\"\"\n field description\n \"\"\"\n name: String!\n fruits: [Fruit!]\n}\n\ntype Query {\n fruits: [Fruit!]!\n}\n```\n\n## Contributing\n\nWe use [poetry](https://github.com/sdispater/poetry) to manage dependencies, to\nget started follow these steps:\n\n```shell\n$ git clone https://github.com/strawberry-graphql/strawberry-django\n$ cd strawberry-django\n$ python -m pip install poetry\n$ make install\n```\n\n### Running tests\n\nUsing [make](Makefile) to run the tests:\n\n```shell\n$ make test\n```\n\nTo run tests in parallel:\n\n```shell\n$ make test-dist\n```\n\n### Pre commit\n\nWe have a configuration for\n[pre-commit](https://github.com/pre-commit/pre-commit), to add the hook run the\nfollowing command:\n\n```shell\npre-commit install\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Strawberry GraphQL Django extension",
"version": "0.65.1",
"project_urls": {
"Documentation": "https://strawberry.rocks/docs/django",
"Homepage": "https://github.com/strawberry-graphql/strawberry-django",
"Repository": "https://github.com/strawberry-graphql/strawberry-django"
},
"split_keywords": [
"graphql",
" api",
" django",
" strawberry-graphql"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6c0e73bc5ae3bc8fb006cc959155e8ed2b017b2019e50f68361e8db9e3662d9a",
"md5": "3c5b888e83491a98287f948deb31fc00",
"sha256": "e0a69af97c50deb07197641cd0b7320e25b5a3148a05ae6006d1bf5103530e85"
},
"downloads": -1,
"filename": "strawberry_graphql_django-0.65.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3c5b888e83491a98287f948deb31fc00",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 107893,
"upload_time": "2025-07-26T10:54:47",
"upload_time_iso_8601": "2025-07-26T10:54:47.139877Z",
"url": "https://files.pythonhosted.org/packages/6c/0e/73bc5ae3bc8fb006cc959155e8ed2b017b2019e50f68361e8db9e3662d9a/strawberry_graphql_django-0.65.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2e7e90e1dc9db01f54dd2cec56867d5eb1d5feb7d549c6f6f54d7515bd371a8c",
"md5": "3081ad4ef9a21cd391fa20f9b6e6cebd",
"sha256": "de312b77d83ab475b875f76f44161e8c5d9d284f349df61cebc83b4362b57a17"
},
"downloads": -1,
"filename": "strawberry_graphql_django-0.65.1.tar.gz",
"has_sig": false,
"md5_digest": "3081ad4ef9a21cd391fa20f9b6e6cebd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 86593,
"upload_time": "2025-07-26T10:54:49",
"upload_time_iso_8601": "2025-07-26T10:54:49.068082Z",
"url": "https://files.pythonhosted.org/packages/2e/7e/90e1dc9db01f54dd2cec56867d5eb1d5feb7d549c6f6f54d7515bd371a8c/strawberry_graphql_django-0.65.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-26 10:54:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "strawberry-graphql",
"github_project": "strawberry-django",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "strawberry-graphql-django"
}