Skip to main content

Ariadne is a Python library for implementing GraphQL servers.

Project description

Ariadne

Documentation Build Status Codecov


Ariadne

Ariadne is a Python library for implementing GraphQL servers.

  • Schema-first: Ariadne enables Python developers to use schema-first approach to the API implementation. This is the leading approach used by the GraphQL community and supported by dozens of frontend and backend developer tools, examples, and learning resources. Ariadne makes all of this immediately available to your and other members of your team.
  • Simple: Ariadne offers small, consistent and easy to memorize API that lets developers focus on business problems, not the boilerplate.
  • Open: Ariadne was designed to be modular and open for customization. If you are missing or unhappy with something, extend or easily swap with your own.

Documentation is available here.

Features

  • Simple, quick to learn and easy to memorize API.
  • Compatibility with GraphQL.js version 14.0.2.
  • Queries, mutations and input types.
  • Asynchronous resolvers and query execution.
  • Subscriptions.
  • Custom scalars and enums.
  • Unions and interfaces.
  • Defining schema using SDL strings.
  • Loading schema from .graphql files.
  • WSGI middleware for implementing GraphQL in existing sites.
  • Opt-in automatic resolvers mapping between camelCase and snake_case.
  • Build-in simple synchronous dev server for quick GraphQL experimentation and GraphQL Playground.
  • Support for Apollo GraphQL extension for Visual Studio Code.
  • GraphQL syntax validation via gql() helper function. Also provides colorization if Apollo GraphQL extension is installed.

Installation

Ariadne can be installed with pip:

pip install ariadne

Quickstart

The following example creates an API defining Person type and single query field people returning a list of two persons. It also starts a local dev server with GraphQL Playground available on the http://127.0.0.1:8000 address.

Start by installing uvicorn, an ASGI server we will use to serve the API:

pip install uvicorn

Then create an example.py file for your example application:

from ariadne import ObjectType, QueryType, gql, make_executable_schema
from ariadne.asgi import GraphQL

# Define types using Schema Definition Language (https://graphql.org/learn/schema/)
# Wrapping string in gql function provides validation and better error traceback
type_defs = gql("""
    type Query {
        people: [Person!]!
    }

    type Person {
        firstName: String
        lastName: String
        age: Int
        fullName: String
    }
""")

# Map resolver functions to Query fields using QueryType
query = QueryType()

# Resolvers are simple python functions
@query.field("people")
def resolve_people(*_):
    return [
        {"firstName": "John", "lastName": "Doe", "age": 21},
        {"firstName": "Bob", "lastName": "Boberson", "age": 24},
    ]


# Map resolver functions to custom type fields using ObjectType
person = ObjectType("Person")

@person.field("fullName")
def resolve_person_fullname(person, *_):
    return "%s %s" % (person["firstName"], person["lastName"])

# Create executable GraphQL schema
schema = make_executable_schema(type_defs, [query, person])

# Create an ASGI app using the schema, running in debug mode
app = GraphQL(schema, debug=True)

Finally run the server:

uvicorn example:app

For more guides and examples, please see the documentation.

Contributing

We are welcoming contributions to Ariadne! If you've found a bug or issue, or if you have any questions or feedback, feel free to use GitHub issues.

For guidance and instructions, please see CONTRIBUTING.md.

Crafted with ❤️ by Mirumee Software hello@mirumee.com

Project details


Download files

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

Source Distribution

ariadne-0.3.0.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

ariadne-0.3.0-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file ariadne-0.3.0.tar.gz.

File metadata

  • Download URL: ariadne-0.3.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

File hashes

Hashes for ariadne-0.3.0.tar.gz
Algorithm Hash digest
SHA256 01ed4572ff9ee24c1b06f932e5516bcc2e2ba23d129fb5a0e9fe4a732eae74ad
MD5 9d4839d70048a40e55f4830207c07b8c
BLAKE2b-256 0ec645a3375913bf8289fddf14399ca189047f746b9a84aadd17ba3debdde54d

See more details on using hashes here.

File details

Details for the file ariadne-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: ariadne-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

File hashes

Hashes for ariadne-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c4b30b6138c7a9b8f890e80aed1303ae82deef70c3b7c5f218f7b2d620e046e8
MD5 ab484aa6e2bd5df10e0c1b27bcea11e8
BLAKE2b-256 58cf7bf7c1a3e2f37b111002d072924d1f31d1244e30578f6d8e5254af8e0099

See more details on using hashes here.

Supported by

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