Skip to main content

strawberry-alchemy

Batteries-included toolkit for building Strawberry GraphQL APIs backed by SQLAlchemy

CI PyPI version Python versions License: MIT

Ask DeepWiki


Source Code: https://github.com/Alteian/strawberry-alchemy

Documentation: https://alteian.github.io/strawberry-alchemy/ · docs/


What is it?

strawberry-alchemy turns Strawberry GraphQL selection sets into a single optimized SQLAlchemy query — automatic selectinload for relationships, column deferral, and SQL EXISTS/COUNT/ancestry annotations — and ships filters, Relay pagination, CRUD repositories, row-level ACL, permissions helpers, and mapping utilities.

  • No N+1: nested selections become eager loads
  • Unrequested columns are deferred
  • Declarative computed fields via @optimize_field
  • AND/OR filters, relation joins, custom filters, Postgres JSONB lookups
  • Relay Connection pagination with totalCount
  • Async repositories with deletion reports, cascade hooks, optional soft-delete
  • Row-level AccessControlFilter (+ per-edge RelationAccessFilter) and optional Postgres RLS GUCs

Installation

pip install strawberry-alchemy
# or
uv add strawberry-alchemy

Requires Python >= 3.13, Strawberry GraphQL >= 0.339.1, sqlalchemy[asyncio] >= 2.1.6, Pydantic >= 2.14.

Quick example

# access_filters.py
from typing import Any
from models import Post
from strawberry_alchemy import AccessControlFilter


class PostAccessFilter(AccessControlFilter):
    model_class = Post

    @staticmethod
    async def apply_filter(query: Any, model: type[Any], context_user: Any) -> Any:
        return query.where(model.user_id == context_user.id)
# types.py
import strawberry
from typing import ClassVar
from strawberry_alchemy import BaseNodeType
from access_filters import PostAccessFilter


@strawberry.type
class PostType(BaseNodeType):
    access_filter: ClassVar[type[PostAccessFilter]] = PostAccessFilter

    title: str | None = strawberry.UNSET
    body: str | None = strawberry.UNSET
# queries.py
import strawberry
from strawberry.types import Info
from strawberry_alchemy import ListResult
from types import PostType


@strawberry.type
class Query:
    @strawberry.field
    async def posts(self, info: Info, limit: int | None = None) -> ListResult[PostType]:
        return await PostType.resolve_list(info=info, limit=limit)

Your request context needs get_session(), an identity / user, and a db_execution_lock — see Context contract.

Documentation

Page Topic
docs/index.md Overview and architecture
docs/getting-started.md Full walkthrough
docs/types-and-models.md Base, BaseNodeType, connections
docs/queries.md resolve_*, pagination, ordering
docs/filtering.md Filters, ACL, RelationAccessFilter
docs/query-optimizer.md Hints, analyzer, custom order
docs/mapping-and-schema.md BaseSchema, schema_from_input
docs/repository.md CRUD, soft-delete, deletion handlers
docs/permissions.md Permission helpers for mutations
docs/postgres-rls.md Session GUC helpers
docs/recipes.md Production wrapping patterns
docs/api-reference.md Public exports

Example

Runnable core patterns (ACL, OR filters, @optimize_field, ClassVar repos, deletion handler, soft-delete, prepare_mutation_resources) live in examples/blog.

make test ARGS="tests/examples"

Development

Tool versions are pinned in mise.toml (same pins CI uses). Tasks stay in Make.

git clone https://github.com/Alteian/strawberry-alchemy.git
cd strawberry-alchemy
mise install
make sync && make doctor
make ci

Docs: make docs / make docs-serve. See CONTRIBUTING.md.

License

MIT

Metadata

Release files for strawberry-alchemy 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for strawberry-alchemy 0.8.0
File Size Uploaded Provenance Actions
strawberry_alchemy-0.8.0.tar.gz 46.9 kB With provenance Details for strawberry_alchemy-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for strawberry-alchemy 0.8.0
File Interpreter ABI Platform Actions
strawberry_alchemy-0.8.0-py3-none-any.whl Python 3 none any Details for strawberry_alchemy-0.8.0-py3-none-any.whl

Total release size: 107.1 kB

Release files / strawberry_alchemy-0.8.0.tar.gz

Download URL strawberry_alchemy-0.8.0.tar.gz
Size 46.9 kB
Tags Source
SHA-256 checksum
How to use checksums
fffc007891e4f1461c271ffbde1a7931d3a6b7ee67dfc74d331e18525ec54a06
BLAKE2b-256 checksum
How to use checksums
26901b14eee5210ca3bfbe52e5be43f68ebb1c9fee5244cd773f8abbed8e32f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / strawberry_alchemy-0.8.0-py3-none-any.whl

Download URL strawberry_alchemy-0.8.0-py3-none-any.whl
Size 60.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17afeabd13d0c7432234b26bc7fbc7bf23529bbac8c8e0954e77cceeab1fa197
BLAKE2b-256 checksum
How to use checksums
d1e25145fdd0f8cc087407f97bccda85daacdcdb5ef3335b2b6ea522739e0062
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Security for strawberry-alchemy 0.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for strawberry_alchemy-0.8.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page