Toolkit for fast and easy strawberry+sqlalchemy apis
Project description
strawberry-alchemy
Batteries-included toolkit for building Strawberry GraphQL APIs backed by SQLAlchemy
Source Code: https://github.com/Alteian/strawberry-alchemy
Features
| Module | What it does |
|---|---|
| QueryOptimizer | Analyzes Strawberry selection sets and builds a single optimized SQLAlchemy query — automatic joinedload / selectinload, column deferral, annotation injection |
| FilterBuilder | Translates Strawberry input types into SQLAlchemy WHERE clauses using a declarative operator system |
| Repository | Generic async CRUD with delete, dependent-map cascading, and lifecycle hooks |
| Types | Relay Connection / Edge / PageInfo pagination, ListResult, BaseNodeType |
| Mapping | Async helpers to convert SQLAlchemy instances → Strawberry types respecting the selected field tree |
| Permissions | Protocol-based permission primitives: IsAuthenticated, RolePermission, OwnerPermission, ObjectAccessPermission, plus resolver pattern and resource-bag |
| Models | Tiny SQLAlchemy DeclarativeBase with UUID primary key, timestamps, and automatic table naming |
| Utilities | camel_to_snake, DateTimeProcessor, Ordering enum, common exceptions |
Installation
pip install strawberry-alchemy
# or with uv
uv add strawberry-alchemy
Quick Start
import strawberry
from sqlalchemy.ext.asyncio import AsyncSession
from strawberry_alchemy import (
BaseNodeType,
BaseRepository,
FilterBuilder,
OptimizedListConnection,
QueryOptimizer,
)
# 1. Define your SQLAlchemy model (or use the provided Base)
from strawberry_alchemy.models import Base
# 2. Define your Strawberry type
@strawberry.type
class BookType(BaseNodeType):
title: str
author: str
# 3. Use QueryOptimizer in your resolver
@strawberry.type
class Query:
@strawberry.field
async def books(self, info: strawberry.Info) -> list[BookType]:
optimizer = QueryOptimizer(session=info.context.db, info=info)
result = await optimizer.optimize_query(model=Book)
return result.items
Development
git clone https://github.com/Alteian/strawberry-alchemy.git
cd strawberry-alchemy
uv sync
# Lint & test
uv run ruff check .
uv run pytest -v
# Build
uv build
Contributing
See CONTRIBUTING.md for guidelines.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file strawberry_alchemy-0.1.0.tar.gz.
File metadata
- Download URL: strawberry_alchemy-0.1.0.tar.gz
- Upload date:
- Size: 26.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ae4494c577c8b4b1e0d60b50dfc4620f822c98ca4a2e912a551d495541fa34b
|
|
| MD5 |
8838584f131dd2e809aa1cd13c780479
|
|
| BLAKE2b-256 |
b7ea5b0f1a3c6dbc6835b9d12502c63b890e87486764db2e3e6929876cb6e1fe
|
Provenance
The following attestation bundles were made for strawberry_alchemy-0.1.0.tar.gz:
Publisher:
release.yml on Alteian/strawberry-alchemy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
strawberry_alchemy-0.1.0.tar.gz -
Subject digest:
2ae4494c577c8b4b1e0d60b50dfc4620f822c98ca4a2e912a551d495541fa34b - Sigstore transparency entry: 1810782214
- Sigstore integration time:
-
Permalink:
Alteian/strawberry-alchemy@6ccd63f098d60bcd424e7b3491e29ce769a4506b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Alteian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6ccd63f098d60bcd424e7b3491e29ce769a4506b -
Trigger Event:
push
-
Statement type:
File details
Details for the file strawberry_alchemy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: strawberry_alchemy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 38.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8108005d720afcb091f72f6efc9f98538cedd333b666182487d6719b78291175
|
|
| MD5 |
e4059a43ac90058cda0af0d2fe20ba82
|
|
| BLAKE2b-256 |
80415188af012f767737a7be47e209e235de973e6297989c1b0c2bfdc088df81
|
Provenance
The following attestation bundles were made for strawberry_alchemy-0.1.0-py3-none-any.whl:
Publisher:
release.yml on Alteian/strawberry-alchemy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
strawberry_alchemy-0.1.0-py3-none-any.whl -
Subject digest:
8108005d720afcb091f72f6efc9f98538cedd333b666182487d6719b78291175 - Sigstore transparency entry: 1810782219
- Sigstore integration time:
-
Permalink:
Alteian/strawberry-alchemy@6ccd63f098d60bcd424e7b3491e29ce769a4506b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Alteian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6ccd63f098d60bcd424e7b3491e29ce769a4506b -
Trigger Event:
push
-
Statement type: