Skip to docs content

Python GraphQL Integration - GraphQL Tools & Database API

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.

Installation

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 and project-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.

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://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)

Detailed Guide

For a detailed guide, be sure to check out the official github page here