This guide shows how to integrate Python with Apito's GraphQL tools and database API using GQL client for Python 3.6+. Our instant API builder generates GraphQL APIs that play nicely with graphene
, graphql-core
, graphql-js
and any other GraphQL implementation compatible with the spec.
WARNING: Please note that the following documentation describes the current version which is currently only available as a pre-release and needs to be installed with
$ pip install --pre gql[all]
NOTE: See also the documentation to install GQL with less extra dependencies
Tip:
Always remember to replace
API_SECRET
in the Bearer Token andproject-id
in the URL with the correct values from the Apito console.
If you are unsure where to find your API secrets and endpoints for your project, visit this page.
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
# Select your transport with a defined url endpoint
transport = AIOHTTPTransport(url="https://api.apito.io/secured/graphql", headers={'Authorization': 'Bearer API_SECRET'})
# 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)
For a detailed guide, be sure to check out the official github page here