Strawberry GraphQL

0.314.3 · active · verified Thu Apr 09

Strawberry GraphQL is a modern Python library for creating GraphQL APIs that leverages type annotations and dataclasses. It follows a code-first philosophy, providing type safety, async/await support, and first-class integrations with popular web frameworks like FastAPI and Django. It aims to stay close to the GraphQL specification while offering a developer-friendly experience. Currently at version 0.314.3, it has an active development cycle with frequent releases. [1, 3, 4, 7, 12, 14, 15, 20]

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a simple GraphQL schema with a `User` type and a `Query` field that returns a hardcoded user. It then instantiates a `strawberry.Schema` and explains how to run it using Strawberry's built-in development server and CLI. [3, 4]

import strawberry

@strawberry.type
class User:
    name: str
    age: int

@strawberry.type
class Query:
    @strawberry.field
    def user(self) -> User:
        return User(name="Patrick", age=100)

schema = strawberry.Schema(query=Query)

# To run this example locally:
# 1. Install with `pip install "strawberry-graphql[cli]"`
# 2. Save the code above as `app.py`
# 3. Run `strawberry dev app` in your terminal.
# 4. Access the GraphiQL interface at http://0.0.0.0:8000/graphql in your browser.

view raw JSON →