Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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 1.21.0.dev45324

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 1.21.0.dev45324
File Size Uploaded Provenance Actions
graftql-1.21.0.dev45324.tar.gz 25.2 kB Without provenance Details for graftql-1.21.0.dev45324.tar.gz

Built distribution (wheel)

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

Total release size: 53.6 kB

Release files / graftql-1.21.0.dev45324.tar.gz

Download URL graftql-1.21.0.dev45324.tar.gz
Size 25.2 kB
Tags Source
SHA-256 checksum
How to use checksums
bf395a4935847c55dfa78edaf705e11cf0e7fb7c07a8a345d45a643fae01666a
BLAKE2b-256 checksum
How to use checksums
22f8180f3c1f215126713364761b3b18f4f16d104c91b295b38c125a70c52a30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / graftql-1.21.0.dev45324-py3-none-any.whl

Download URL graftql-1.21.0.dev45324-py3-none-any.whl
Size 28.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
80702245849f54287d499d6555ccfa527d6920ed18b62b3a4cdb7e4056498c3f
BLAKE2b-256 checksum
How to use checksums
328bf58324e43080a3c19d6112b583c5e2305847725705f41a12ad08c60dff23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for graftql 1.21.0.dev45324

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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