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.7.3

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.7.3
File Size Uploaded Provenance Actions
strawberry_alchemy-0.7.3.tar.gz 43.5 kB With provenance Details for strawberry_alchemy-0.7.3.tar.gz

Built distribution (wheel)

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

Total release size: 99.3 kB

Release files / strawberry_alchemy-0.7.3.tar.gz

Download URL strawberry_alchemy-0.7.3.tar.gz
Size 43.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b07dd7d38ff6f51086420b17c5908e8aeb9458121c68f995926d1d4ee25fbbf1
BLAKE2b-256 checksum
How to use checksums
989b9b1b2afaf3e3bd249982beab928793ded6264ec37464b61366de71a94ce5
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 22, 2026.

Transparency log

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

Download URL strawberry_alchemy-0.7.3-py3-none-any.whl
Size 55.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
971d7b0e5895b5a14617f20a659e78d1af9ef599eca89ec0fe3cd4d6f0491f02
BLAKE2b-256 checksum
How to use checksums
9c556ff11597671bc61ee54954821400ae4761bce9cc951bd067e8136802bce1
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 22, 2026.

Transparency log

Security for strawberry-alchemy 0.7.3

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.7.3.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 22, 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