graphql-query
Complete Domain Specific Language (DSL) for GraphQL query in Python.
What it is and what it does
graphql-query is a Python DSL for constructing GraphQL query strings from Python code. Instead of writing raw GraphQL strings, you build queries using Python classes like Query, Field, Argument, Variable, Fragment, and Directive, then call render() to produce the final GraphQL string. It depends on jinja2 for templating and pydantic for data validation, and supports modern Python versions from 3.8 onward.
The package is designed for scenarios where you want to programmatically assemble queries, reuse common arguments and variables across multiple queries, or generate query classes from pydantic models. It handles simple field selection, complex arguments with variables, inline fragments, and directives like @include and @skip.
Use it for:
- Build GraphQL queries dynamically in client applications without concatenating strings or managing raw query text.
- Share and reuse common Arguments, Variables, and Fragments across multiple queries in a codebase.
- Generate GraphQL query classes from existing pydantic data models to keep query structure in sync with your Python types.
- Construct queries with conditional fields and directives (e.g., @include, @skip) based on runtime logic.
- Test GraphQL APIs by programmatically generating test queries with varying arguments and field selections.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Builds GraphQL query strings programmatically in Python using a domain-specific language, letting you construct queries from Python classes instead of writing raw GraphQL strings.
Yes, if you need to generate GraphQL queries programmatically and want type-safe, reusable query construction. The low install friction, permissive MIT license, and support for modern Python versions make it straightforward to adopt. The dormant maintenance status is a minor concern—no active vulnerabilities and the last commit is recent—but verify compatibility with your pydantic and jinja2 versions before relying on it for production systems.
Install
graphql-query on PyPI
pip
pip install graphql-queryuv
uv add graphql-querypoetry
poetry add graphql-queryInstalling graphql-query
Before you install
Low friction install with only jinja2 and pydantic as runtime dependencies. Maintenance is dormant—last commit was 2024-11-26 and no releases in the past 744 days—but the repository remains active and unarchived.
License in practice
MIT license (permissive) means you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install graphql-query
from graphql_query import Operation, Query
hero = Query(name="hero", fields=["name"])
operation = Operation(type="query", queries=[hero])
print(operation.render())
Verify before relying
- Whether the dormant maintenance status (no releases in 744 days) affects compatibility with recent GraphQL schema changes or breaking updates in jinja2/pydantic.
- Real-world performance or scalability limits when generating very large or deeply nested GraphQL queries.
- Whether generated queries are validated against a GraphQL schema or only syntactically correct.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — jinja2, pydantic |
| Maintenance | dormant — 744 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 277,642/month — #8,144 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: graphql_query-1.4.0-py3-none-any.whl
Keywords: code-generation, codegen, dsl, graphql, graphql-query, graphql-query-builder, pydantic, python, query-builder, query-generation, query-generator
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
ariadne-codegenGenerates fully typed, asynchronous Python…
permissive · top 5,000 on PyPI
sgqlcsgqlc is a Python client library for querying…
permissive · top 5,000 on PyPI
hypothesis-graphqlGenerates arbitrary GraphQL queries matching…
permissive · top 5,000 on PyPI
gqlA GraphQL client for Python that executes…
permissive · top 1,000 on PyPI
datamodel-code-generatorGenerates Python data models (Pydantic,…
permissive · top 5,000 on PyPI
gw-dsl-parserConverts graphic-walker workflow definitions…
permissive · top 15,000 on PyPI
graphene-pydanticConverts Pydantic models into GraphQL object…
permissive · top 15,000 on PyPI
python-graphql-clientSends GraphQL queries, mutations, and…
permissive · top 15,000 on PyPI
enigma-api-clientPython SDK for querying Enigma's GraphQL…
permissive · top 15,000 on PyPI
yaqlYAQL is an embeddable query language for Python…
permissive · top 15,000 on PyPI