Skip to main content
In this final section we’ll master GitHub Copilot in Action and the core features used to build a simple, production-like tool: a Fake Data Generator API built with FastAPI. In this module we’ll:
  • Provide a concise project introduction and outline goals.
  • Create a new Python project scaffold.
  • Implement a fake data generator service with inline code documentation.
  • Add unit tests to verify behavior.
  • Generate and enhance API documentation (OpenAPI).
  • Demonstrate how AI pair programming (Copilot) can accelerate each step.
What are we going to build? Your organization now prohibits the use of real customer data for testing. To comply, tests and development must rely on synthetic—but realistic—data. The solution here is a small API that generates structured mock data suitable for tests and demos, and that can export results as JSON, plain text, or CSV.
Do not use real customer data for testing. Generate synthetic data that resembles real-world records while preserving privacy.
Key features of the Fake Data Generator API:
  • Generate a configurable number of fake records (names, emails, ages, city, occupation).
  • Export generated data in JSON, CSV, or plain text formats.
  • Provide a clean REST endpoint surface for easy consumption by tests or other services.
  • Include automated unit tests and comprehensive API documentation.
Example output produced by the API:
This API will be implemented with Python and FastAPI (see: Python API Development with FastAPI). It will expose endpoints for generating data and downloading it in multiple formats.
A presentation slide titled "What We'll Build" showing a "Build an API in Python" box with an API icon and the Python logo. Below it are stacked file icons and text indicating generation of fake data (text files/CSV).
API design overview Example request body for generating data:
  • {"count": 2} (wrap JSON in the request when calling the endpoint)
Unit testing We’ll add pytest-based unit tests that patch the data generation function. Here’s a sample test that verifies the POST endpoint returns the expected fake data:
Testing notes:
  • Use fixtures (sample_data) to provide deterministic expected results.
  • Patch the internal data-fetching/generation function to isolate endpoint behavior.
  • Validate status codes, payload shape, and content.
Documentation and discoverability FastAPI automatically generates OpenAPI documentation and interactive UIs at /docs (Swagger UI) and /redoc. To make the API easy for engineering teams to consume:
  • Add detailed Pydantic models with field descriptions.
  • Provide example request/response bodies in endpoint docstrings.
  • Include usage examples for each supported export format (JSON/CSV/text).
Best practice: add small, copy-pasteable examples in your docstrings and OpenAPI examples so other teams can quickly integrate the fake-data generator into CI tests and development workflows.
Next steps (recommended development checklist)
  1. Scaffold the project (virtualenv/poetry, FastAPI, Uvicorn, Faker for realistic data).
  2. Implement endpoints and Pydantic models for strong typing and auto-docs.
  3. Add CSV/text serialization helpers (ensure correct CSV headers and escaping).
  4. Write pytest tests with fixtures and function patching to ensure deterministic outcomes.
  5. Use Copilot as an assistant: generate stubs, create example tests, and refine docstrings.
  6. Publish README with usage examples and link to /docs.
References This completes the planning and overview. The following sections will guide you through scaffolding the project, implementing the generator, writing tests, and publishing documentation — all while demonstrating how Copilot can accelerate each task.

Watch Video