Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Ariadne Code Generator

Ariadne

Build Status

Python code generator that turns a GraphQL schema and your operations into a fully typed, async (or sync) Python client built on Pydantic. You write your queries, mutations and subscriptions in GraphQL, and ariadne-codegen generates a typed Python method for each one, returning Pydantic models - so you get autocompletion and static type checking instead of hand-writing query strings and parsing raw JSON.

📖 Documentation · Step-by-step example · Configuration reference

Features

  • Fully typed models - Pydantic models for schema types, inputs, enums, fragments, and every operation's result.
  • Typed client methods - each query, mutation, and subscription becomes a method with typed arguments and a typed return value.
  • Async or sync - generate an async client (default) or a synchronous one.
  • Subscriptions - real-time updates over WebSockets (graphql-transport-ws).
  • File uploads - multipart requests via the GraphQL multipart request spec.
  • Custom scalars - map GraphQL scalars to your own Python types with serialize/parse hooks.
  • Extensible output - inject mixins into generated models, copy in your own files, or swap the base client (custom auth, or to drop the httpx/websockets deps).
  • Flexible schema sources - a local file, installed Python packages, or remote introspection.
  • Plugin system - customize generation through hooks, plus ready-made plugins (shorter results, extracted operation strings, forward refs, …).
  • More - programmatic query building, OpenTelemetry tracing, multiple clients per project, and a schema-copy mode.

Installation

Requires Python 3.10 or newer.

pip install ariadne-codegen

Add subscription (WebSocket) support with:

pip install ariadne-codegen[subscriptions]

Quickstart

Generate a typed client from three files.

1. Describe your schema in schema.graphql:

type Query {
  hello(name: String!): String!
}

2. Write the operations you need in queries.graphql:

query Greet($name: String!) {
  hello(name: $name)
}

3. Point ariadne-codegen at them in pyproject.toml:

[tool.ariadne-codegen]
schema_path = "schema.graphql"
queries_path = "queries.graphql"

Then generate the client:

ariadne-codegen

This creates a graphql_client package. Use it:

import asyncio
from graphql_client import Client


async def main():
    async with Client(url="https://example.com/graphql") as client:
        result = await client.greet(name="World")
        print(result.hello)


asyncio.run(main())

greet is a typed method generated from your Greet operation, and result is a validated Pydantic model. See the step-by-step example for a walk-through of everything that gets generated.

Contributing

Contributions are welcome! See CONTRIBUTING.md for how to report bugs, work on issues, and open pull requests.

Also make sure you follow @AriadneGraphQL on Twitter for latest updates, news and random musings!

Crafted with ❤️ by Mirumee Labs ariadne@mirumee.com

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ariadne_codegen-0.19a3.tar.gz (79.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ariadne_codegen-0.19a3-py3-none-any.whl (118.9 kB view details)

Uploaded Python 3

File details

Details for the file ariadne_codegen-0.19a3.tar.gz.

File metadata

  • Download URL: ariadne_codegen-0.19a3.tar.gz
  • Upload date:
  • Size: 79.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ariadne_codegen-0.19a3.tar.gz
Algorithm Hash digest
SHA256 4cb4b0eec12962618e37386065c6e81c662deed3da093bdab0fc5b374e29e1f3
MD5 6050d5d309067890283042c098c81eac
BLAKE2b-256 5a42adad66f5bf0423ee59a82e580fd9c7c7c81a779cb225861e0041604cc995

See more details on using hashes here.

Provenance

The following attestation bundles were made for ariadne_codegen-0.19a3.tar.gz:

Publisher: publish.yml on mirumee/ariadne-codegen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ariadne_codegen-0.19a3-py3-none-any.whl.

File metadata

File hashes

Hashes for ariadne_codegen-0.19a3-py3-none-any.whl
Algorithm Hash digest
SHA256 43459fb85feb208e04ece9189858ea60a5261d8ed6338e2cf745f40353a8172c
MD5 23e9009a32aa048d84053ae522f690a4
BLAKE2b-256 7dd2be1f55a6eac54cf0fc62b5351d344d40e2aae22bca90915b87a1ce87cd15

See more details on using hashes here.

Provenance

The following attestation bundles were made for ariadne_codegen-0.19a3-py3-none-any.whl:

Publisher: publish.yml on mirumee/ariadne-codegen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page