This is a Redis starter template for Python using:
- make
- python>=3.10
- uv
- docker
- Optional outside tests
Copy and edit the .env file:
cp .env.example .envYour .env file should contain the connection string you copied from Redis Cloud.
Available settings:
APP_ENV=development|test|productionLOG_LEVEL=DEBUG|INFO|WARNING|ERROR|CRITICALLOG_STREAM_KEY=logsPORT=8080REDIS_URL=redis://...
For docker, .env.docker should use container-internal addresses. Example:
APP_ENV=production
LOG_LEVEL=INFO
LOG_STREAM_KEY=logs
REDIS_URL="redis://redis:6379"Next, spin up docker containers:
make dockerYou should have a server running on http://localhost:<port> where the port is set in your .env file (default is 8080). You can test the following routes:
GET /api/todos- Gets all todosGET /api/todos/:id- Gets a todo by IDGET /api/todos/search?[name=<name>]&[status=<status>]- Search for todos by name and/or statusPOST /api/todos- Create a todo with{ "name": "Sample todo" }PATCH /api/todos/:id- Update todo by ID with{ "status": "todo|in progress|complete" }DELETE /api/todos/:id- Delete a todo by ID
Todos are serialized with JS-compatible camelCase timestamps:
createdDateupdatedDate
Validation and client errors use the JSON envelope:
{ "status": 400, "message": "Todo must have a name" }Requests and component logs are written to stdout. They are also shipped to Redis as stream entries via XADD on the key configured by LOG_STREAM_KEY (default logs).
The test suite lives in __test__ and can be run with:
make testIf REDIS_URL points at the default local Redis and nothing is listening on it, the tests will start the redis service with docker compose automatically and stop it afterward.
Install dependencies and run the dev server:
make install
make devFor a production-style server:
make serveRun make to see the list of available commands.
Useful targets:
make formatmake lintmake updatemake lock
If you don't yet have a database setup in Redis Cloud get started here for free.
To connect to a Redis Cloud database, log into the console and find the following:
- The
public endpoint - Your
username - Your
password
Combine them into a connection string and put it in .env and .env.docker. Example:
REDIS_URL="redis://default:<password>@redis-#####.c###.us-west-2-#.ec2.redns.redis-cloud.com:#####"Run make test to verify the connection.