- Introduce the project and goals.
- Create a new FastAPI project and implement the application.
- Add inline code documentation and generate API documentation (OpenAPI/Swagger).
- Write unit tests to validate behavior and integrate tests into CI.
- Demonstrate AI pair-programming workflows with GitHub Copilot to accelerate development.
- A FastAPI application that generates realistic mock records on demand.
- Endpoints to request:
- A specific count of records.
- Different output formats: JSON (
application/json), CSV (text/csv), and plain text.
- A
fetch_fake_datafunction that produces synthetic records (Pydantic models recommended). - Unit tests using
pytestand FastAPI’sTestClient. - Automatically generated API docs via FastAPI (OpenAPI/Swagger) and developer docs.
This fake data generator helps you comply with privacy rules by producing realistic but synthetic data for development, QA, and demos without exposing customer information.
- Tech stack: Python, FastAPI, Pydantic for schemas, and a lightweight data generator (e.g., Faker).
- Primary route:
POST /api/v1/getfakedata— accepts JSON body with parameters such ascount,format, andfields. - Response types:
application/json,text/csv, ortext/plain. - Validation: Use Pydantic models to validate request payloads and API responses.
Example request payloads
- Minimal JSON request:
- Request specifying output format and fields:
- Use Pydantic models for both request validation and response schemas to get strong typing and automatic OpenAPI docs.
- Use the Faker library (or a custom generator) to produce realistic but synthetic names, emails, cities, and occupations.
- Return a well-formed CSV with headers when
formatiscsv. For large datasets consider streaming responses. - Add logging and rate-limiting if the service will be exposed across teams.
TestClient and unittest.mock.patch.
- Use
pytestfor unit tests, and include fixtures for sample synthetic data. - Mock out the generator function to control returned data and test edge cases (zero records, invalid fields, unsupported formats).
- Add tests to verify content-type headers for each format and that CSV output contains expected headers.
- Integrate tests into CI (GitHub Actions, GitLab CI, etc.), run formatting (black), linting (flake8/ruff), and tests on every PR.
- Initialize a FastAPI project and repository.
- Define request and response Pydantic models.
- Implement
fetch_fake_data(count, fields=None)using Faker or similar. - Create
/api/v1/getfakedataroute with format handling and proper response headers. - Add unit tests covering success, validation errors, and edge cases.
- Configure OpenAPI docs (auto with FastAPI) and include additional README developer docs.
- Add CI pipeline to run tests and checks; optionally publish a Docker image.
- Scaffold the FastAPI project and routes for generating fake data.
- Implement
fetch_fake_dataso it returns realistic mock records in the requested shape. - Add and run tests like the example above, and integrate them into CI.
- Generate API documentation (OpenAPI/Swagger and additional developer docs).
- Use GitHub Copilot as an AI pair programmer to accelerate implementation, create tests, and write documentation.
- FastAPI: https://fastapi.tiangolo.com/
- Pydantic: https://pydantic-docs.helpmanual.io/
- Faker (Python): https://faker.readthedocs.io/
- GitHub Copilot: https://github.com/features/copilot
- OpenAPI / Swagger Overview: https://swagger.io/specification/