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, inspired by Apollo Server and built with GraphQL-core-next.

The library already implements enough features to enable developers to build functional GraphQL APIs. It is also being dogfooded internally on a number of projects.

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.
  • Custom scalars and enums.
  • Defining schema using SDL strings.
  • Loading schema from .graphql files.
  • WSGI middleware for implementing GraphQL in existing sites.
  • Opt-in automatic resolvers mapping between pascalCase 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.

Following features should work but are not tested and documented: unions, interfaces and subscriptions.

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:8888 address.

from ariadne import ResolverMap, gql, start_simple_server

# 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 type fields using ResolverMap
query = ResolverMap("Query")

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


person = ResolverMap("Person")

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

# Create and run dev server that provides api browser
start_simple_server(type_defs, [query, person]) # Visit http://127.0.0.1:8888 to see API browser!

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.

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.2.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

ariadne-0.2.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ariadne-0.2.0.tar.gz
  • Upload date:
  • Size: 9.9 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.2.0.tar.gz
Algorithm Hash digest
SHA256 aab57955c1446f2ca50103bd536d3dbe8aa61030b00344c6d8d771dec5d05b5d
MD5 3af476475e0648c295ae900920f51138
BLAKE2b-256 d276e8fd159a3b762e165c83f649958cd1ea66edcf8380335164c3b48c99fe9b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ariadne-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92c189b5ddb7c31182d0934700c6485ace6bb96b75a43880f4ae21374ae222fc
MD5 9a9a146c9f75b5b5806a735560370274
BLAKE2b-256 ca9b6c61c0a689e4ebbce846d0024d6af53ea16c8eb7592081f5645d8770b8f0

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