Ariadne

1.0.1 · active · verified Fri Apr 10

Ariadne is a Python library for implementing GraphQL servers using a schema-first approach. It emphasizes a simple, extensible API for defining GraphQL schemas using Schema Definition Language (SDL) and connecting business logic with minimal boilerplate. It supports queries, mutations, subscriptions, custom scalars, and integrates with ASGI/WSGI frameworks like Django, FastAPI, Flask, and Starlette. The project maintains an active and frequent release cadence, with regular patch, minor, and occasional alpha releases, as seen with versions like 1.0.1 and subsequent 1.1.0a2.

Warnings

Install

Imports

Quickstart

This quickstart sets up a basic Ariadne GraphQL server with a 'Person' type and a 'people' query. It defines the schema in SDL, creates a resolver for the 'people' field, and runs a development server with GraphiQL for interactive API exploration.

from ariadne import gql, QueryType, make_executable_schema, start_dev_server

# Define GraphQL schema using Schema Definition Language (SDL)
type_defs = gql("""
    type Query {
        people: [Person!]!
    }

    type Person {
        firstName: String!
        lastName: String!
    }
""")

# Create a QueryType instance to define query resolvers
query = QueryType()

# Define the resolver for the 'people' field
@query.field("people")
def resolve_people(*_):
    return [
        {"firstName": "John", "lastName": "Doe"},
        {"firstName": "Jane", "lastName": "Smith"},
    ]

# Combine type definitions and resolvers into an executable schema
schema = make_executable_schema(type_defs, query)

# Run the development server
if __name__ == "__main__":
    # Access the GraphQL endpoint and GraphiQL at http://127.0.0.1:8000
    start_dev_server(schema, port=8000)

view raw JSON →