This release is a pre-release and may not be stable for production use.
SQLModel in, typed GraphQL out.
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
GraftModelinstead of bothSQLModeland a Strawberry type. - Auto GraphQL schema — queries, mutations (PUT / DELETE), and paginated connections generated automatically.
- DataLoaders — declare relations with
DlandManyRelation; N+1 queries solved out of the box. - Composable filters — date ranges, ordering, and custom filter attributes, all typed.
- Permission hooks — override
permission_getterper-model or supply a globalget_permissionfunction. - 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
- Fork lorrod/graftql.
- Create a feature branch:
git checkout -b feat/my-change. - Make your changes and add tests.
- Run the checks:
uv run --group dev ruff check . && uv run --group dev pytest. - 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.dev44411
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 |
|---|---|---|---|---|
| graftql-1.21.0.dev44411.tar.gz | 25.2 kB | Without provenance | Details for graftql-1.21.0.dev44411.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| graftql-1.21.0.dev44411-py3-none-any.whl | Python 3 | none | any | Details for graftql-1.21.0.dev44411-py3-none-any.whl |
Total release size: 53.6 kB
Release files / graftql-1.21.0.dev44411.tar.gz
| Download URL | graftql-1.21.0.dev44411.tar.gz |
|---|---|
| Size | 25.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
97653e4945b982d1b96e1cc31e9007f99ca210e9a088e09bcb41eacca7968d4a
|
|
BLAKE2b-256 checksum How to use checksums |
c5b72643162ef1397ee03f778be58e75df572cf79fb4f0eb9a4bc054788f90ea
|
| 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.dev44411-py3-none-any.whl
| Download URL | graftql-1.21.0.dev44411-py3-none-any.whl |
|---|---|
| Size | 28.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b114d790e70a0a1cf9e265d83de26c055c27ed5937f0e8cd9c655dd10c5466fc
|
|
BLAKE2b-256 checksum How to use checksums |
454e27a143956aa7d171dccbfd34da4316da479cae26f5f2c120ef1b77b4495f
|
| 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.dev44411
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.