Skip to main content
In the previous lesson we generated a CSV of fake people data using a local LLM. In this article we’ll import that CSV into a local SQLite database and scaffold a compact FastAPI-based REST API that serves generated fake data (names, emails, phones, etc.). The goals are:
  • Import the generated CSV into SQLite.
  • Create a FastAPI application.
  • Add a single router with a POST endpoint that returns generated fake data.
  • Iterate with GitHub Copilot but review and adjust all suggested code.
Here is an excerpt of the CSV we’ll import (the full file is in the project):
Import this CSV into SQLite using DB Browser for SQLite:
  1. Create a new database (for example, fakeData.db).
  2. Use File → Import → Table from CSV File.
  3. If your CSV has a header row, verify and adjust column names during import.
  4. Confirm rows appear correctly in the table view and save the DB file.
A dark-themed DB Browser for SQLite window displaying a "fake_data" table with columns like first_name, last_name, email_address, age, city, and occupation filled with sample rows. A right-side panel shows an open cell editor with an email address and editing details.
Once the import is complete, save and close DB Browser. The SQLite file (fakeData.db) is ready to be used by the API.
GitHub Copilot (or any code assistant) is helpful for scaffolding and iteration. Always review and test automatically generated code before using it in production.

Choosing a framework

Common Python frameworks for building web APIs:
  • FastAPI — async-first, excellent performance, automatic OpenAPI docs (Swagger/ReDoc), Pydantic-based validation.
  • Flask — minimal and flexible; requires more boilerplate for larger APIs.
  • Django — full-featured framework with an ORM; best for monolithic apps but can be overkill for small microservices.
For this small, async-friendly API we use FastAPI for its speed and developer ergonomics. When experimenting with Copilot the assistant suggested a project layout that works well as a starting point:
A screenshot of a code editor/workspace showing a proposed FastAPI project directory tree with folders like src (api, core, db, models, schemas, services), init.py, main.py, tests, .env, requirements.txt and README.md. A "Create Workspace..." button with a hand cursor is visible at the bottom.
A minimal layout we used: This structure is lightweight and keeps routing centralized for quick iteration. For larger projects split routers and services into separate modules.

main.py

A compact FastAPI app that includes the router and can be run with Uvicorn:
Run locally:
Typical startup logs:

Database helper (SQLAlchemy)

When you’re ready to query the SQLite database, create a small DB helper with SQLAlchemy and a session dependency:
Wire this dependency into route handlers later when you start reading from the fake_data table via SQLAlchemy models or raw SQL.

Request model (Pydantic)

Define the POST request body with Pydantic so FastAPI validates incoming requests automatically:

Single router with a POST endpoint

For rapid prototyping we keep a single router file (src/api/endpoints/router.py) that contains a root GET and the POST /getfakedata endpoint. Initially we use small internal generators (no external packages) so you can test quickly before hooking the API up to the SQLite table.
Notes:
  • This in-memory generator is intentionally lightweight to get you up and running quickly.
  • Replace these internal generators with database-backed retrieval (SQLAlchemy queries or raw SQL) when you’re ready to serve realistic records from fake_data.
  • For larger applications, split routers, services, and database models into separate modules.

Example: POST request and responses

Request (JSON):
Possible response (200 OK):
Validation and error responses:
  • If the request body is missing or malformed, FastAPI/Pydantic returns a 422 Unprocessable Entity with field-level errors.
  • If data_type is unsupported, the endpoint returns a 400 with a clear error message.
Example missing body (422 Unprocessable Entity):

Iteration with Copilot

GitHub Copilot Chat helped scaffold:
  • Project directory suggestions.
  • Pydantic models and example endpoints.
  • Small implementations that you can adapt.
When using Copilot interactively, be explicit in prompts (framework, files to modify, constraints such as “do not add external packages”). Review, test, and lock down any generated code before relying on it.
When relying on code assistants, be explicit in prompts (framework, file to modify, constraints like “do not add external packages”). Always run and test generated code.

Next steps (roadmap)

  • Replace in-memory generation with code that queries the fake_data table in fakeData.db (via SQLAlchemy models or raw SQL).
  • Add response models (Pydantic) and API versioning.
  • Add unit tests with pytest and CI configuration.
  • Consider pagination, filtering, and column selection endpoints.
  • Add OpenAPI documentation examples and client usage snippets.
This lesson demonstrated importing CSV data into SQLite, scaffolding a FastAPI project (with Copilot assistance), and implementing a simple POST endpoint to return generated fake data. In a follow-up article we’ll wire the API to the SQLite dataset and add tests and documentation.

Watch Video