GraphQL for Django, powered by graphene 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 graphene and
Pydantic. Define your GraphQL API straight from your
Django models — no DRF, no graphene-django, 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).
Migrating from
graphene-django-extras? See the Migration Guide.
Requirements
- Python: 3.12+ (3.13, 3.14 supported)
- Django: 4.0+ (4.2, 5.0, 5.1, 5.2, 6.0 supported)
- graphene: >=3.3,<4
- 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
import graphene
from django.contrib.auth.models import User
from django_graphex import (
DjangoListObjectType, DjangoListObjectField, DjangoObjectField, DjangoModelMutation,
)
from django_graphex.paginations import LimitOffsetGraphqlPagination
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(graphene.ObjectType):
users = DjangoListObjectField(UserListType)
class Mutation(graphene.ObjectType):
user_create = UserMutation.CreateField()
user_update = UserMutation.UpdateField()
user_delete = UserMutation.DeleteField()
schema = graphene.Schema(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,
"CACHE_ACTIVE": True,
}
To use directives, add the middleware and pass all_directives to the schema:
GRAPHENE = {"MIDDLEWARE": ["django_graphex.ExtraGraphQLDirectiveMiddleware"]}
from django_graphex import all_directives
schema = graphene.Schema(query=Query, mutation=Mutation, directives=all_directives)
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
Release history Release notifications | RSS feed
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-1.0.0.tar.gz.
File metadata
- Download URL: django_graphex-1.0.0.tar.gz
- Upload date:
- Size: 482.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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 |
059db9b319ed99d975a3649333af71e3931fa4ad25dfd05826a63a61b0763e9b
|
|
| MD5 |
66fbc4e2cbc289e19f7118f608bf4d4a
|
|
| BLAKE2b-256 |
0e64e5074619d162a5c431dfdbe4583321fcdea1bd15e556f2d9370a3c39ca01
|
File details
Details for the file django_graphex-1.0.0-py3-none-any.whl.
File metadata
- Download URL: django_graphex-1.0.0-py3-none-any.whl
- Upload date:
- Size: 131.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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 |
7a1601f2b70092ef744a0079a3c11a38a3dce0da1c38a077f78ce526ae41e582
|
|
| MD5 |
83ee14bf398326369558f70d0e986610
|
|
| BLAKE2b-256 |
e6eb6ed65a1e9a0891c21d958a10b4543e98d147606ccd47c3258c1338e02748
|