
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)
- Part of
- Built on GraphQL-core
- 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
@deferand@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
defresolver blocks the whole worker; the docs recommendasync defeverywhere - The DataLoader and
@defer/@streamwork only with async execution;execute_syncand 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 →
GrapheneOpen sourceBuilt on itThe oldest Python GraphQL library: code first, with its own field classes such as `graphene.String` and a `resolve_` method per field.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 →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
dataclassesalready 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
- 2018
Repository created in December
- 2019
0.1.0 on PyPI in March; mypy plugin and Django view in September
- 2020
Apollo Federation in May; built-in DataLoader and Pydantic types in November
- 2021
FastAPI
GraphQLRouterin October - 2025
Experimental
@deferand@streamin July - 2026
Requires GraphQL-core 3.3.0 from September
- PyCon DE 2019: Strawberry, a dataclasses inspired approach to GraphQL (Patrick Arminio, talk and transcript)
- GitHub: strawberry-graphql/strawberry CHANGELOG (0.14.3 mypy plugin, 0.15.1 Django, 0.26.0 federation, 0.41.0 DataLoader, 0.43.0 Pydantic, 0.84.0 FastAPI, 0.277.0 defer and stream, 0.328.0 graphql-core 3.3)
- PyPI: strawberry-graphql release history (0.1.0 in March 2019)
- GitHub: strawberry-graphql/strawberry (repository created December 2018)
- FastAPI docs: GraphQL (Strawberry recommended)
Sources10 · facts checked 9 October 2026
- GitHub: strawberry-graphql/strawberry README (based on dataclasses, mypy plugin, MIT)
- Strawberry docs: Getting started (dataclasses and type hints)
- Strawberry docs index (integrations, permissions, Relay, federation)
- Strawberry docs: Schema codegen (Python types from SDL files)
- Strawberry docs: FastAPI integration (GraphQLRouter, context_getter, sync resolvers block the worker)
- Strawberry docs: Defer and Stream (experimental, async only)
- Strawberry docs: DataLoaders (async only)
- Strawberry docs: List of breaking changes and deprecations
- PyPI: strawberry-graphql 0.332.0 (October 6, 2026; requires graphql-core 3.3)
- FastAPI docs: GraphQL (Strawberry is based on type annotations, closest to FastAPI’s design)