Skip to main content

Strawberry GraphQL Django Integration

CI Coverage PyPI Downloads PyPI - Python Version

Documentation | Discord

Strawberry GraphQL Django integration provides powerful tools to build GraphQL APIs with Django. Automatically generate GraphQL types, queries, mutations, and resolvers from your Django models with full type safety.

Installation

pip install strawberry-graphql-django

Features

  • 🍓 Automatic Type Generation - Generate GraphQL types from Django models with full type safety
  • 🔍 Advanced Filtering - Powerful filtering system with lookups (contains, exact, in, etc.)
  • 📄 Pagination - Built-in offset and cursor-based (Relay) pagination
  • 📊 Ordering - Sort results by any field with automatic ordering support
  • 🔐 Authentication & Permissions - Django auth integration with flexible permission system
  • ✨ CRUD Mutations - Auto-generated create, update, and delete mutations with validation
  • ⚡ Query Optimizer - Automatic select_related and prefetch_related to prevent N+1 queries
  • 🐍 Django Integration - Works with Django views (sync and async), forms, and validation
  • 🐛 Debug Toolbar - GraphiQL integration with Django Debug Toolbar for query inspection

Quick Start

# models.py
from django.db import models


class Fruit(models.Model):
    name = models.CharField(max_length=20)
    color = models.ForeignKey("Color", on_delete=models.CASCADE, related_name="fruits")


class Color(models.Model):
    name = models.CharField(max_length=20)
# 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]
# 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],
)
# urls.py
from django.urls import path
from strawberry.django.views import AsyncGraphQLView
from .schema import schema

urlpatterns = [
    path("graphql/", AsyncGraphQLView.as_view(schema=schema)),
]

That's it! You now have a fully functional GraphQL API with:

  • Automatic type inference from Django models
  • Optimized database queries (no N+1 problems)
  • Interactive GraphiQL interface at /graphql/

Visit http://localhost:8000/graphql/ and try this query:

query {
  fruits {
    id
    name
    color {
      name
    }
  }
}

Next Steps

Check out our comprehensive documentation:

Contributing

We welcome contributions! Whether you're fixing bugs, adding features, or improving documentation, your help is appreciated 😊

Quick Start:

git clone https://github.com/strawberry-graphql/strawberry-django
cd strawberry-django
pre-commit install

Then run tests with make test or make test-dist for parallel execution.

Community

License

This project is licensed under the MIT License.

Metadata

Release files for strawberry-graphql-django 0.93.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for strawberry-graphql-django 0.93.1
File Size Uploaded Provenance Actions
strawberry_graphql_django-0.93.1.tar.gz 97.6 kB Without provenance Details for strawberry_graphql_django-0.93.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for strawberry-graphql-django 0.93.1
File Interpreter ABI Platform Actions
strawberry_graphql_django-0.93.1-py3-none-any.whl Python 3 none any Details for strawberry_graphql_django-0.93.1-py3-none-any.whl

Total release size: 219.0 kB

Release files / strawberry_graphql_django-0.93.1.tar.gz

Download URL strawberry_graphql_django-0.93.1.tar.gz
Size 97.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1373d192070e98e36135347df0eae4ecfa636e664599d67e39efe8aa5453b773
BLAKE2b-256 checksum
How to use checksums
11a9a3f9de3b0535d9773e606bba5236da3e07582209fab55b8ff4b7c42c28bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / strawberry_graphql_django-0.93.1-py3-none-any.whl

Download URL strawberry_graphql_django-0.93.1-py3-none-any.whl
Size 121.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1bf9b3ab55395bfbab2cb382c60a76bfde8bd63219d0fec4238e6c2c75466c89
BLAKE2b-256 checksum
How to use checksums
32c9a73d1b7dba4e56c300e997546c0e203a35fad987e450371dfb54cb0d49c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for strawberry-graphql-django 0.93.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.93.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page