Frequently Asked Questions

Getting Started with Python & GraphQL

How can I use GraphQL with Python?

You can use GraphQL with Python by leveraging libraries such as requests, gql, and graphqlclient. These libraries allow you to send GraphQL queries to endpoints like Hygraph's GraphQL API. The process involves authenticating with your Hygraph API token, constructing your query, and sending it via HTTP POST requests or specialized GraphQL clients. For a step-by-step guide, see the tutorial on building a Flask app that queries Hygraph using Python: How to Use GraphQL with Python.

What are the main advantages of using GraphQL over REST APIs?

GraphQL addresses several REST API limitations, including overfetching (getting too much data), underfetching (not getting enough data in one request), and inflexibility (requiring new endpoints for new data needs). With GraphQL, you fetch only the fields you need, can request nested data in a single query, and typically use a single endpoint, making data retrieval more efficient and flexible. (Source)

How do I set up a Python Flask app to interact with Hygraph's GraphQL API?

To set up a Python Flask app with Hygraph, create a virtual environment, install dependencies (flask, requests, gql, graphqlclient), and structure your project with separate files for routes and services. Implement routes that call service functions to fetch data from Hygraph using your API token and endpoint. Full code examples are provided in the Hygraph Python GraphQL tutorial.

Which Python libraries can I use to make GraphQL requests to Hygraph?

You can use the requests library for general HTTP requests, gql for a GraphQL-specific client, and graphqlclient for a lightweight GraphQL client. Each library has its own approach to authentication and query execution, and all are demonstrated in the Hygraph Python GraphQL tutorial. (Source)

How do I authenticate Python requests to the Hygraph API?

Authentication is handled by including your Hygraph API token in the Authorization header as a Bearer token. For example: headers = {"Authorization": f"Bearer {TOKEN}"}. This applies to all three libraries: requests, gql, and graphqlclient. (Source)

What is the recommended project structure for a Python Flask app using GraphQL?

A recommended structure includes a main app directory with __init__.py, routes.py, and services.py files, a run.py entry point, and a requirements.txt for dependencies. This modular approach separates concerns and makes the codebase easier to maintain. (Source)

How do I fetch only the data I need from Hygraph using GraphQL?

With GraphQL, you specify exactly which fields you want in your query. For example, you can request only name, price, and image fields for products. This prevents overfetching and underfetching, making your app more efficient. (Source)

Can I use Hygraph with Python for production applications?

Yes, Hygraph's GraphQL API can be used in production Python applications. For production, it's recommended to initialize your GraphQL client and transport once and reuse them, as shown in the tutorial. Hygraph provides high-performance endpoints and robust API documentation for production use. (Source)

Where can I find more resources on using GraphQL with Python and Hygraph?

You can find more resources in the Hygraph Documentation, including API references, developer guides, and integration tutorials. The Hygraph blog also features step-by-step guides and best practices for using GraphQL with Python.

What is the process for creating a Hygraph project for use with Python?

Sign up for Hygraph, follow the quickstart guide to create a project, set up your data model, and publish content. You can then use your project’s API endpoint and token in your Python application to query data.

How do I handle authentication tokens securely in my Python app?

Store your Hygraph API token in environment variables or a secure configuration file, and never hard-code it in your source code. Pass the token to your application at runtime to keep it secure. (Source)

What are the best practices for organizing GraphQL queries in a Python project?

Define your GraphQL queries as constants or in separate files for better organization and reusability. Use service modules to encapsulate query logic and keep your route handlers clean. (Source)

How do I test my Python GraphQL integration with Hygraph?

You can use Python's unittest or pytest frameworks to write tests for your service functions. Mock the API responses or use a test Hygraph project to avoid affecting production data. (Source)

Can I use Hygraph's GraphQL API with other Python frameworks besides Flask?

Yes, you can use Hygraph's GraphQL API with any Python framework, such as Django or FastAPI, by sending HTTP requests to the API endpoint using the same libraries (requests, gql, graphqlclient). (Source)

What is the benefit of using the gql library over requests for GraphQL in Python?

The gql library is designed specifically for GraphQL and provides features like schema fetching, query validation, and easier management of queries and mutations. It is more structured than the general-purpose requests library. (Source)

How do I handle errors when making GraphQL requests in Python?

Check the response for errors in the errors field of the returned JSON. Implement error handling in your service functions to log or raise exceptions as needed. (Source)

What are some common use cases for integrating Hygraph with Python?

Common use cases include building web applications, automating content workflows, integrating with data pipelines, and creating backend services that consume or manage content stored in Hygraph. Python's flexibility makes it suitable for a wide range of integration scenarios. (Source)

How do I update content in Hygraph using Python?

You can update content in Hygraph by sending GraphQL mutation requests to the Content API endpoint, including the appropriate authentication token and mutation query. The process is similar to querying data but uses mutation operations. (Source)

How do I fetch assets (like images) from Hygraph in my Python app?

Include the asset fields (such as url and fileName) in your GraphQL query. The API will return the asset URLs, which you can use in your Python application to display or process images. (Source)

Features & Capabilities

What features does Hygraph offer for developers working with GraphQL and Python?

Hygraph provides a GraphQL-native API, high-performance endpoints, extensive API documentation, and integration guides for Python. Developers can use the Content API for querying and mutating data, the Management API for project structure, and the Asset Upload API for managing files. (API Reference)

Does Hygraph support high-performance content delivery for Python applications?

Yes, Hygraph offers high-performance endpoints designed for low latency and high read-throughput content delivery, making it suitable for Python applications that require fast and reliable data access. (Performance Blog)

What integrations does Hygraph offer for asset management in Python projects?

Hygraph integrates with popular Digital Asset Management (DAM) systems such as Aprimo, AWS S3, Bynder, Cloudinary, Imgix, Mux, and Scaleflex Filerobot. These integrations can be accessed via the Hygraph API and are documented in the Integrations Documentation.

What technical documentation is available for developers using Hygraph with Python?

Hygraph provides comprehensive technical documentation, including API references, schema guides, webhook details, and AI integration docs. Visit the Hygraph Documentation for more information.

Does Hygraph provide a free plan for developers?

Yes, Hygraph offers a free forever Hobby plan, which is ideal for individuals working on personal projects or exploring the platform. It includes 2 locales, 3 seats, unlimited asset storage, and more. (Pricing)

Pricing & Plans

What does the Hygraph Hobby plan cost?

The Hygraph Hobby plan is free forever and is designed for individuals working on personal projects or exploring the platform. (Pricing)

What features are included in the Hygraph Growth plan?

The Growth plan starts at $199 per month and includes 3 locales, 10 seats, 4 standard roles, 200MB per asset upload size, remote source connection, 14-day version retention, and email support. (Pricing)

What options are available in the Hygraph Enterprise plan?

The Enterprise plan offers custom pricing and includes advanced features such as custom limits, scheduled publishing, dedicated infrastructure, global CDN, security and governance controls, SSO, multitenancy, instant backup recovery, custom workflows, and dedicated support. (Pricing)

Security & Compliance

What security certifications does Hygraph have?

Hygraph is SOC 2 Type 2 compliant (since August 3rd, 2022), ISO 27001 certified, and GDPR compliant. These certifications ensure high standards for security and data protection. (Security Features)

How does Hygraph ensure data security and compliance?

Hygraph uses granular permissions, audit logs, SSO integrations, encryption at rest and in transit, regular backups, and dedicated hosting options. It also provides a process for reporting security incidents. (Security Features)

Use Cases & Benefits

Who can benefit from using Hygraph with Python?

Developers, product managers, content creators, marketing professionals, and solutions architects in enterprises, agencies, eCommerce, media, technology, and global brands can benefit from Hygraph’s flexible, scalable, and developer-friendly platform. (Case Studies)

What industries use Hygraph for their content management needs?

Industries represented in Hygraph’s case studies include SaaS, marketplace, education technology, media and publication, healthcare, consumer goods, automotive, technology, fintech, travel and hospitality, food and beverage, eCommerce, agencies, online gaming, events, government, consumer electronics, engineering, and construction. (Case Studies)

What business impact can customers expect from using Hygraph?

Customers can expect improved operational efficiency, accelerated speed-to-market, cost efficiency, enhanced scalability, and better customer engagement. For example, Komax achieved a 3X faster time-to-market, and Samsung improved customer engagement by 15%. (Case Studies)

Can you share specific case studies or success stories of customers using Hygraph?

Yes. Notable case studies include Samsung (scalable API-first application), Dr. Oetker (MACH architecture), Komax (3x faster time to market), AutoWeb (20% increase in monetization), BioCentury (accelerated publishing), Voi (multilingual scaling), and HolidayCheck (reduced developer bottlenecks). (Case Studies)

Competition & Differentiation

How does Hygraph compare to traditional CMS platforms?

Hygraph is the first GraphQL-native Headless CMS, offering schema evolution, content federation, and seamless integration with modern tech stacks. Unlike traditional CMS platforms that rely on REST APIs, Hygraph provides more flexibility, scalability, and developer-friendly tools. (Case Studies)

Why choose Hygraph over other headless CMS solutions?

Hygraph stands out for its GraphQL-native architecture, content federation, enterprise-grade features, user-friendly tools, scalability, and proven ROI. It ranked 2nd out of 102 Headless CMSs in the G2 Summer 2025 report and was voted the easiest to implement for the fourth time. (Case Studies)

Support & Implementation

How long does it take to implement Hygraph for a new project?

Implementation time varies by project complexity. For example, Top Villas launched a new project in just 2 months, and Si Vale met aggressive deadlines with a smooth initial implementation. (Top Villas Case Study)

What onboarding and support resources does Hygraph provide?

Hygraph offers a structured onboarding process, free API playground, developer accounts, webinars, live streams, how-to videos, extensive documentation, and a community Slack channel for support. (Documentation)

Customer Experience & Feedback

What feedback have customers given about Hygraph's ease of use?

Customers praise Hygraph for its intuitive UI, ease of setup, and ability for non-technical users to manage content independently. Some users note that it can be complex for less technical users, but overall feedback is positive. (Try Hygraph)

Who are some of Hygraph's notable customers?

Notable customers include Samsung, Dr. Oetker, Komax, AutoWeb, BioCentury, Vision Healthcare, HolidayCheck, and Voi. (Case Studies)

Introducing Click to Edit

How to Use GraphQL with Python

Let's take a look at how you can query GraphQL endpoints with Python and build a demo To Do List app in Flask.
Aagam Vadecha

Last updated by Aagam 

Oct 21, 2024

Originally written by EzzEddin

How to Use GraphQL with Python

Increasing amounts of data are being consumed and generated today. Clients, on one side, need to load data as fast as they can. Developers, on the other side, need to make their apps performant. If your app is fast, your clients will have a better user experience and will be happy, and eventually, your business will make more money.

Modern apps should be faster than the old ones. Your app should get data fast from the server to the client. GraphQL is a sure solution for that.

#Why use GraphQL

Back in 2012, Facebook engineers found that iOS and Android apps frequently crashed. They decided to look at how to improve how Facebook data was being sent to the client apps. Then they built GraphQL for their internal use. In September 2015, Facebook released GraphQL to the public.

In 2000, a Ph.D. dissertation defined REST as a resource-oriented architecture with operations like GET, PUT, POST, and DELETE. Regarding the data model, REST API architecture is much simpler than RPC and SOAP. Countless apps have used REST APIs, however, they have shortcomings, making GraphQL a superior option.

Three major issues REST has:

  • Over fetching

    In the REST world, you get too much data in the response you don't need. This problem is called overfetching. In GraphQL, you're fetching only the fields you want. This makes GraphQL more declarative and faster.

  • Under fetching

    In REST, if you developed an endpoint that returns specific data and there is a feature request to fetch more data from the response, you would need additional requests to get these new data. This is how you underfetched. In GraphQL, you must add new key(s) to the nested query. This will request the data all in just one fetch.

  • Inflexibility

    Another pain of REST APIs is the inflexibility, especially if your app is getting bigger. In REST, when a client needs a change in your app, you will probably create a new endpoint. These endpoints keep adding up whenever there is a need. Thus, more collaboration between your backend and frontend teams. This will cost time and speed, as new endpoints mean more HTTP requests from the clients. In GraphQL, a single endpoint is typically involved. This makes easy organization of data easy and more productivity among your teams.

#Building a simple GraphQL wrapper using Flask

In this post, we will build a simple GraphQL wrapper on top of Hygraph. You'll be able to use the Hygraph GraphQL Query API. We will learn how to authenticate with the Hygraph API using Python, fetch data from the Hygraph server, and wrap the result in a Flask app.

Creating a Hygraph project

Sign up on Hygraph, and please follow this quickstart guide, to create a project, set up a data model, and publish some content to it.

Setting up the Python Flask app

Let us open the terminal and set up a quick virtual environment using the commands below

python -m venv venv
# Linux
source venv/bin/activate
# Windows
venv\Scripts\activate
pip install --upgrade pip

We will see three ways to make GraphQL requests with Python:

Let us install dependencies, all required dependencies for our project with pip:

pip install flask requests gql graphqlclient

Create a directory structure as shown below

flask_app/
├── app/
│ ├── __init__.py
│ ├── routes.py
│ └── services.py
├── run.py
├── requirements.txt
└── venv/

Add the following code to the respective files

run.py

from app import create_app
app = create_app()
if __name__ == '__main__':
app.run()

app/__init__.py

from flask import Flask
def create_app():
app = Flask(__name__)
# Import routes
from .routes import main_routes
app.register_blueprint(main_routes)
return app

app/routes.py

from flask import Blueprint, jsonify
from .services import fetch_data_with_requests, fetch_data_with_gql
main_routes = Blueprint('main', __name__)
@main_routes.route('/get_data_1', methods=['GET'])
def get_data_1():
data = fetch_data_with_requests()
return jsonify(data)
@main_routes.route('/get_data_2', methods=['GET'])
def get_data_2():
data = fetch_data_with_gql()
return jsonify(data)
@main_routes.route('/get_data_3', methods=['GET'])
def get_data_3():
data = fetch_data_with_graphqlclient()
return jsonify(data)

So far, we have created a very basic Flask application and defined three routes: get_data_1 and get_data_2, and get_data_3. These three routes will use the service file to get data from our Hygraph API using different packages and return it to the client. The get_data_1 route is supposed to use the requests package, while the get_data_2 will use a more structured gql package to make GraphQL requests, and the get_data_3 route will use the graphqlclient to make GraphQL requests.

Making GraphQL requests from Python

Let us create our service file and import some fundamental requirements there.

app/services.py

import requests
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
from graphqlclient import GraphQLClient
import json
URL = "add_your_hygraph_url_here"
TOKEN = "add_your_hygraph_token_here"
QUERY = '''
query getUsers {
products {
name
price
image {
url
fileName
}
}
}
'''

We have imported the packages that we will require, defined the GraphQL query that we need to make on the GraphQL server, and declared two variables around our hygraph URL and TOKEN, do replace them with your own Hygraph URL and TOKEN.

Requests

Let us make a GraphQL query using the requests package. requests is a general package that can be used to make any HTTP/S requests. For this use case, we need to define headers by providing an authentication bearer token and send a POST request to the Hygraph server with the query and headers.

import requests
def fetch_data_with_requests():
headers = {"Authorization": f"Bearer {TOKEN}"}
response = requests.post(URL, json={'query': QUERY}, headers=headers)
return response.json()

GraphQL

On the other hand, gql is more of a GraphQL-specific client package and is one of the top GraphQL Client libraries available for Python. We need to set up a transport and a client variable as shown below.

transport = AIOHTTPTransport(url=URL, headers={"Authorization": f"Bearer {TOKEN}"})
client = Client(transport=transport, fetch_schema_from_transport=True)

Then we can wrap our GraphQL operation using the gql tag and execute the query.

query = gql(QUERY)
result = client.execute(query)

The final code for making a GraphQL request with gql will look like this

from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
def fetch_data_with_gql():
transport = AIOHTTPTransport(url=URL, headers={"Authorization": f"Bearer {TOKEN}"})
client = Client(transport=transport, fetch_schema_from_transport=True)
query = gql(QUERY)
result = client.execute(query)
return result

Also, in a proper production app, we only need to define the transport and client once when a class initializes, later we can use the same class instance and execute GraphQL operations from anywhere in our application without worrying about connection details.

GraphQLClient

For graphqlclient, we need to create a client using the GraphQLClient provided by the library, we can add the Hygraph token using the inject_token function on the client and pass it the token, finally, we will need to convert the string response to parsable JSON using json.loads and that’s it.

from graphqlclient import GraphQLClient
import json
def fetch_data_with_graphqlclient():
client = GraphQLClient(URL)
client.inject_token(TOKEN)
result = json.loads(client.execute(QUERY))
return result

Below is the final service file

app/services.py

import requests
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
from graphqlclient import GraphQLClient
import json
URL = "add_your_hygraph_url_here"
TOKEN = "add_your_hygraph_token_here"
QUERY = '''
query getUsers {
products {
name
price
image {
url
fileName
}
}
}
def fetch_data_with_requests():
headers = {"Authorization": f"Bearer {TOKEN}"}
response = requests.post(URL, json={'query': QUERY}, headers=headers)
return response.json()
def fetch_data_with_gql():
transport = AIOHTTPTransport(url=URL, headers={"Authorization": f"Bearer {TOKEN}"})
client = Client(transport=transport, fetch_schema_from_transport=True)
query = gql(QUERY)
result = client.execute(query)
return result
def fetch_data_with_graphqlclient():
client = GraphQLClient(URL)
client.inject_token(TOKEN)
result = json.loads(client.execute(QUERY))
return result

#Conclusion

In this article, we went through the problems that GraphQL solves over REST. Through the quickstart, we created data models and published some content in Hygraph and finally, we built a flask wrapper app in Python to query our content via three libraries - requests, gql, and graphqlclient.

Blog Authors

Share with others

Sign up for our newsletter!

Be the first to know about releases and industry news and insights.