strawberry-chemist
Docs Site | Docs Source | Getting Started | Examples
Explicit GraphQL types. Smart SQLAlchemy loading.
- mapped fields
- computed fields
- scoped relationships
- queryable connections
- filters and ordering
- relay IDs
- node lookup
- selection-aware dataloading
strawberry-chemist helps expose SQLAlchemy models through Strawberry without
turning your GraphQL schema into generated magic.
The package is intentionally explicit. You still write the Strawberry types you want clients to see. That keeps the DTO layer visible, keeps the public contract adaptable, and fits production codebases that care about query shape, permissions, loading behavior, and long-term schema maintenance.
That explicitness does not mean giving up performance. Chemist-managed relationship and connection fields are selection-aware and dataloader-backed, so you can keep explicit DTOs without falling into per-parent N+1 loading.
Installation
pip install strawberry-chemist
What It Looks Like
Server-scoped relationship-backed field:
import strawberry_chemist as sc
from strawberry_chemist.gql_context import context_var
@sc.type(model=BookModel)
class Book:
@sc.relationship(
"bookmarks",
where=lambda: BookmarkModel.user_id == context_var.get().current_user_id,
select=["id"],
)
def is_bookmarked(self, bookmarks: list[BookmarkModel]) -> bool:
return bool(bookmarks)
Note: current_user_id is application data; the package does not ship auth.
Computed field from selected columns:
import strawberry_chemist as sc
@sc.type(model=BookModel)
class Book:
@sc.field(select=["title", "isbn"])
def title_with_isbn(self, title: str, isbn: str) -> str:
return f"{title} ({isbn})"
Queryable relationship-backed connection:
import strawberry_chemist as sc
@sc.type(model=AuthorModel)
class Author:
books: sc.Connection[Book] = sc.connection(
source="books",
filter=BookFilter,
order=BookOrder,
pagination=sc.CursorPagination(max_limit=20),
)
Your GraphQL context must provide a get_session() async context manager that
returns a SQLAlchemy AsyncSession.
If loader session churn matters for a heavy query, call
sc.configure(use_single_loader_session=True) before schema creation.
Chemist-managed loaders will reuse one request-local AsyncSession for their
internal work; your own resolvers still control session usage through
info.context.get_session(). During operation teardown, Chemist drains
in-flight shared-session loader work before closing that session, and any
late-arriving internal loads fall back to a fresh short-lived session.
Public docs
The public docs live in docs/. The published site is meruslan.github.io/strawberry-chemist and is built with MkDocs.
Useful entrypoints:
Serve the docs locally:
uv sync --group dev
uv run mkdocs serve
Build the docs locally:
uv run mkdocs build --strict
Runnable examples
Each numbered example under examples/ is self-contained. The root
example-* commands below just delegate into that example's own Makefile.
Each example is intentionally split into:
db.pyfor SQLAlchemy models and seeded database setupschema.pyforAppContext, GraphQL types, andbuild_schema()app.pyfor the tiny runtime CLI that prints SDL or serves the schema
Serve a seeded sample schema locally:
make example-serve EXAMPLE=03_connections_filters_and_ordering PORT=8000
The contract examples tests under examples/ can run in two modes.
Against the current checkout:
make example-test EXAMPLE=03_connections_filters_and_ordering
Against the pinned published package:
make example-test-published EXAMPLE=03_connections_filters_and_ordering
Print a sample schema:
make example-schema EXAMPLE=03_connections_filters_and_ordering
Run the same example directly from its own directory:
cd examples/03_connections_filters_and_ordering
make test
make schema
make serve PORT=8000
If you want to force published-mode testing against a locally built
distribution, point the published-mode flow at a build output directory:
uv run python -m build --outdir /tmp/strawberry-chemist-dist
STRAWBERRY_CHEMIST_FIND_LINKS=/tmp/strawberry-chemist-dist \
make example-test-published EXAMPLE=03_connections_filters_and_ordering
API overview
- Types and fields:
@sc.type,@sc.node,sc.attr,@sc.field - Relationships:
sc.relationship(...) - Collections:
sc.connection(...),sc.Connection,sc.OffsetConnection - Pagination:
sc.CursorPagination,sc.OffsetPagination,sc.PaginationPolicy - Filters:
@sc.filter,sc.FilterSet,sc.filter_field,sc.manual_filter - Ordering:
@sc.order,sc.order_field,sc.manual_order - Relay:
@sc.node,sc.node_field(),sc.node_lookup(...),sc.relay.configure(...) - Schema integration:
sc.extensions()
Each part of the surface has a dedicated public docs page and at least one example reference in docs/examples.md.
Development
Run the default non-Postgres test suite with either:
uv run pytest
make test
Run formatting and type checks:
uv run pre-commit run --all-files
uv run mypy
make mypy
make check
Release notes live in CHANGELOG.md.
Metadata
Release files for strawberry-chemist 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| strawberry_chemist-0.7.0.tar.gz | 218.1 kB | With provenance | Details for strawberry_chemist-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| strawberry_chemist-0.7.0-py3-none-any.whl | Python 3 | none | any | Details for strawberry_chemist-0.7.0-py3-none-any.whl |
Total release size: 270.7 kB
Release files / strawberry_chemist-0.7.0.tar.gz
| Download URL | strawberry_chemist-0.7.0.tar.gz |
|---|---|
| Size | 218.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
67b84f3e025e552c5fc4b21bca0dd707888e9325f2eae4216fab44f58fd3cfee
|
|
BLAKE2b-256 checksum How to use checksums |
30f98dfd1252300d33640d350b325dfafee2ba5ecffa77ae8d008e83df49f2bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 14, 2026.
Transparency logRelease files / strawberry_chemist-0.7.0-py3-none-any.whl
| Download URL | strawberry_chemist-0.7.0-py3-none-any.whl |
|---|---|
| Size | 52.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
30da30582b44098f0f614c0a9626cd2b3a85874385de6a798ef4813907a4aa84
|
|
BLAKE2b-256 checksum How to use checksums |
03fa674804614e8167aaa0a9f0ba20eb4f2c8d79a79f1a441a586b4514d4f9e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 14, 2026.
Transparency logSecurity for strawberry-chemist 0.7.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.
Attestation for strawberry_chemist-0.7.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 Oct 14, 2026.
Transparency logA 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.