Strawchemy
Strawchemy generates GraphQL types, inputs and resolvers from SQLAlchemy models. The models already in the application are the schema definition.
Without it, filtering, ordering, pagination and nested selections all need hand-written resolvers — boilerplate that also invites N+1 queries.
Features
- Single-statement resolution
Each root field's selection set compiles to one SQL query, however deep. No dataloaders, no N+1. - Type-aware filtering
Each column gets the comparisons its type supports, from text and dates to arrays, JSON, and PostGIS geometry, combined with and, or, and not to any depth. - Full aggregation support
Aggregate a relationship or the whole result set, and filter on the result — "users with more than three posts" is a filter argument. - Nested mutation trees
Create a parent, its children and their children in one mutation. Link, unlink and insert-or-update in the same call. - Generated GraphQL types
Output types and the filtering, ordering, and mutation inputs all come from the model, and you opt into each separately. - Layered configuration
Set defaults once on the mapper, override them on a type, and override them again on a single field. - Custom fields
A field you write yourself declares what it reads, and the main query loads it. - Multi-dialect
Target PostgreSQL, MySQL, and SQLite from one mapping; Strawchemy absorbs the dialect differences. - Sync/Async compatible
The same mapped types work against a sync or an async session, chosen per schema or per field.
Documentation
Full documentation is at https://strawchemy.pages.dev — guides for mapping models, filtering, aggregations and mutations, plus a generated API reference.
Installation
Strawchemy is available on PyPi
pip install strawchemy
Strawchemy has the following optional dependencies:
geo: Enable Postgis support through geoalchemy2
To install these dependencies along with strawchemy:
pip install strawchemy[geo]
A first look
Map a model, derive filter and type classes from it, then expose a query field:
class User(Base):
__tablename__ = "user"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
posts: Mapped[list[Post]] = relationship("Post", back_populates="author")
strawchemy = Strawchemy(StrawchemyConfig("sqlite"))
@strawchemy.filter(User, include="all")
class UserFilter: ...
@strawchemy.type(User, include="all")
class UserType: ...
@strawberry.type
class Query:
users: list[UserType] = strawchemy.field(filter_input=UserFilter, pagination=True)
Querying it filters, paginates and resolves the posts relationship without any resolver code:
{
users(limit: 10, filter: { name: { contains: "Al" } }) {
id
name
posts {
title
}
}
}
See the getting started guide for the full walkthrough.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details on how to contribute to this project.
License
This project is licensed under the terms of the license included in the LICENCE file.
Metadata
Release files for strawchemy 0.24.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 | |
|---|---|---|---|
| strawchemy-0.24.0.tar.gz | 971.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| strawchemy-0.24.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.2 MB
Release files / strawchemy-0.24.0.tar.gz
| Download URL | strawchemy-0.24.0.tar.gz |
|---|---|
| Size | 971.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ceaff1ec82580482dd6e183f51bf32561d890a61e598aa67e967f6a98094d1f7
|
|
BLAKE2b-256 checksum How to use checksums |
5bc5cd5d15695d4524306bd7e8224ad6731ef8f0c3b0203a897f257820976c7c
|
| 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 6, 2026.
Transparency logRelease files / strawchemy-0.24.0-py3-none-any.whl
| Download URL | strawchemy-0.24.0-py3-none-any.whl |
|---|---|
| Size | 220.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4e3c2ec29c2a615ed4dfa96c1429a90bd28819b5072fd406d0dd9b4cd132b33b
|
|
BLAKE2b-256 checksum How to use checksums |
6aed8208ea795b11040f489bc2b539d0c8d844dbaa3ab5ebd1f72ff81c098211
|
| 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 6, 2026.
Transparency log