skillfed

graphql-query

Complete Domain Specific Language (DSL) for GraphQL query in Python.

graphql-query v1.4.0 277.6K downloads/30d#8,144 on PyPI70
Permissive license DORMANT released

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-query

uv

uv add graphql-query

poetry

poetry add graphql-query

Installing 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

Development Status :: 5 - Production/StableEnvironment :: MacOS XFramework :: PydanticFramework :: Pydantic :: 2License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python Modules

Tags

graphql query builder pythongenerate graphql queries programmaticallygraphql dsl pythonpython graphql query generatorgraphql query construction librarygraphql arguments variables pythonpydantic graphql codegen
graphqlcode-generationquery-builder

More Libraries packages