Skip to main content

Python GraphQL Client Library

Project description

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

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

gql-next-0.1.1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

gql_next-0.1.1-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file gql-next-0.1.1.tar.gz.

File metadata

  • Download URL: gql-next-0.1.1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.11 CPython/3.7.2 Darwin/18.2.0

File hashes

Hashes for gql-next-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7c27ad4ed06b87950991c392387bbd4525b6a266c23731002c892f8fb6c8c383
MD5 655bf9814e9e8f9fd3a860fe5addc352
BLAKE2b-256 36ec5413b0cf71059f5f066cfd1a664fe85cd3283965f6c1eb88e5e287e83d19

See more details on using hashes here.

File details

Details for the file gql_next-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: gql_next-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 28.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.11 CPython/3.7.2 Darwin/18.2.0

File hashes

Hashes for gql_next-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 189f2ac00b206753b5079003f0c27377ba5a0ab6737438364a70a044c806b6a2
MD5 e0f119c9903b8cc60b12467e4a52b53a
BLAKE2b-256 36cfe0d49f16f069d55991ef76620762a28abf09b00b653df06feb5a67b00054

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