Skip to main content

GraphQL client for Python

Project description

GQL

This is a GraphQL client for Python 3.7+. 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:

# Quotes may be required on certain shells such as zsh.
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)

Executing the above code should output the following result:

$ python basic_example.py
{'continents': [{'code': 'AF', 'name': 'Africa'}, {'code': 'AN', 'name': 'Antarctica'}, {'code': 'AS', 'name': 'Asia'}, {'code': 'EU', 'name': 'Europe'}, {'code': 'NA', 'name': 'North America'}, {'code': 'OC', 'name': 'Oceania'}, {'code': 'SA', 'name': 'South America'}]}

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

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-3.6.0b1.tar.gz (181.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gql-3.6.0b1-py2.py3-none-any.whl (74.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file gql-3.6.0b1.tar.gz.

File metadata

  • Download URL: gql-3.6.0b1.tar.gz
  • Upload date:
  • Size: 181.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.17

File hashes

Hashes for gql-3.6.0b1.tar.gz
Algorithm Hash digest
SHA256 d8d30c5b154f68183de2d11971a197685f7f79255972f70f46f1b822ff0dc62d
MD5 96918a94054ed2d7345782bc232b99be
BLAKE2b-256 b182a809857e1f1b953d49d92531ec21ead28233ac3ca20008b42aabf8414a84

See more details on using hashes here.

File details

Details for the file gql-3.6.0b1-py2.py3-none-any.whl.

File metadata

  • Download URL: gql-3.6.0b1-py2.py3-none-any.whl
  • Upload date:
  • Size: 74.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.17

File hashes

Hashes for gql-3.6.0b1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c1acb7736fda247e21fe99325041eddef16a97e3618fe2d90e1c2ed7fe994d28
MD5 57ad87c75414c6661e2ffb7254c236f0
BLAKE2b-256 ef27a922bc453df59d1e8da0ad4bdfe59a06cbad3d969374355032aa7e470b8b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page