Skip to main content

Comprehensive GraphQL implementation for Python.

Project description

py-gql

CircleCI Codecov PyPI PyPI - Python Version PyPI - Wheel Read the Docs (version)

py-gql_is a pure python GraphQL implementation aimed at creating GraphQL servers.

It supports:

  • Parsing the GraphQL query language and schema definition language.
  • Building a GraphQL type schema programatically and from Schema Definition files (including support for schema directives).
  • Validating and Executing a GraphQL request against a type schema.

Quick links

Installation

pip install py-gql

For more details see install.rst.

Usage & Examples

Hello World

from py_gql import build_schema, graphql_blocking

schema = build_schema(
    """
    type Query {
        hello(value: String = "world"): String!
    }
    """
)


@schema.resolver("Query.hello")
def resolve_hello(*_, value):
    return f"Hello {value}!"


result = graphql_blocking(schema, '{ hello(value: "Foo") }')
assert result.response() == {
    "data": {
        "hello": "Hello Foo!"
    }
}

For more usage examples, you can refer to the User Guide and some more involved examples available in the examples folder.

The tests should also provide some contrived exmaples.

Goals & Status

This project was initially born as an experiment / learning project following some frustration with with graphql-core and Graphene I encountered at work.

The main goals were originally to:

  • Get a deeper understanding of GraphQL

  • Provide an alternative to graphql-core which:

    • tracks the latest version of the spec (which graphql-core didn't)
    • does so without being a port of the JS code which leads to some weird edge case when we tried to extend the library
    • keeps support for Python 2 (which graphql-core-next) didn't.
    • (subjective) attempts to be a bit more usable for our use cases, the ideal result would sit somewhere in between Graphene and graphql-core
    • makes it easier for us to build / include some extra tooling such as custom tracing, custom validation and SDL based tools.

After going through a couple iterations, it should be ready ready for general use to create GraphQL servers; with the notable omissions of:

  • Subscription support
  • Python 2 support has been dropped
  • Middleware have been dropped pending an iteration on the API (and consequently tracers are not supported either)

Development setup

Make sure you are using Python 3.6+.

Clone this repo and create a virtualenv before installing the development dependencies:

git clone git@github.com:lirsacc/py-gql.git
python -m venv $WORKON_HOME/py-gql --copies
pip install -U -r dev-requirements.txt

From there, most development tasks are available through invoke.

Use inv -l to list all available tasks and inv {TASKS} --help to get help on a specific task.

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

py_gql-0.2.0.tar.gz (178.7 kB view hashes)

Uploaded Source

Built Distribution

py_gql-0.2.0-py2.py3-none-any.whl (120.0 kB view hashes)

Uploaded Python 2 Python 3

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