Skip to main content

Strawberry GraphQL helpers for SQLAlchemy models.

Project description

strawberry-chemist

Helpers for exposing SQLAlchemy models through Strawberry GraphQL with less boilerplate.

This package wraps common patterns for:

  • generating Strawberry types from SQLAlchemy models
  • exposing model fields and relationships
  • relay-style IDs and connections
  • connection filtering, ordering, and pagination

Status

This project is currently alpha. The API is usable, but you should still expect some rough edges and breaking changes while the standalone package settles.

Installation

pip install strawberry-chemist

Supported Python versions:

  • 3.11
  • 3.12

Minimal example

from typing import Optional

import strawberry
import strawberry_chemist
from sqlalchemy import Integer, String, select
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from strawberry.types import Info

from strawberry_chemist.gql_context import SQLAlchemyContext


class Base(DeclarativeBase):
    pass


class Book(Base):
    __tablename__ = "book"
    id: Mapped[int] = mapped_column(Integer, primary_key=True)
    title: Mapped[str] = mapped_column(String)


@strawberry_chemist.type(model=Book)
class BookNode:
    title: str


@strawberry.type
class Query:
    @strawberry.field
    async def book_by_title(
        self, info: Info[SQLAlchemyContext, None], title: str
    ) -> Optional[BookNode]:
        async with info.context.get_session() as session:
            return (
                await session.execute(select(Book).where(Book.title == title))
            ).scalar_one_or_none()


schema = strawberry.Schema(query=Query)

Your GraphQL context must provide a get_session() async context manager that returns a SQLAlchemy AsyncSession.

Development

Run the default non-Postgres test suite:

uv run pytest

Run formatter and type checks:

uv run pre-commit run --all-files

Changelog

Release notes live in CHANGELOG.md.

Limitations

Current behavioral constraints and relay ID caveats are documented in LIMITATIONS.md.

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_chemist-0.1.0.tar.gz (78.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_chemist-0.1.0-py3-none-any.whl (37.2 kB view details)

Uploaded Python 3

File details

Details for the file strawberry_chemist-0.1.0.tar.gz.

File metadata

  • Download URL: strawberry_chemist-0.1.0.tar.gz
  • Upload date:
  • Size: 78.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for strawberry_chemist-0.1.0.tar.gz
Algorithm Hash digest
SHA256 89b962a0fd21b663834237921a0e2643b5191544bfba4ab23b2e6a3ba73c3e7e
MD5 bc98ff2abd3a24c9c6b91dfb69d30561
BLAKE2b-256 811524fb918a352f9ebe4fbe311928f1509eb437dba418ae195cd06a4dab8c7e

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on MeRuslan/strawberry-chemist

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_chemist-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for strawberry_chemist-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ddd2d5da4e3aa55a46b4dcb2d7bb4050a4c84668857430eadd3abb9d6cd7170
MD5 527043dc14a94b80926538b38b92f70e
BLAKE2b-256 d9cc9c3941221bc267607393398ebb0b9e1e246389e27b87b03f3d3e66d98545

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on MeRuslan/strawberry-chemist

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