Skip to main content
In this tutorial, we’ll import fake data from a CSV into SQLite and then wrap it in a RESTful API using FastAPI—with help from GitHub Copilot. By the end, you’ll have a working API that generates and persists fake data.

Importing Fake Data into SQLite

First, open DB Browser for SQLite and create a database called fake_data_generator.db. Then import fake-data.csv into a table named fake_data:
The image shows a code editor with a CSV file open, displaying a list of fake data entries including names, emails, ages, cities, and occupations. The file is part of a project named "FakeDataGenerator" in a directory structure.
  1. In DB Browser, choose File > Import > Table from CSV file.
  2. Select fake-data.csv.
  3. Set the table name to fake_data, enable Column names in the first line, and click OK.
The image shows a screenshot of a database management application, specifically DB Browser for SQLite, with a CSV import dialog open. It displays options for importing data into a table named "fake_data" and shows a preview of the data with columns like first name, last name, age, and occupation.
Ensure your CSV headers match the column names you want in SQLite. This makes querying and persistence more straightforward.
Once imported, confirm that fake_data is populated and ready for queries.

Scaffolding the Python Project

Open your project root in VS Code:
The image shows a Visual Studio Code interface with a file explorer open on the left, displaying various files. A warning message indicates that a file is not displayed because it is either binary or uses an unsupported text encoding.
Create main.py to invoke the CLI generator:
Open GitHub Copilot Chat in VS Code and ask:
If it suggests the wrong stack (e.g., TypeScript), use the context menu to clear or restart:
The image shows a code editor with a file directory on the right, and a context menu open with options related to code suggestions or issues.
Refine prompts carefully. Copilot can veer off into other languages or frameworks if not guided.

Choosing the Right Framework

Let Copilot compare FastAPI, Flask, and Django REST Framework:
The image shows a comparison of pros and cons for FastAPI, Flask, and Django REST Framework, highlighting features like performance, documentation, and community support.
Here’s a quick comparison: We’ll proceed with FastAPI for its speed and automatic documentation.

Generating the FastAPI Project Structure

Ask Copilot:
It may suggest:
Open the workspace, rename it to FakeDataGeneratorAPI, then:
  1. Move src contents to the project root.
  2. Remove unused files (.env, README.md, etc.).
  3. Add a tests folder at the root.
The image shows a Visual Studio Code interface with a Python project directory structure for a REST API. The left panel displays the file explorer, and the right panel shows a proposed directory structure and a chat with GitHub Copilot.
Final layout:
Use Copilot iteratively until you’re happy:
The image shows a Visual Studio Code interface with a project directory structure for a FastAPI project, including various Python files and folders. The right panel displays a GitHub Copilot chat discussing the setup of the project.

Implementing the FastAPI Application

Install dependencies:
Create main.py at the root:
Run and verify:

Defining the Database Dependency

In db/database.py, configure SQLAlchemy for SQLite:

Creating the Pydantic Request Model

Define models/fake_data_request.py:

Implementing the Fake Data Endpoint

Install Faker:
Add /getfakedata in api/endpoints/router.py:

Testing the POST Endpoint

Send this request:
Expected response:

Next Steps

  • Persist generated records into SQLite.
  • Add OpenAPI metadata and detailed endpoint docs.
  • Write tests in tests/ to validate both database and API layers.

Watch Video