Skip to main content

py-gql

GitHub Workflow Status Codecov PyPI PyPI - Python Version Wheel Read the Docs (version)

py-gql is a pure python GraphQL implementation aimed at creating GraphQL servers and providing common tooling.

It supports:

  • Parsing the GraphQL query language and schema definition language.
  • Building a GraphQL type schema programmatically 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

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 "Hello {}!".format(value)


result = graphql_blocking(schema, '{ hello(value: "World") }')

assert result.response() == {
    "data": {
        "hello": "Hello World!"
    }
}

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 examples.

Goals & Status

This project was initially born as an experiment / learning project following some frustration 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 at the time)
    • 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
    • (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 as well as builder infrastructure to support easily implementing graphql layers over existing data layers (such as ORM)

Not all these points are satisfied yet, and some have been changed over time, but py-gql should be ready for general use. It is however still in a fairly experimental phase and to reflect that versions are still in the 0.x.y.The API is still subject to change as different part of the codebase are iterated on and are getting more use against production codebases.

Development setup

Make sure you are using Python 3.6+ (you can run the tests under 3.5 but `other development tasks such as black are not guaranteed to work).

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 requirements-dev.txt
pip install -e .

Development tasks are available through invoke. Check tasks.py or use inv -l to list all available tasks and inv --help {TASK} to get help on a specific task. Most of the tools used should be usable directly, but the tasks provide some common aliases and targets.

As a shortcut, inv check will run all checks that are normally run on CI (lint, typecheck and tests).

CI is done on Github Actions.

Branches

  • The last tag should correspond to the latest release version
  • master contains unreleased changes that are planned to be released
  • dev is used for experimenting and hard changes such as rebase and force pushed should be expected. For now this is the branch I used in side projects and where most of the iteration happens.

Metadata

Release files for py-gql 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-gql 0.6.1
File Size Uploaded
py_gql-0.6.1.tar.gz 247.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-gql 0.6.1
File Interpreter ABI Platform
py_gql-0.6.1-py3-none-any.whl Python 3 none any Details

Total release size: 391.1 kB

Release files / py_gql-0.6.1.tar.gz

Download URL py_gql-0.6.1.tar.gz
Size 247.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8df8496302dacb71b6076db72ef363a1f05ac6dd41ac2a5a96efa99ef6b90d09
BLAKE2b-256 checksum
How to use checksums
51f3c299e8f6de546c3d2540da076c4437bdff32c24014c91e2437b4ade9ec8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1+

Release files / py_gql-0.6.1-py3-none-any.whl

Download URL py_gql-0.6.1-py3-none-any.whl
Size 143.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15707a69e5fc9c6a079ae54a2c33829567c8e1b066a2683f22c019be2553ffa1
BLAKE2b-256 checksum
How to use checksums
6decedcbf6f32b6f95d8c566fad2669427784b4a7caf236c7d7a0d380a263290
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1+

Release history Release notifications | RSS feed

This release

0.6.1 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page