Skip to main content
We previously generated a large set of fake people data with a local LLM and exported it as CSV. In this guide we’ll:
  • Import that CSV into a local SQLite database.
  • Scaffold a small FastAPI service that can return fake-person records on demand (for example: “give me 50 fake names, email addresses, ages, etc.”).
  • Implement a minimal Pydantic request model and a POST endpoint for generating fake data.
  • Show how to connect FastAPI to SQLite using SQLAlchemy with a dependency-based session.
Here is a portion of the CSV we generated (we will import this into SQLite):
Importing the CSV into SQLite
  1. Open DB Browser for SQLite (or your preferred SQLite client).
  2. Create a new database file (for example fakeData.db).
  3. Use File → Import → Table from CSV and import fake_data.csv.
    • If your CSV includes headers, make sure “Column names in the first line” is checked.
  4. Verify the table is populated in Browse Data mode.
A screenshot of DB Browser for SQLite showing a "fake_data" table in Browse Data mode with columns like first_name, last_name, email_address, age, city, and occupation populated with sample rows. The right panel shows a cell editor open for an email address and database/file controls across the top.
After saving and closing DB Browser you should have fakeData.db (or whatever filename you chose) ready to use from your application. Example terminal prompt where the project lives:
Planning the API
  • Goal: small Python REST API that returns fake-person data on demand.
  • Framework: FastAPI — chosen for performance, async support, and automatic interactive docs.
  • Productivity: GitHub Copilot Chat was used to accelerate scaffolding; remember Copilot is a helper and its suggestions often need manual refinement.
Comparing frameworks (pros/cons) You may compare frameworks quickly to select the right fit. Below is a concise comparison of common choices:
A dark-themed screenshot of a text/document editor showing bulleted lists comparing "Flask" pros and cons and "Django REST Framework (with Django) Pros," with a visible mouse cursor and a terminal/sidebar on the left.
Project structure (one practical layout for FastAPI)
A minimal main.py to run the FastAPI app
Connecting to SQLite with SQLAlchemy
  • Use SQLAlchemy to manage the database engine, sessions, and models.
  • For SQLite, set check_same_thread=False when reusing the engine across threads (typical when using uvicorn in dev).
Example database.py (db layer):
Designing the endpoint and request model
  • We’ll accept a POST request that includes a small Pydantic model describing the fake-data request (fields: data_type, count, optional locale).
  • Initially we used simple deterministic generators (no external Faker dependency) to keep the prototype lightweight and reproducible.
Pydantic request model (models/fake_data_request.py):
Router and generators
  • Keep a single router file to control routing for this small project.
  • Implement a few simple generators (name, email, phone) without using Faker for now.
  • Validate data_type against supported generators and return HTTP 400 if unsupported.
Example router (api/endpoints/router.py):
GitHub Copilot can scaffold directories, models, and routes quickly, but expect to refine the output — for example, Copilot suggested integrating Faker; for the prototype we replaced that with simple Python generators to avoid extra dependencies and keep results deterministic during early development.
Running and testing the API
  1. Install dependencies:
    • FastAPI, Uvicorn, SQLAlchemy, Pydantic (and others as needed).
    • Example: pip install fastapi uvicorn sqlalchemy pydantic
  2. Start the app:
Expected server log (example):
Test endpoints with curl, Postman, or the interactive docs at http://localhost:8000/docs. Request validation example
  • If you POST without a body (or with an invalid body), FastAPI/Pydantic will return a 422 Unprocessable Entity with descriptive errors about the missing or invalid fields.
Example request body to generate three names:
Example successful response (HTTP 200):
If you send an unsupported data_type the API returns a 400:
Next steps (recommended)
  • Replace the in-memory generators with DB reads/writes to fakeData.db to return real rows (for example, SELECT random rows or generate variations from DB fields).
  • Create proper output schemas (Pydantic models) for structured person records.
  • Add unit and integration tests for endpoints and services.
  • Expand API docs and examples; FastAPI auto-generates OpenAPI docs at /docs.
  • Optionally reintroduce Faker for richer, localized fake data—pin dependency versions and validate generated values before production use.
Summary This article demonstrated how to import CSV data into SQLite, scaffold a FastAPI service (with Copilot assistance), implement a POST endpoint backed by a Pydantic model, and test a fake-data generator. The next iteration will wire the generator to the fakeData.db and add structured response schemas, tests, and richer generation strategies. Links and references

Watch Video