Project design
- Python course
- Advanced
- Lesson 79/83
- 6 min
Design the advanced final skeleton.
Project design
In this 5-lesson project you'll build a tasks API. Each lesson adds one layer: first an async skeleton, then asyncio.gather, then a SQLAlchemy database, then a FastAPI route, and finally a decorator for call logging.
import asyncio
async def fetch_tasks():
return [...]The first lesson just lays the skeleton: an async function returns a fixed list of tasks. In later lessons you'll wire this function to a real database. Starting simple keeps the layers visible.
Layer order
The layers of the project are added in order:
- Async skeleton: the
fetch_tasksfunction. - Async layer:
asyncio.gatherfor multiple sources. - Database: the SQLAlchemy
Taskmodel. - Route: the FastAPI
/tasks. - Decorator:
log_callfor logging.
Each lesson's starting code contains the previous solution; you only add the new layer. This mirrors how real-world projects grow.
Practice Write the fetch_tasks skeleton
Start with import asyncio. Define async def fetch_tasks(): whose body does return [{"id": 1, "title": "Görev 1"}, {"id": 2, "title": "Görev 2"}]. Then print the result with print(asyncio.run(fetch_tasks())).
Starter code
# bring in the asyncio module
# define an async function named fetch_tasks
# the function returns a fixed list of tasks
# run the function with asyncio.run and print the resultSample solution
import asyncio
async def fetch_tasks():
return [{"id": 1, "title": "Görev 1"}, {"id": 2, "title": "Görev 2"}]
print(asyncio.run(fetch_tasks()))Expected output
[{'id': 1, 'title': 'Görev 1'}, {'id': 2, 'title': 'Görev 2'}]
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does the first lesson of this project define?
- The FastAPI app
- The async fetch_tasks skeleton Correct answer
- The SQLAlchemy model
- The decorator
Explanation: The first lesson only defines the async fetch_tasks skeleton.
2 Complete the fetch_tasks definition
async def fetch_tasks():
____
async def fetch_tasks():
return [...]
Explanation: fetch_tasks returns a list.
3 Match the layers
| Term | Meaning |
|---|---|
fetch_tasks |
Async skeleton |
asyncio.gather |
Multiple sources |
Task |
Database model |
@app.get |
FastAPI route |