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.5.0b9.tar.gz (179.5 kB view details)

Uploaded Source

Built Distribution

gql-3.5.0b9-py2.py3-none-any.whl (73.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file gql-3.5.0b9.tar.gz.

File metadata

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

File hashes

Hashes for gql-3.5.0b9.tar.gz
Algorithm Hash digest
SHA256 e20e8cbbe0f0b8e56dc7dac1734a60ad388e5e08f8e650ea682fc1cfb90b65c4
MD5 7be24b4b3a269c58c120f46d95c2d175
BLAKE2b-256 c6130f328480f51c5b22aa360c6f76cfc33f24c9452c15f8608245ef2437697e

See more details on using hashes here.

Provenance

File details

Details for the file gql-3.5.0b9-py2.py3-none-any.whl.

File metadata

  • Download URL: gql-3.5.0b9-py2.py3-none-any.whl
  • Upload date:
  • Size: 73.9 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.5.0b9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b0604c40bf3f8c8cd57b85266c1834e93e5e0f887542f59833eec8632e1a4a0d
MD5 9aea47725dac42e07b84b2a66014dbab
BLAKE2b-256 c78f310ce8b72a29a58e7bf45d38bbdc91993affa2fd7447948406938175c97d

See more details on using hashes here.

Provenance

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