Introduction
This quickstart will guide you through setting up QStash to run a daily script to clean up your database. This is useful for testing and development environments where you want to reset the database every day.Prerequisites
- Create an Upstash account and get your QStash token
1
Create Python app
First, we’ll create a new directory for our Python app. We’ll call it
clean-db-cron
.The database we’ll be using is Redis, so we’ll need to install the upstash_redis
package.2
Cleanup logic
Let’s write the Python code to clean up the database. We’ll use the Try running the code to see if it works. Your database keys should be deleted!
upstash_redis
package to connect to the database and delete all keys.index.py
3
Make the Python code into a public endpoint
In order to use QStash, we need to make the Python code into a public endpoint. There
are many ways to do this such as using Flask, FastAPI, or Django. In this example, we’ll
use the Python For the purpose of this tutorial, I’ll deploy the application to Vercel using the
Python Runtime, but feel free to
use any other hosting provider.
Once deployed, you can find the public URL in the dashboard.
http.server
module to create a simple HTTP server.api/index.py
Deploying to Vercel
Deploying to Vercel
4
Have QStash invoke the endpoint
There are two ways we can go about configuring QStash. We can either use the QStash dashboard
or the QStash API. In this example, it makes more sense to utilize the dashboard since we
only need to set up a singular cronjob.However, you can imagine a scenario where you have a large number of cronjobs and you’d
want to automate the process. In that case, you’d want to use the QStash Python SDK.To create the schedule, go to the QStash dashboard and enter
the URL of the public endpoint you created. Then, set the schedule to run daily at a time of your choosing.
Once you start the schedule, QStash will invoke the endpoint at the specified time. You can
scroll down and verify the job has been created!

Using the SDK
Using the SDK
If you have a use case where you need to automate the creation of jobs, you can use the SDK instead.