Skip to content

graphql-python/gql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6c91bb5 · May 20, 2022
Apr 9, 2022
May 19, 2022
May 15, 2020
May 20, 2022
May 19, 2022
May 15, 2020
Oct 24, 2021
Jun 14, 2020
Sep 16, 2021
Jun 27, 2016
Apr 9, 2022
Apr 9, 2022
Apr 23, 2022
May 15, 2020
Apr 9, 2022
Dec 10, 2021

Repository files navigation

GQL

This is a GraphQL client for Python 3.6+. Plays nicely with graphene, graphql-core, graphql-js and any other GraphQL implementation compatible with the spec.

GQL architecture is inspired by React-Relay and Apollo-Client.

GitHub-Actions pyversion pypi Anaconda-Server Badge codecov

Documentation

The complete documentation for GQL can be found at gql.readthedocs.io.

Features

Installation

You can install GQL with all the optional dependencies using pip:

pip install gql[all]

NOTE: See also the documentation to install GQL with less extra dependencies depending on the transports you would like to use or for alternative installation methods.

Usage

Basic usage

from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport

# Select your transport with a defined url endpoint
transport = AIOHTTPTransport(url="https://countries.trevorblades.com/")

# Create a GraphQL client using the defined transport
client = Client(transport=transport, fetch_schema_from_transport=True)

# Provide a GraphQL query
query = gql(
    """
    query getContinents {
      continents {
        code
        name
      }
    }
"""
)

# Execute the query on the transport
result = client.execute(query)
print(result)

WARNING: Please note that this basic example won't work if you have an asyncio event loop running. In some python environments (as with Jupyter which uses IPython) an asyncio event loop is created for you. In that case you should use instead the async usage example.

Contributing

See CONTRIBUTING.md

License

MIT License