Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsJul 18, 2026·2 min de lecture

Strawberry — Type-Annotated GraphQL Library for Python

A Python GraphQL library that leverages dataclasses and type annotations to define schemas with zero boilerplate.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Strawberry GraphQL for Python
Commande d'installation directe
npx -y tokrepo@latest install 1d572c91-82e9-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

Strawberry is a modern Python GraphQL library built on type annotations and dataclasses. Instead of writing schema definitions in a separate DSL, you define your GraphQL types directly in Python using decorators and standard typing, getting full IDE autocompletion and type checking for free.

What Strawberry Does

  • Defines GraphQL schemas using Python type annotations and dataclasses
  • Generates schema SDL automatically from decorated Python classes
  • Integrates with Django, FastAPI, Flask, and ASGI frameworks
  • Supports subscriptions, federation, and file uploads
  • Provides a built-in GraphiQL IDE for development

Architecture Overview

Strawberry uses Python decorators to transform regular classes into GraphQL types at import time. A schema compiler inspects type annotations to build the GraphQL type system, resolvers, and validation rules. The execution layer delegates to graphql-core for query parsing and validation while adding async support and DataLoader integration.

Self-Hosting & Configuration

  • Install via pip: pip install strawberry-graphql[fastapi]
  • Add framework integration (Django, FastAPI, Flask, Starlette)
  • Configure via schema instantiation options (extensions, directives)
  • Enable debug mode with built-in GraphiQL at /graphql
  • Deploy as a standard ASGI/WSGI application

Key Features

  • Code-first schema definition with full IDE support
  • Native async/await support for resolvers
  • Built-in DataLoader pattern for N+1 query prevention
  • Apollo Federation support for distributed graphs
  • Pydantic integration for input validation

Comparison with Similar Tools

  • Graphene — Older Python GraphQL library; more verbose class-based API
  • Ariadne — Schema-first approach using SDL strings; Strawberry is code-first
  • tartiflette — Async-first with SDL; less community adoption
  • Apollo Server (JS) — Node.js equivalent; Strawberry brings similar DX to Python

FAQ

Q: Can I use Strawberry with Django? A: Yes. Install strawberry-graphql-django for model integration, permission handling, and pagination support.

Q: Does Strawberry support file uploads? A: Yes. It implements the GraphQL multipart request specification for file upload mutations.

Q: How does Strawberry handle authentication? A: Via context injection. Your framework middleware sets auth info on the request context, which resolvers access through the info parameter.

Q: Is Strawberry compatible with Apollo Federation? A: Yes. Decorate types with @strawberry.federation.type and configure entity resolvers to participate in a federated graph.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires