hypothesis-graphql
Hypothesis strategies for GraphQL queries
What it is and what it does
hypothesis-graphql is a Hypothesis strategy library that generates valid (and optionally invalid) GraphQL queries matching your schema. It integrates with Hypothesis's property-based testing framework to create parametrized test cases with arbitrary query depth and field combinations, helping you find edge cases and error-handling gaps in your GraphQL backend that manual test cases might miss.
The library works by taking a GraphQL schema as input and returning a Hypothesis strategy that produces random but schema-compliant queries. You can customize generation via field restrictions, string encoding options, and custom scalar mappings. It also supports negative testing mode to generate intentionally invalid queries for validating your server's error handling.
Use it for:
- Test a GraphQL API for crashes or unexpected behavior by generating thousands of random valid queries automatically.
- Validate error handling in your GraphQL server by generating invalid queries (wrong types, missing required args, null for non-null fields).
- Restrict query generation to specific fields to focus testing on a particular part of your schema.
- Generate custom scalar values (e.g., dates, UUIDs) that match your schema's domain constraints.
- Discover edge cases in nested query resolution that are unlikely to be covered by hand-written test cases.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Generates arbitrary GraphQL queries matching your schema to use as property-based test cases via Hypothesis, exposing edge cases in your GraphQL backend.
Yes. The package is actively maintained, has no known vulnerabilities, low install friction, and solves a real testing problem—finding edge cases in GraphQL backends through property-based testing. It integrates cleanly with Hypothesis and supports both positive and negative test generation. Recommended for any project with a GraphQL API that needs robust backend validation.
Install
hypothesis-graphql on PyPI
pip
pip install hypothesis-graphqluv
uv add hypothesis-graphqlpoetry
poetry add hypothesis-graphqlInstalling hypothesis-graphql
Before you install
Low friction: pure Python wheel with only two runtime dependencies (graphql-core and hypothesis). Actively maintained with a release 31 days ago and no known vulnerabilities.
License in practice
MIT license (permissive) — you can use this freely in commercial and open-source projects with minimal restrictions.
Quickstart
from hypothesis import given
from hypothesis_graphql import from_schema
SCHEMA = "type Query { getBooks: [String] }"
@given(from_schema(SCHEMA))
def test_graphql(query):
# query is a generated GraphQL string
response = requests.post("http://localhost/graphql", json={"query": query})
assert response.status_code == 200
Requires Python 3.10 or later.
Verify before relying
- Whether the library supports all GraphQL spec features (subscriptions, directives, interfaces, unions) or has known limitations.
- Performance characteristics when generating queries against very large schemas.
- Whether custom scalar strategies can handle complex nested types beyond the documented examples.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — graphql-core, hypothesis |
| Maintenance | actively maintained — 31 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,888,327/month — #2,840 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: hypothesis_graphql-0.13.1-py3-none-any.whl
Keywords: graphql, hypothesis, testing
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
hypothesis-jsonschemaGenerates random JSON data that conforms to a…
copyleft · top 5,000 on PyPI
schemathesisSchemathesis generates test cases from OpenAPI…
permissive · top 5,000 on PyPI
hypothesisHypothesis is a property-based testing library…
copyleft · top 1,000 on PyPI
hegel-coreHegel-core provides property-based testing data…
permissive · top 15,000 on PyPI
graphql-queryBuilds GraphQL query strings programmatically…
permissive · top 15,000 on PyPI
gqlA GraphQL client for Python that executes…
permissive · top 1,000 on PyPI
python-graphql-clientSends GraphQL queries, mutations, and…
permissive · top 15,000 on PyPI
ariadne-codegenGenerates fully typed, asynchronous Python…
permissive · top 5,000 on PyPI
strawberry-graphql-djangoGenerates GraphQL types, queries, mutations,…
permissive · top 5,000 on PyPI
enigma-api-clientPython SDK for querying Enigma's GraphQL…
permissive · top 15,000 on PyPI