Easily restore your project to a previous version with our new Instant One-click Backup Recovery

Headless CMS for Python

Hygraph is the ideal Headless CMS for Python websites and applications. Read further to learn how our API-first CMS allows you to add components to your Python apps in minutes and enable your website's content to be managed from a powerful CMS.

Step #1 - Querying the data

Querying the GraphQL API from the headless CMS such as Hygraph requires only the requests library which you can install with the following command in your terminal:

pip install requests

In order to parse the data, you'll need the json library. Once you have imported those, you'll need to store your Hygraph Content API endpoint and the token as variables.

query_products = """query MyQuery {
products {
slug
name
description
availability
}
}
"""
url = "https://api-<region>.hygraph.com/v2/<some hash>/master" # add your Content API endpoint
token = "YOUR_HYGRAPH_TOKEN"
headers = {"Authorization": f"Bearer {token}"}
def get_products():
payload = {"query": query_products}
r = requests.post(url, json=payload, headers=headers)
json_data = r.json()
return json_data

Step #2 - Work with mutations - store content in the headless CMS

GraphQL mutations are essential if you also want to store the data in Hygraph from your Python project. They allow for direct content manipulation—creating, updating, and deleting—via structured commands.

In Python, executing a mutation is straightforward: construct the mutation query, send it through a POST request using the requests library, and handle the response.

add_review = """mutation {
createReview(
data: {
reviewerName: "John Doe"
description: "Crisp, clear audio quality; compact design; user-friendly interface; affordable price.",
verifiedPurchase: true
},
{
reviewerName
description
verifiedPurchase
}
}"""
url = "https://management.hygraph.com/graphql"
token = "YOUR_HYGRAPH_TOKEN"
headers = {"Authorization": f"Bearer {token}"}
def add_review():
payload = {"query": add_review}
r = requests.post(url, json=payload, headers=headers)
json_data = r.json()
return json_data

Start building with Python

We made it really easy to set up your project in Hygraph and use our GraphQL API within your Python project.

Quickstart

Take a look at our documentation on setting up your project within minutes and using our GraphQL API with your Python project.

Learn GraphQL

Hygraph is GraphQL-native Headless CMS offers precise data retrieval, minimizing over-fetching and optimizing efficiency.

Examples

Look at some of the example projects to see Hygraph in action.

Why Hygraph

Choosing Hygraph for your Python project

Hygraph is a top choice for Python projects as a headless CMS, thanks to its GraphQL-based API which aligns well with Python's efficient and straightforward approach to backend development. It facilitates precise content delivery, crucial for Python's data-driven applications. The CMS's robust features, like an intuitive content editor and adaptable content models, streamline content management.

This allows Python developers to concentrate on refining core functionalities and enhancing the overall application. With strong security and the ability to scale, Hygraph supports rapidly deploying high-performance applications across various industries.

headless cms for python

Developer Experience

We try to be the most un-opinionated CMS on the market with a wide collection of open source example projects to get you started.

Headless CMS

As a headless CMS (i.e. API based content management), you can be as modular and flexible as you need. We even support multiplatform content management.

Management API

Hygraph boasts a flexible and powerful management API to manage your content and schema, as well as a blazing fast content API.

Get started for free, or request a demo to discuss larger projects