Skip to main content

Strawchemy

🔂 Tests and linting codecov PyPI Downloads

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:

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)

Source distribution for strawchemy 0.24.0
File Size Uploaded
strawchemy-0.24.0.tar.gz 971.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for strawchemy 0.24.0
File Interpreter ABI Platform
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 log

Release 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

Release history Release notifications | RSS feed

This release

0.24.0 This release

2 release files

0.23.1

2 release files

0.23.0

2 release files

0.22.0

2 release files

0.21.0

2 release files

0.20.0

2 release files

0.16.0

2 release files

0.15.6

2 release files

0.15.5

2 release files

0.15.4

2 release files

0.15.3

2 release files

0.15.2

2 release files

0.15.1

2 release files

0.15.0

2 release files

0.14.2

2 release files

0.14.1

2 release files

0.14.0

2 release files

0.13.7

2 release files

0.13.6

2 release files

0.13.5

2 release files

0.13.4

2 release files

0.13.3

2 release files

0.13.2

2 release files

0.13.1

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page