Skip to main content
In this guide, you’ll learn how to build a Fake Data Generator API in Python using GitHub Copilot. By the end, you’ll have a service that produces mock customer records in JSON, CSV, or plain text—perfect for development and testing without exposing real personal data.

Table of Contents


Module Overview

In this module, we will:
  • Initialize a new Python project
  • Implement the Fake Data Generator API using FastAPI
  • Add comprehensive docstrings and inline comments
  • Write unit tests with Pytest
  • Auto-generate interactive API documentation
  • Demonstrate AI pair programming with GitHub Copilot

Project Scenario

A new company policy prohibits using real customer data in test environments. To comply and maintain developer productivity, we’ll build an API service that generates synthetic customer records on demand. Example JSON output:
The image outlines a project to build an API in Python, which will generate fake data in formats like text files or CSV.

Prerequisites

  • Python 3.8+
  • FastAPI
  • Uvicorn or another ASGI server
  • Pytest
  • GitHub Copilot extension enabled in your IDE
Ensure your environment has Python 3.8 or later. Use a virtual environment to isolate dependencies.

Setup and Installation

  1. Create a project directory and initialize Git:
  2. Set up a virtual environment and install dependencies:
  3. Define the project structure:

API Implementation

In app/main.py, set up the FastAPI app and fake data endpoint:
In app/schemas.py, define Pydantic models:
In app/utils.py, use Faker to produce data:

In-Code Documentation

Each function and class includes a clear docstring and Field descriptions. This ensures that generated API docs are populated with useful information.

Unit Testing with Pytest

In tests/test_main.py, add tests for the /api/v1/getfakedata endpoint:
Always mock external dependencies when unit testing to isolate behaviour and improve test reliability.

Generate API Documentation

FastAPI automatically provides interactive docs:
  • Swagger UI: http://localhost:8000/docs
  • Redoc: http://localhost:8000/redoc
Start the server with:

AI Pair Programming

Use GitHub Copilot to accelerate:
  • Generate boilerplate code for models and endpoints
  • Write repetitive test cases
  • Suggest docstrings and type hints
Copilot can turn comments into working code snippets—just review and adjust as needed.
The image shows a digital illustration of two people interacting with a computer interface, alongside a detailed API response example. The text "What We'll Build" is displayed at the top.

References

Feel free to explore and extend this Fake Data Generator API to suit your organization’s testing needs!

Watch Video