Cloud Parts

Strawberry GraphQL

A code-first Python GraphQL library: you write dataclass-style classes with type hints, and Strawberry turns them into the schema.

What it is
API frameworks (graphql libraries)
Type
Open source
Made by
Strawberry GraphQL contributors (created by Patrick Arminio)
License
MIT
Facts checked
9 October 2026

What it is

Strawberry builds the schema from ordinary Python type hints, in the style of dataclasses. You decorate a class with @strawberry.type, and each annotated attribute becomes a field: title: str becomes title: String!, and str | None becomes a nullable String. A method marked @strawberry.field is a resolver, and its return annotation is the field’s type. strawberry.Schema(query=Query) turns those classes into a GraphQL-core schema, and printing it shows the SDL. Because the classes are the schema, the same classes serve as the data objects your resolvers return, and a mypy plugin type-checks them like any other Python code. The FastAPI documentation recommends Strawberry because it’s built on type annotations, as FastAPI is.

Strawberry ships its own integrations: a GraphQLRouter for FastAPI (an APIRouter whose context getter is a FastAPI dependency), plus views for Django, Flask, Quart, AIOHTTP, Channels and plain ASGI. Subscriptions work over WebSockets, and optionally SSE or multipart. It includes a DataLoader for batching, permission classes, Relay helpers and Apollo Federation, and has experimental @defer and @stream support, which needs GraphQL-core 3.3. It is still on 0.x version numbers (0.332.0 on October 6, 2026) and releases often; its breaking-changes page lists 20 releases with breaking changes since December 2022.

Why teams pick it

  • One source of truth: the type hints are the schema, the data classes and what mypy checks
  • First-party integrations, including a FastAPI router that supports FastAPI dependencies for the context
  • Tracks GraphQL-core closely: it requires 3.3 and offers experimental @defer and @stream
  • Built-in DataLoader, permission classes, Relay and Apollo Federation support

Watch out for

  • Still 0.x with frequent releases: 20 releases with breaking changes since December 2022, so upgrades need reading the notes
  • Sync resolvers run on the event loop, so under FastAPI one slow def resolver blocks the whole worker; the docs recommend async def everywhere
  • The DataLoader and @defer/@stream work only with async execution; execute_sync and the sync views return an error for incremental delivery
  • Code first only: the Python classes are the source of truth, so a schema designed in SDL is converted once (strawberry schema-codegen) and then maintained as Python

More of the GraphQL-core family

What all graphql libraries have in common →

How it fits with other technologies

A book query, code first: the type hints are the schema · python

# pip install strawberry-graphql   (0.332.0, Python 3.10+)
import strawberry


@strawberry.type
class Book:
    title: str          # str becomes String!, str | None would be String
    author: str


@strawberry.type
class Query:
    @strawberry.field
    def book(self) -> Book | None:
        return Book(title="Dune", author="Frank Herbert")


schema = strawberry.Schema(query=Query)

print(schema)
# type Book {
#   title: String!
#   author: String!
# }
#
# type Query {
#   book: Book
# }

result = schema.execute_sync("{ book { title author } }")
print(result.data)  # {'book': {'title': 'Dune', 'author': 'Frank Herbert'}}

# Serve it from FastAPI (pip install "strawberry-graphql[fastapi]"):
# from fastapi import FastAPI
# from strawberry.fastapi import GraphQLRouter
# app = FastAPI()
# app.include_router(GraphQLRouter(schema), prefix="/graphql")

See it in a real stack

GraphQL API in Python →
Live model
What you’re watchingClients post GraphQL queries (blue) to one endpoint. Uvicorn hands each request to FastAPI over ASGI, FastAPI routes it to Strawberry’s router, and graphql-core validates and executes it; resolvers load rows through SQLAlchemy from PostgreSQL, and the answer travels back the same way. Pink queries fail validation, so graphql-core answers them with an error list and the database never sees them. Green requests are plain REST calls that FastAPI validates with Pydantic models.
Where it came from2018–2026

Until 2018, Python had one main GraphQL library, Graphene, which defines fields with its own type classes. Patrick Arminio, a backend engineer in London, had contributed to Graphene, but decided to “make something else just to scratch my own itch”. Python 3.7 had added dataclasses, which turn annotated class attributes into fields, and Arminio used the same idea for GraphQL types: the repository started in December 2018, and version 0.1.0 reached PyPI in March 2019.

At PyCon DE 2019 Arminio presented it as “a dataclasses inspired approach to GraphQL”, eight months into the work. A mypy plugin (September 2019) made the schema type-checkable, a Django view followed the same month, then Apollo Federation (2020), a built-in DataLoader and Pydantic models (November 2020), and a FastAPI router (October 2021). The FastAPI documentation now recommends it as the GraphQL library closest to FastAPI’s own design.

Strawberry has stayed on 0.x versions and kept close to GraphQL-core: it added experimental @defer and @stream in July 2025 against GraphQL-core’s 3.3 pre-releases, and in September 2026 required GraphQL-core 3.3.0, dropping 3.2.

Why it’s built this way

Dataclass-style classes instead of field objects
Python 3.7’s dataclasses already turned annotated attributes into fields. Reusing that pattern means a GraphQL type reads like any other Python data class, and the classes double as the objects resolvers return.
Type hints as the schema
With the types in annotations rather than in library-specific field classes, standard tools can check them: a mypy plugin type-checks Strawberry types like the rest of the code.
Permission classes borrowed from Django REST framework
Arminio wanted fields that stay generic but don’t return data to the wrong people, so a field takes a list of permission classes, as views do in Django REST framework.

Timeline

  1. 2018

    Repository created in December

  2. 2019

    0.1.0 on PyPI in March; mypy plugin and Django view in September

  3. 2020

    Apollo Federation in May; built-in DataLoader and Pydantic types in November

  4. 2021

    FastAPI GraphQLRouter in October

  5. 2025

    Experimental @defer and @stream in July

  6. 2026

    Requires GraphQL-core 3.3.0 from September

Sources10 · facts checked 9 October 2026

Improve this page on GitHub