GraphQL for Django, powered by graphql-core and Pydantic: define types/mutations/subscriptions from your models, with nested filtering (and/or/not), pagination, permissions and directives.
Project description
django-graphex
GraphQL for Django, powered by graphql-core
and Pydantic. Define your GraphQL API straight from
your Django models — no DRF, no graphene, no django-filter.
- Model-first types & mutations —
DjangoModelType/DjangoModelMutationgive you query, list and create/update/delete from a singleMeta.model, validated and persisted with Pydantic v2 + the Django ORM (FK existence, uniqueness,unique_together, partial updates,choices→ Enum). - Logical filtering — one nested
filter:argument withand/or/not, per-field lookups, relation descent and plain-pk/UUID filtering (nodjango-filter). - Pagination — limit/offset, page and keyset cursor paginators with a
uniform
results/totalCountshape (and an automatic N+1 query optimizer). - Custom validation — DRF-style inline
validate_<field>()/validate()or aMeta.pydantic_model. - Permissions, security & directives — permission classes, depth & cost limits, introspection control, and string/number/date/list directives.
- Subscriptions — real-time GraphQL over Django Channels 4 (optional extra).
Coming from
graphene-djangoorgraphene-django-extras? See the Migration Guide for a step-by-step upgrade with before/after examples.Upgrading from
django-graphex1.x? 2.0 removed the graphene backend entirely — see the Upgrade Guide and thescripts/migrate_2_0.pycodemod.
Requirements
- Python: 3.12+ (3.13, 3.14 supported)
- Django: 5.2+ (5.2 LTS, 6.0 supported) — each Django version tested on the Python versions it officially supports
- graphql-core: >=3.2.11,<3.3
- pydantic: >=2,<3
Installation
# uv (recommended)
uv add django-graphex
# real-time subscriptions (adds Django Channels 4):
uv add "django-graphex[subscriptions]"
# pip
pip install django-graphex
pip install "django-graphex[subscriptions]"
The base install never imports channels; only the subscriptions extra does.
Quick start
from django.contrib.auth.models import User
from django_graphex.fields import DjangoListObjectField
from django_graphex.mutation import DjangoModelMutation
from django_graphex.core import ObjectType
from django_graphex.paginations import LimitOffsetGraphqlPagination
from django_graphex.schema import DjangoGraphQLSchema
from django_graphex.types import DjangoListObjectType
class UserListType(DjangoListObjectType):
class Meta:
model = User
pagination = LimitOffsetGraphqlPagination()
filter_fields = {"username": ("icontains", "exact"), "is_active": ("exact",)}
class UserMutation(DjangoModelMutation): # define once -> create/update/delete
class Meta:
model = User
class Query(ObjectType):
users = DjangoListObjectField(UserListType)
class Mutation(ObjectType):
user_create = UserMutation.CreateField()
user_update = UserMutation.UpdateField()
user_delete = UserMutation.DeleteField()
schema = DjangoGraphQLSchema(query=Query, mutation=Mutation)
Query it with the nested filter: argument (and / or / not):
{
users(filter: { is_active: { exact: true }, username: { icontains: "jo" } }) {
results(limit: 10, ordering: "-date_joined") { id username }
totalCount
}
}
Configuration
All settings live under a single DJANGO_GRAPHEX dict (every key is optional):
# settings.py
DJANGO_GRAPHEX = {
"DEFAULT_PAGINATION_CLASS": "django_graphex.paginations.LimitOffsetGraphqlPagination",
"DEFAULT_PAGE_SIZE": 20,
"MAX_PAGE_SIZE": 50,
# Response caching. Default is False (disabled).
# WARNING: cache keys are identity-salted per user (v1.2.1+), but shared
# caches can still leak data if misconfigured. Review the caching guide
# before enabling in production: docs/usage/caching.md
"CACHE_ACTIVE": True,
}
To use directives, add the middleware and pass all_directives to the schema:
DJANGO_GRAPHEX = {"MIDDLEWARE": ["django_graphex.middleware.GraphQLDirectiveMiddleware"]}
from django_graphex.directives import all_directives
from django_graphex.schema import DjangoGraphQLSchema
schema = DjangoGraphQLSchema(query=Query, mutation=Mutation, directives=all_directives)
Playground
A fully wired example project lives in examples/playground/. It exercises every major feature end-to-end — types, paginators, filtering, mutations, permissions, subscriptions, and the query optimizer — and installs the library from this repo checkout (editable, no PyPI release needed).
Documentation
📚 Full documentation — including the Quick Start, Model backend, Filtering, Pagination, Subscriptions, Settings and the Migration Guide.
License
MIT License — see the LICENSE file.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_graphex-2.0.0.tar.gz.
File metadata
- Download URL: django_graphex-2.0.0.tar.gz
- Upload date:
- Size: 1.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e369dd88f6a45713ca390985ea902061bb435e1483745883d695bebb57f9f0f6
|
|
| MD5 |
ee67c087a6dbb04779395ea0b63ac0f6
|
|
| BLAKE2b-256 |
993ee57b05692fe682b6aff5137f5149316f6b93b018f2af7a0b8ac25ed147dd
|
File details
Details for the file django_graphex-2.0.0-py3-none-any.whl.
File metadata
- Download URL: django_graphex-2.0.0-py3-none-any.whl
- Upload date:
- Size: 448.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0031e3a2d921c9520cce3f7f5979a436ff5c874f77c00691c74d8f56ddc808f
|
|
| MD5 |
34e21b54c20bdd9941e9e79560c79ccb
|
|
| BLAKE2b-256 |
70525976663bfdeccb69297f191f14e5123e8e7fecedfdbbd191472d47c16500
|