Skip to main content

Toolkit for fast and easy strawberry+sqlalchemy apis

Project description

strawberry-alchemy

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

CI PyPI version Python versions License: MIT


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

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

strawberry_alchemy-0.1.0.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

strawberry_alchemy-0.1.0-py3-none-any.whl (38.1 kB view details)

Uploaded Python 3

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

Hashes for strawberry_alchemy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2ae4494c577c8b4b1e0d60b50dfc4620f822c98ca4a2e912a551d495541fa34b
MD5 8838584f131dd2e809aa1cd13c780479
BLAKE2b-256 b7ea5b0f1a3c6dbc6835b9d12502c63b890e87486764db2e3e6929876cb6e1fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for strawberry_alchemy-0.1.0.tar.gz:

Publisher: release.yml on Alteian/strawberry-alchemy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file strawberry_alchemy-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for strawberry_alchemy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8108005d720afcb091f72f6efc9f98538cedd333b666182487d6719b78291175
MD5 e4059a43ac90058cda0af0d2fe20ba82
BLAKE2b-256 80415188af012f767737a7be47e209e235de973e6297989c1b0c2bfdc088df81

See more details on using hashes here.

Provenance

The following attestation bundles were made for strawberry_alchemy-0.1.0-py3-none-any.whl:

Publisher: release.yml on Alteian/strawberry-alchemy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page