Skip to main content

GraftQL

SQLModel in, typed GraphQL out.

CI PyPI Python Docs License

GraftQL turns your SQLModel definitions into a fully-typed GraphQL API — no schema duplication, no glue code.


Overview

GraftQL lets you define your data models once (as GraftModel subclasses) and get a fully-typed GraphQL API automatically — no schema duplication, no glue code. It layers on top of SQLModel for the ORM and Strawberry for the GraphQL schema. Mount GraftRouter in any FastAPI app and your models are immediately queryable and mutable over GraphQL — including paginated connections, filters, ordering, and fine-grained permission hooks.

Async (SQLAlchemy async engines) and sync engines are both supported, and multiple database engines can be registered under different names for multi-tenant or federated setups.


Features

  • Single model class — extend GraftModel instead of both SQLModel and a Strawberry type.
  • Auto GraphQL schema — queries, mutations (PUT / DELETE), and paginated connections generated automatically.
  • DataLoaders — declare relations with Dl and ManyRelation; N+1 queries solved out of the box.
  • Composable filters — date ranges, ordering, and custom filter attributes, all typed.
  • Permission hooks — override permission_getter per-model or supply a global get_permission function.
  • Async support — pass an async SQLAlchemy engine and GraftQL handles the rest.
  • Multi-engine — register multiple engines by name; each model picks its engine via __enginename__.
  • Federation-ready — Strawberry federation directives can be applied through the schema DSL.

Installation

pip install graftql

Quick Start

from datetime import date

from fastapi import FastAPI
from sqlmodel import create_engine

from graftql import Field, GraftModel, GraftRouter

# 1. Define your models — once. No separate Pydantic/Strawberry types needed.
class Student(GraftModel, table=True):
    id: int | None = Field(primary_key=True, default=None)
    name: str
    birth_date: date

# 2. Create tables and mount the router.
engine = create_engine("sqlite:///./dev.db")
GraftModel.metadata.create_all(engine)

app = FastAPI()
router = GraftRouter(
    engine=engine,
    enable_put_mutations=True,
    enable_delete_mutations=True,
)
app.include_router(router, prefix="/graphql")

# 3. Run:  uvicorn main:app --reload
#    Visit: http://localhost:8000/graphql

You can now run queries like:

mutation {
  students {
    put(input: { name: "Alice", birthDate: "2000-01-01" }) { id }
  }
}

query {
  students {
    many { edges { node { id name birthDate } } }
  }
}

Documentation

See the documentation for the full guide including relations, DataLoaders, authentication, async engines, and federation.


Contributing

  1. Fork lorrod/graftql.
  2. Create a feature branch: git checkout -b feat/my-change.
  3. Make your changes and add tests.
  4. Run the checks: uv run --group dev ruff check . && uv run --group dev pytest.
  5. Open a pull request.

All contributions are welcome — bug reports, documentation fixes, and new features alike.


License

MIT — see LICENSE.

Metadata

Release files for graftql 2.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graftql 2.0.4
File Size Uploaded Provenance Actions
graftql-2.0.4.tar.gz 25.1 kB With provenance Details for graftql-2.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for graftql 2.0.4
File Interpreter ABI Platform Actions
graftql-2.0.4-py3-none-any.whl Python 3 none any Details for graftql-2.0.4-py3-none-any.whl

Total release size: 53.5 kB

Release files / graftql-2.0.4.tar.gz

Download URL graftql-2.0.4.tar.gz
Size 25.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c4004bef9c5d5d45eaf0d26dba3a40c0b2cc5039f1e9e5e8035e3df71397241b
BLAKE2b-256 checksum
How to use checksums
237a5c83a8b6db46ed34f744ccb0572605be1427c9c148a7e166c415b57a5028
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 1, 2026.

Transparency log

Release files / graftql-2.0.4-py3-none-any.whl

Download URL graftql-2.0.4-py3-none-any.whl
Size 28.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76ac1241f52430745671bb04c7a52f35b54fb0908e1e7f77bab9ce57474c7d2a
BLAKE2b-256 checksum
How to use checksums
7bcd1202539d3305ece52a6869ea58e79f32eb3ff9a3c33f2f768d1dfbae46fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 1, 2026.

Transparency log

Security for graftql 2.0.4

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for graftql-2.0.4.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 Nov 1, 2026.

Transparency log

A 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.

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