Have you ever felt frustrated managing multiple REST endpoints, chasing over-fetching or under-fetching data? Enter GraphQL — a modern alternative to REST APIs that lets clients request exactly what they need.
In this tutorial, you’ll build a simple but powerful Todo API using Python, leveraging:
• ⚡ FastAPI — a blazing fast, modern web framework
• 🍓 Strawberry — a Python-native GraphQL library with type hints
• 💾 SQLite + SQLModel — lightweight and easy data persistence
• 🐳 Docker — containerize your app for easy deployment
• 🌐 Render — deploy your app in minutes for free
By the end, you’ll have a fully working GraphQL API deployed on the cloud — and all the code will be on GitHub for you to explore and extend.
Why Choose GraphQL Over REST?
REST APIs are great, but as apps grow, you often face challenges:
• Multiple endpoints for related data
• Over-fetching or under-fetching data
• Versioning headaches
GraphQL solves these by letting clients ask for exactly the data they want in a single request, reducing network overhead and improving developer experience.
What You’ll Build
A Todo API that supports:
• Adding todos
• Marking them completed
• Deleting todos
• Querying all or filtered todos
All via a clean GraphQL schema, with a built-in playground UI to try queries live.
Setting Up the Project
- Create a new folder and initialize the project
mkdir graphql-todo-api
cd graphql-todo-api
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Create a requirements.txt file with these dependencies:
fastapi
strawberry-graphql[fastapi]
uvicorn
sqlmodel
- Install the dependencies
pip install -r requirements.txt
Understanding GraphQL: The Basics
GraphQL is a query language for APIs developed by Facebook to make data fetching more efficient and flexible than traditional REST APIs.
How GraphQL Differs from REST
• Single Endpoint: Unlike REST which uses multiple endpoints (e.g., /todos, /users), GraphQL uses a single endpoint (like /graphql) to handle all requests.
• Client-Driven Queries: Clients specify exactly what data they want — no more, no less. This prevents over-fetching or under-fetching.
• Strongly Typed Schema: GraphQL APIs expose a schema that defines the types of data and operations (queries and mutations) available.
• Real-time Data: Supports subscriptions for real-time updates (though not covered here).
Key Concepts
Term: What It Means
Query: A read-only fetch operation
Mutation: A write operation (create, update, delete)
Schema: The structure defining data types & operations
Resolver: Function that fetches or modifies data for a field
🧱 Tech Stack: What We Used and Why
Let’s break down each tech choice and why it made sense for this project:
🐍 Python
The language of choice for rapid backend development. Python’s clean syntax and huge ecosystem made building and testing fast.
⚡ FastAPI
A modern web framework built for speed and type safety. We chose FastAPI because:
• It uses Python type hints for automatic validation and docs
• It plays well with async and GraphQL
• It’s fast enough for production workloads
🍓 Strawberry GraphQL
A Pythonic GraphQL library that feels natural for developers. We chose Strawberry because:
• It lets you define GraphQL schemas using plain Python classes
• It supports modern typing and IDE autocompletion
• It integrates smoothly with FastAPI
💾 SQLite + SQLModel
SQLite is lightweight and file-based — ideal for demo and local development.
SQLModel (by the creator of FastAPI) combines Pydantic and SQLAlchemy to:
• Define data models with type hints
• Automatically create and query the SQLite database
• Keep everything concise and maintainable
🐳 Docker
Docker helps package the app with all dependencies so it runs identically everywhere.
We used it to:
• Create a container that holds Python, the app, and its dependencies
• Avoid “it works on my machine” bugs
• Simplify deployment to Render
🌐 Render
Render is a developer-friendly cloud platform with a free tier. It:
• Connects to GitHub
• Deploys Docker containers automatically
• Provides a public URL out of the box
✨ Try It Live
No setup needed — you can try the GraphQL API right now:
👉 https://graphql-todo-api.onrender.com/graphql
Use the playground to:
• Add a todo
• Mark it completed
• Delete it
• Filter by status
Note: The app would take upto one minute to load if the application is set to idle for more than 15 minutes, since, it is hosted for feee and Render would free up the space for utilisation.
🧭 What’s Next?
Some ideas to extend this project:
• Add a React UI with Apollo Client
• Migrate to PostgreSQL for production
• Add JWT authentication
• Use GraphQL subscriptions for real-time updates
💬 Final Thoughts
This project shows how smooth and elegant building a GraphQL API in Python can be — no REST clutter, no boilerplate, and fully typed.
If you’re curious about GraphQL or tired of juggling REST endpoints, this stack is worth exploring.
🙌 Like What You Read?
If this helped you:
- 💬 Leave a comment
- 🔁 Share it with your network
- 🌟 Star the GitHub repo!
Let's connect on LinkedIn!
Top comments (0)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.