graphql-typed-python
Build GraphQL operations with Python dictionary literals and get static types for both the request and the selected response fields. Generation has two passes. The schema supplies completions while you write your operations. Each named operation then supplies the variables and return type for the generated client.
Quick start
Use Python 3.12 or newer. Install the generator in your development environment. Applications using the default HTTP transport also need httpx.
uv add --dev graphql-typed-python
uv add httpx
Given a schema.graphql file:
type Query { device(serial: String!): Device }
type Device { id: ID!, name: String!, firmware: String }
Generate the authoring types:
uv run graphql-typed generate schema.graphql --out generated
Write operations.py alongside the generated package:
from generated import schema
from graphql_typed import Operation, var
identity: schema.DeviceFields = {"id": True, "name": True}
def operations() -> list[Operation]:
return [
schema.query(
"DeviceBySerial",
select={
"device": {
"args": {"serial": var("serial")},
"select": identity,
},
},
)
]
Generate the client. This command also works on a fresh checkout. The generator evaluates the factory against the newly generated schema types before writing its outputs.
uv run graphql-typed generate schema.graphql --out generated --operations operations:operations
Use the same name to execute the operation:
from generated.client import AsyncClient
async def device_name(client: AsyncClient, serial: str) -> str | None:
data = await client.query("DeviceBySerial")(variables={"serial": serial})
if (device := data["device"]) is not None:
return device["name"]
return None
Construct a client with AsyncClient("https://example.test/graphql"). The sync equivalent is Client(endpoint).query("DeviceBySerial")(variables={"serial": "R42"}). Completion follows the selected fields. Accessing device["firmware"] in this example is a type error.
Selections and variables
- Use
Truefor a leaf field,argsfor field arguments, andselectfor nested fields. Object selections must contain at least one field. - Use either a single selection or a list for each field. An alias becomes the key in the result. For example,
"name": [{"alias": "label"}]yieldsdevice["label"]. Give distinct aliases to fields with different arguments. - Use
var("name")at an argument, input object field, or list item. The first use determines its GraphQL type. Further uses must have exactly the same type, including nullability and list markers. Custom scalars retain their GraphQL names and use PythonAny. - Input objects are dictionaries and enum values are string literals. Nullable variables can be omitted or set to
None. A selected nullable response field has a required key whose value can beNone. - Use
schema.mutation(...)andclient.mutation("Name")(...)for mutations. Operations without variables are called asclient.query("Name")(). - V1 supports queries and mutations over concrete objects. Subscriptions, directives on selections, and type-specific selections on unions and interfaces are outside its scope.
Schema sources and output
The source can be an SDL file, a local introspection JSON document (raw or wrapped in data), or an HTTP(S) GraphQL endpoint. Endpoint generation issues an unauthenticated introspection request. Add --no-ssl to disable certificate verification for that request.
uv run graphql-typed generate https://example.test/graphql --out generated --operations operations:operations
For programmatic use, import generate from graphql_typed.generator. It accepts source, out, and the optional keyword arguments operations and verify_ssl. The factory reference uses module:function and the module must be importable.
| Generated module | Contents |
|---|---|
generated.schema |
Authoring types and operation builders. Used during development and generation. |
generated.client |
Sync and async clients with operation-name overloads. |
generated.types |
Input objects, per-operation variables, and response dictionaries. |
generated.transport |
Structural transport protocols and GraphQLResponseError. |
Transports and errors
The default transport posts GraphQL JSON using httpx. To supply a transport, implement the following method and pass the object to the client. An async transport provides an async def execute method with the same parameters.
from collections.abc import Mapping
from generated.client import Client
class FakeTransport:
def execute(
self, *, document: str, operation_name: str, variables: Mapping[str, object]
) -> object:
return {"data": {"device": {"id": "42", "name": "router"}}}
client = Client(transport=FakeTransport())
A transport returns the decoded GraphQL response envelope. The client returns its data on success. When the envelope contains errors, it raises generated.transport.GraphQLResponseError with .errors and .data, including any partial result. Consumers using a custom transport can run the generated client with the Python standard library alone.
Development
uv sync --locked
prek install
prek run --all-files
uv build
Small schemas, operation factories, and typing.assert_type examples live in tests/contract/. The tests generate clients in temporary packages, check them with ty, exercise editor completions via its language server, and execute queries through custom transports and a local GraphQL HTTP server. The TLS test uses the openssl command. just check runs the same formatting, typing, and test checks used in CI.
The release workflow builds and checks distributions on pushes to the releases branch and publishes using PyPI trusted publishing. just release runs local release checks and pushes the version bump.
Metadata
Release files for graphql-typed-python 0.1.2
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_typed_python-0.1.2.tar.gz | 63.5 kB | With provenance | Details for graphql_typed_python-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| graphql_typed_python-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for graphql_typed_python-0.1.2-py3-none-any.whl |
Total release size: 80.2 kB
Release files / graphql_typed_python-0.1.2.tar.gz
| Download URL | graphql_typed_python-0.1.2.tar.gz |
|---|---|
| Size | 63.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4ae355763325d6322a139a851963a1fd85029d32917a60dc6c85738ff7962169
|
|
BLAKE2b-256 checksum How to use checksums |
c969e52e91c51097e510d0046f566bb788e21c2ce65652ebb23b65f646b4cf77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 24, 2026.
Transparency logRelease files / graphql_typed_python-0.1.2-py3-none-any.whl
| Download URL | graphql_typed_python-0.1.2-py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
42419036893e76b665715e98175e563007de33cc2534b8d871c6b815d7ee973a
|
|
BLAKE2b-256 checksum How to use checksums |
b2d9c8857ce67ca84f0c7fcc65bb5d1e7f6a5e6866a686dd02c2ee5d8d5cdbea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 24, 2026.
Transparency logSecurity for graphql-typed-python 0.1.2
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_typed_python-0.1.2.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 24, 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.