skillfed

graphene-django-optimizer

Optimize database access inside graphene queries.

graphene-django-optimizer v0.10.0 143.5K downloads/30d#11,176 on PyPI437
Permissive license MIT DORMANT released

What it is and what it does

graphene-django-optimizer wraps Django QuerySet queries to automatically apply select_related, prefetch_related, and only optimizations based on the GraphQL query structure. It inspects the incoming GraphQL request and modifies the underlying database query to fetch only the fields and relationships actually requested, eliminating N+1 query problems that commonly plague GraphQL-to-ORM integrations.

The package integrates directly into graphene-django resolvers via a gql_optimizer.query() wrapper and provides decorators for custom resolvers that need explicit optimization hints. It supports both simple auto-optimized fields and advanced cases where resolvers use filtering or custom logic, allowing developers to declare which relationships and fields should be prefetched or selected.

Use it for:

  • Reduce database queries when fetching nested relationships in GraphQL queries with select_related and prefetch_related.
  • Optimize single-node queries using OptimizedDjangoObjectType to automatically apply select_related and only to individual object resolvers.
  • Handle filtered prefetch scenarios where a resolver argument determines which related objects to load.
  • Prevent N+1 query problems in production GraphQL APIs backed by Django ORM without manual queryset tuning per resolver.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Automatically optimizes GraphQL queries executed by graphene-django using Django QuerySet methods like select_related, prefetch_related, and only to reduce database round-trips.

Yes, if you are actively using graphene-django with Django 2.2 or 3.1 and Python 3.6, 3.7, or 3.8. The package solves a real performance problem (N+1 queries) with minimal friction. However, be aware that maintenance is dormant—last release was 2023-08-05—so compatibility with newer Django or graphene versions is unverified. Evaluate whether your stack's versions align with the classifiers before committing.

Install

graphene-django-optimizer on PyPI

pip

pip install graphene-django-optimizer

uv

uv add graphene-django-optimizer

poetry

poetry add graphene-django-optimizer

Installing graphene-django-optimizer

Before you install

Low friction installation with no runtime dependencies. Maintenance is dormant—last release was 2023-08-05, over a year ago, though the repository remains active with 437 stars and not archived.

License in practice

MIT license permits unrestricted commercial and private use, modification, and distribution with minimal obligations beyond attribution.

Quickstart

pip install graphene-django-optimizer

import graphene_django_optimizer as gql_optimizer

class Query(graphene.ObjectType):
    all_items = graphene.List(ItemType)
    def resolve_all_items(root, info):
        return gql_optimizer.query(Item.objects.all(), info)

Requires graphene-django to be installed and a Django project with ORM models; version 0.10.0 targets Graphene V3 (use version 0.8 for Graphene V2).

Verify before relying

  • Whether the package is compatible with current versions of graphene-django and Django beyond those listed in classifiers
  • Whether dormant maintenance status indicates the package is stable or at risk of incompatibility with future Django/graphene releases
  • Whether version 0.10.0 works with Graphene V3 as intended or if compatibility issues exist

Package facts

License MIT (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance dormant — 1,105 days since the last release
Last repo commit
First released
Downloads 143,472/month — #11,176 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: graphene_django_optimizer-0.10.0-py2.py3-none-any.whl

Keywords: graphene, django, optimizer, optimize, graphql, query, prefetch, select, related

Development Status :: 4 - BetaEnvironment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 2.2Framework :: Django :: 3.1Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8

Tags

graphql query optimization djangographene-django performancereduce n+1 queries graphqldjango select_related prefetch_relatedgraphene query optimizerdjango graphql database optimization
graphqlorm-optimizationdjango

More Front-Ends packages

SQLAlchemy

SQLAlchemy is a Python SQL toolkit and Object…

permissive · top 100 on PyPI

psycopg2-binary

psycopg2-binary is a PostgreSQL database…

copyleft · top 1,000 on PyPI

alembic

Alembic generates and manages database schema…

permissive · top 1,000 on PyPI

weaviate-client

A Python client library for connecting to and…

permissive · top 1,000 on PyPI

databricks-sql-connector

A Python client library that connects to…

permissive · top 1,000 on PyPI

psycopg

Psycopg 3 is a PostgreSQL database adapter for…

copyleft · top 1,000 on PyPI

graphene-django

Graphene-Django bridges Django models and…

permissive · top 5,000 on PyPI

graphene

Graphene is a Python library for building…

permissive · top 1,000 on PyPI

graphene-sqlalchemy

Graphene-SQLAlchemy exposes SQLAlchemy database…

permissive · top 15,000 on PyPI

django-chunkator

Iterates over large Django QuerySets in…

permissive · top 15,000 on PyPI

strawberry-graphql-django

Generates GraphQL types, queries, mutations,…

permissive · top 5,000 on PyPI

graphene-file-upload

Adds file upload support to GraphQL mutations…

permissive · top 15,000 on PyPI

django-query-builder

Builds and executes complex SQL queries…

permissive · top 15,000 on PyPI

graphql-core-promise

Adds promise-based resolver and dataloader…

permissive · top 15,000 on PyPI

gql

A GraphQL client for Python that executes…

permissive · top 1,000 on PyPI

django-cursor-pagination

Implements cursor-based pagination for Django…

permissive · top 15,000 on PyPI