CodeBlanks Logo Icon CodeBlanks

Project design

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:

  1. Async skeleton: the fetch_tasks function.
  2. Async layer: asyncio.gather for multiple sources.
  3. Database: the SQLAlchemy Task model.
  4. Route: the FastAPI /tasks.
  5. Decorator: log_call for 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

main.py
# 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 result

Sample solution

main.py
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

Question
async def fetch_tasks():
    ____
Answer
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

All lessons in Advanced