Skip to main content
In this guide you’ll create a small Python project that generates fake CSV data by querying a local Ollama model. The lesson covers:
  • Creating a project folder and a Python virtual environment
  • Scaffolding a minimal application and organizing code into modules
  • Adding a utility that calls a local Ollama server to produce CSV-formatted fake data
  • Capturing dependencies in requirements.txt
  • Creating a .gitignore to keep the repo clean
This walkthrough is optimized for clarity and searchability with actionable commands, code examples, and links to relevant tools and docs. Overview of steps:
  • Create project folder and virtual environment
  • Scaffold main.py and a FakeDataGenerator class
  • Move the class to fake_data_generator.py and import it from main.py
  • Add create_fake_data.py to call a local Ollama server and save CSV
  • Install dependencies and produce requirements.txt
  • Create a .gitignore to exclude the virtual environment and other artifacts
References:

Quick file summary


1) Create the project folder and virtual environment

Create the project folder, open it in your editor (e.g., VS Code), and create a Python virtual environment. Example CLI commands:
Activate the virtual environment:
  • macOS / Linux:
  • Windows (PowerShell):
When activated your prompt will indicate the venv, for example:
Use python3 -m venv .venv to create a portable local environment. Always activate it before installing project dependencies so packages are isolated to this project.

2) Scaffold a minimal application

Start with a simple main.py that defines a FakeDataGenerator class and runs when executed. This keeps the initial project minimal and testable. main.py:
Run it to verify:

3) Move the generator into its own module

As projects grow, keeping classes and functions in focused modules improves maintainability. Move FakeDataGenerator into fake_data_generator.py and import it from main.py. fake_data_generator.py:
Update main.py to import the class:
Run again to confirm behavior remains the same:

4) Add a utility to request fake data from a local Ollama model

Create create_fake_data.py. It sends a prompt to an Ollama server running locally at http://localhost:11434/api/generate, asks for CSV-formatted fake data, and saves the returned raw CSV text to fake_data.csv. create_fake_data.py:
Ollama’s JSON schema can change across versions. If the server returns fields like output or nested objects, inspect the raw JSON and update the key access accordingly before writing to disk.
Install requests in the virtual environment:
Run the script:
Sample generated CSV (example):

5) Track project dependencies with requirements.txt

After installing project packages (for example, requests), capture them in requirements.txt so collaborators can recreate your environment. Example:
Recreate the environment from requirements.txt:

6) Create a robust .gitignore

Exclude the virtual environment directory and other generated artifacts from Git. Below is a practical .gitignore example to keep your repository clean.
A dark-themed code editor/chat screenshot showing a user asking how to keep git from seeing a .venv folder. GitHub Copilot is generating a reply that suggests creating a .gitignore file to exclude the virtual environment.
Example .gitignore (partial):
If your .venv was already committed, remove it from tracking:
Then add and commit the .gitignore:

Summary

  • Created a new Python project with an isolated virtual environment.
  • Scaffoled a minimal FakeDataGenerator and moved it into a dedicated module.
  • Built create_fake_data.py to call a local Ollama model and save CSV-formatted fake data.
  • Captured dependencies in requirements.txt and protected the repo with .gitignore.
  • This example demonstrates how GitHub Copilot can accelerate boilerplate creation; future articles will show importing generated data into a database and using it for more advanced workflows.

Watch Video