Skip to main content

GQL: Python GraphQL Client Library

Build Status Coverage Status

Introduction

GQL is a GraphQL Client Python library intended to help Python application make GraphQL API call while enjoying the advantages that come with GraphQL.

  • Strongly Typed response objects (dynamically created in build time to match your query)
  • Query Validation that checks your code's queries against the GraphQL server's schema.

Installation

Simply install from PyPi:

pip install gql-next

Then go to your project folder and run gql init

Quick Start

gql works by parsing query files (**/*.graphql by default) into their own Python module where an class, named after the operation defined in the file, allows you to make that query and get a typed response.

For example, given the following file get_film.graphql file:

query GetFilm($id: ID!) {
  film(id: $id) {
    title
    director
  }
}

A get_film.py will be created defining a GetFilm class:

# AUTOGENERATED file. Do not Change!
from typing import Any, Callable, Mapping, List
from enum import Enum
from dataclasses import dataclass
from dataclasses_json import dataclass_json
from gql.clients import Client, AsyncIOClient


@dataclass_json
@dataclass
class GetFilm:
    @dataclass_json
    @dataclass
    class GetFilmData:
        @dataclass_json
        @dataclass
        class Film:
            title: str
            director: str
        film: Film = None

    data: GetFilmData = None
    errors: Any = None

    @classmethod
    def execute(cls, id: str, on_before_callback: Callable[[Mapping[str, str], Mapping[str, str]], None] = None) -> GetFilm:
        ...

    @classmethod
    async def execute_async(cls, id: str, on_before_callback: Callable[[Mapping[str, str], Mapping[str, str]], None] = None) -> GetFilm:
        ...

Allowing you to make the GraphQL query:

from .get_film import GetFilm

result = GetFilm.execute('meaning_of_life')
film = result.data.film

Important notes:

  • Operations defined in graphql query must be named so that we can name the relevant Python Class which you can then import in your code

How it works

The gql client

gql init

Initializes a project to use GQL as client - writes a .gql.json configuration file.

gql run

Run through your project's files and compile GraphQL queries into into Python types.

gql watch

Useful during development. Listen to file changes in your project's folder and continuously builds GraphQL queries as they change. This allows you to:

  • Immediately verify query changes you make are valid.
  • Enjoy your IDE's autocomplete features on GraphQL auto-generated objects while developing as watch will auto-update them as you change queries.

Sponsors

Metadata

Release files for gql-next 0.1.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 gql-next 0.1.1
File Size Uploaded
gql-next-0.1.1.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gql-next 0.1.1
File Interpreter ABI Platform
gql_next-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 38.6 kB

Release files / gql-next-0.1.1.tar.gz

Download URL gql-next-0.1.1.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7c27ad4ed06b87950991c392387bbd4525b6a266c23731002c892f8fb6c8c383
BLAKE2b-256 checksum
How to use checksums
36ec5413b0cf71059f5f066cfd1a664fe85cd3283965f6c1eb88e5e287e83d19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.11 CPython/3.7.2 Darwin/18.2.0

Release files / gql_next-0.1.1-py3-none-any.whl

Download URL gql_next-0.1.1-py3-none-any.whl
Size 28.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
189f2ac00b206753b5079003f0c27377ba5a0ab6737438364a70a044c806b6a2
BLAKE2b-256 checksum
How to use checksums
36cfe0d49f16f069d55991ef76620762a28abf09b00b653df06feb5a67b00054
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.11 CPython/3.7.2 Darwin/18.2.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

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