GraphQL Complexity
Python library to compute the complexity of a GraphQL operation. Protect your API from expensive queries and potential DoS attacks by calculating complexity before execution.
🎮 Try it live: graphql-complexity playground 📖 Full docs: graphql-complexity.readthedocs.io
Installation
pip install graphql-complexity
# With Strawberry GraphQL support
pip install graphql-complexity[strawberry-graphql]
Quick Start
from graphql_complexity import get_complexity, SimpleEstimator
from graphql import build_schema
schema = build_schema("""
type User {
id: ID!
name: String!
}
type Query {
user: User
}
""")
complexity = get_complexity(
query="query { user { id name } }",
schema=schema,
estimator=SimpleEstimator(complexity=1),
)
if complexity > 10:
raise Exception(f"Query is too complex: {complexity}")
Estimators
| Estimator | Description |
|---|---|
SimpleEstimator |
Assigns a constant cost to every field |
DirectivesEstimator |
Reads cost from @complexity(value: N) schema directives |
ArgumentsEstimator |
Multiplies cost by a numeric/list argument (e.g. limit, ids) |
| Custom | Subclass ComplexityEstimator and implement get_field_complexity |
See the estimators docs for full reference and examples.
Integrations
See the integrations docs for examples
about how this library integrates with strawberry, FastAPI, Flask and graphene-django.
Credits
Estimators idea was heavily inspired by graphql-query-complexity.
License
Metadata
Release files for graphql-complexity 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| graphql_complexity-1.1.0.tar.gz | 10.9 kB | With provenance | Details for graphql_complexity-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| graphql_complexity-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for graphql_complexity-1.1.0-py3-none-any.whl |
Total release size: 26.0 kB
Release files / graphql_complexity-1.1.0.tar.gz
| Download URL | graphql_complexity-1.1.0.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d0981e7dc9f2c0788b890cd51c6bafe4405ae6342e97f6476c76449cef745138
|
|
BLAKE2b-256 checksum How to use checksums |
16ea0b8bc148890c69d490747a5f73e5fef0e90a56f01892fca7a8eae6b3b1d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.
Transparency logRelease files / graphql_complexity-1.1.0-py3-none-any.whl
| Download URL | graphql_complexity-1.1.0-py3-none-any.whl |
|---|---|
| Size | 15.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8538c41d79131033350b13b5a5703928b2c748726fa1d3965ee4448e168b808e
|
|
BLAKE2b-256 checksum How to use checksums |
c68bf73e9b58cd1d460d74719be18cdf98fab455df75e7218919f31040aacceb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.
Transparency logSecurity for graphql-complexity 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for graphql_complexity-1.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.