Skip to main content

Strawberry GraphQL Django extension

Project description

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.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

strawberry_graphql_django-0.82.1.tar.gz (92.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

strawberry_graphql_django-0.82.1-py3-none-any.whl (117.2 kB view details)

Uploaded Python 3

File details

Details for the file strawberry_graphql_django-0.82.1.tar.gz.

File metadata

  • Download URL: strawberry_graphql_django-0.82.1.tar.gz
  • Upload date:
  • Size: 92.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for strawberry_graphql_django-0.82.1.tar.gz
Algorithm Hash digest
SHA256 a6fa235e4ada110d8e8aff82d12317535e63123f294fbcd6287af68895167a9c
MD5 23a0174568bb4f07a9bc562828156043
BLAKE2b-256 7791b3eb1b6cf6eeb38c9991d2b6a7c9ca8d57f7e9f014eda9f72f3ce3340eca

See more details on using hashes here.

File details

Details for the file strawberry_graphql_django-0.82.1-py3-none-any.whl.

File metadata

  • Download URL: strawberry_graphql_django-0.82.1-py3-none-any.whl
  • Upload date:
  • Size: 117.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for strawberry_graphql_django-0.82.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4fd54cd4cd17d3dae111c433a4a3aeaa10b98e4abeefc9614cbb6f28f9dbc51c
MD5 9a18dbc8a3dd0e8e80f19379810af1b1
BLAKE2b-256 620edf3278171e6b501df3e9f2ff236e359ee72f429d2ec035068952fc3c4488

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page