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
.
Documentation
The complete documentation for GQL can be found at gql.readthedocs.io.
Features
- Execute GraphQL queries using different protocols:
- http
- websockets:
- apollo or graphql-ws protocol
- Phoenix channels
- AWS AppSync realtime protocol (experimental)
- Possibility to validate the queries locally using a GraphQL schema provided locally or fetched from the backend using an instrospection query
- Supports GraphQL queries, mutations and subscriptions
- Supports sync or async usage, allowing concurrent requests
- Supports File uploads
- Supports Custom scalars / Enums
- gql-cli script to execute GraphQL queries or download schemas from the command line
- DSL module to compose GraphQL queries dynamically
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gql-3.5.0.tar.gz
.
File metadata
- Download URL: gql-3.5.0.tar.gz
- Upload date:
- Size: 179.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccb9c5db543682b28f577069950488218ed65d4ac70bb03b6929aaadaf636de9 |
|
MD5 | 5bc49c18e3f8129d5c81356380c3549c |
|
BLAKE2b-256 | 3d85feda24b33adcc6c8463a62a8e2ca2cc3425dc6d687388ff728ceae231204 |
File details
Details for the file gql-3.5.0-py2.py3-none-any.whl
.
File metadata
- Download URL: gql-3.5.0-py2.py3-none-any.whl
- Upload date:
- Size: 74.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70dda5694a5b194a8441f077aa5fb70cc94e4ec08016117523f013680901ecb7 |
|
MD5 | 1a56b1e7697fb9f24b4630f7540c973e |
|
BLAKE2b-256 | 74fb01a200e1c31b79690427c8e983014e4220d2652b4372a46fe4598e1d7a8e |