Skip to main content
In this project we generated a large set of fake CSV data with help from a local LLM, imported it into a SQLite database, and built a small REST API in Python (FastAPI) that can either query the DB or generate fake data on demand. This guide shows the core files, minimal DB helper, simple generators (no external Faker dependency), and how to run and test the service.

CSV sample

A short excerpt of the CSV we imported into SQLite (the full file is in the project):
We imported this CSV into a table named fake_data inside a SQLite file named fakeData.db. After creating the DB and importing the CSV, the database UI looked like this:
A dark-mode screenshot of DB Browser for SQLite displaying a table named "fake_data" with columns like first_name, last_name, email_address, age, city, and occupation populated with sample rows. The right pane shows an editor for the selected cell (an email address).
With fakeData.db saved and verified, the next step is building a small API that can either query the fake_data table or generate additional fake records on demand.

Quick DB helper (SQLAlchemy)

We use SQLAlchemy to obtain DB sessions inside FastAPI routes. Create a simple DB helper that exposes a get_db dependency for route injection:
Use get_db() in endpoints that need to query the fake_data table (example wiring is listed in “Next steps” below).

Choosing a Python web framework

FastAPI was selected for this project due to its performance, developer ergonomics, and automatic OpenAPI docs. Flask and Django are valid alternatives depending on project needs: An annotated comparison screenshot used during exploration:
A dark-themed screenshot showing a comparison list of web frameworks (FastAPI and Flask) with bullet-pointed pros and cons. A white mouse cursor is visible over the text.

Project scaffold

A minimal project layout used for this example:

main.py — start the FastAPI app

A minimal main.py that mounts the router and runs via Uvicorn:
If FastAPI or Uvicorn are not installed, running python main.py will raise an import error:
Install the runtime dependencies:
When the app starts successfully you’ll see logs like:

Request model (Pydantic)

Use a Pydantic model to validate incoming POST requests for fake-data generation:
Pydantic provides automatic validation and descriptive errors for missing/invalid fields.

Router and generating fake data (no third-party Faker)

To keep dependencies minimal, this project uses simple Python-based generators rather than the external faker library. The API exposes a POST endpoint /getfakedata which maps data_type to a generator function:
This single router organizes endpoints and keeps a clear mapping between data_type and the generator function. Supported data types and generators:

Example request / response

Send a POST to /getfakedata with JSON:
A typical successful response:
Validation error when required fields are missing (FastAPI returns 422):
Invalid data_type example (400 response):

Running and testing

Start the app:
Use curl, httpie, or Postman to test endpoints:
  • POST http://localhost:8000/getfakedata with JSON shown above.
  • Visit http://localhost:8000/docs for automatically generated OpenAPI docs.
Watch Uvicorn logs to see incoming requests and response codes (200/422/400).
When using Copilot or any code generator, treat the output as a draft: validate imports, run tests, and adapt generated code to your project structure (packages, relative imports, DB paths). In this example we intentionally replaced external Faker usage with small local generators to reduce dependencies and keep full control over output.

Next steps (wiring DB queries and expanding features)

Suggested enhancements to connect the API to the SQLite dataset and make it production-ready:
  • Wire endpoints to query fake_data using get_db() (SQLAlchemy session). Example pattern:
  • Add query parameters or dedicated endpoints for filtering (by city, age, occupation), sorting, and pagination.
  • Add unit tests for endpoints and generator functions (pytest).
  • Add API documentation notes and curated OpenAPI examples (FastAPI supports response_model and examples).
  • Consider using SQLAlchemy models to map fake_data rows to ORM objects for cleaner queries.
This completes the initial API scaffolding and simple fake-data generator. Next, we’ll connect the API to the SQLite dataset and expand the feature set (filtering, pagination, and documentation).

Watch Video