Python Project Folder Structure: Best Practices Guide

Jun 10, 2026
42 min read

AI Insights

Powered by GPT-4o-mini

Verified Context: python-project-folder-structure-best-practices-guide
Quick Answer

Learn how to organize Python projects with clean folders, .venv, src, tests, data, README, requirements.txt, pyproject.toml, .gitignore, and Git.

Quick Summary

Learn how to organize your Python project folder with best practices for files, folders, venv, and Git to enhance productivity.

Python Project Folder Structure: Files, Folders, venv, src, tests, data, and Git

Quick Answer

A good Python project keeps code, data, tests, docs, and environment files in predictable places.

Beginner rule:

text
project/
  README.md
  requirements.txt
  .gitignore
  src/
  data/
  tests/
  .venv/

Commit your code. Do not commit .venv.

Last verified: June 9, 2026.

What You Will Learn

By the end, you should be able to:

  • create a clean project folder
  • know where code, data, notebooks, and tests go
  • choose between requirements.txt and pyproject.toml
  • write a basic README
  • protect secrets with .gitignore
  • avoid messy beginner layouts

1. Small Practice Script Structure

For one tiny script:

text
python-practice/
  hello.py

This is fine for day one.

Once you use packages, data files, notebooks, or tests, use a real structure.

text
learning-analysis/
  README.md
  requirements.txt
  .gitignore
  src/
    analyze.py
  data/
    sample.csv
  tests/
    test_analyze.py
  .venv/

Meaning:

ItemPurposeCommit?
README.mdexplains the projectyes
requirements.txtpackage listyes
.gitignoreignored files listyes
src/Python codeyes
data/small safe data filesmaybe
tests/test filesyes
.venv/local environmentno

3. Data Science Project Structure

text
pandas-project/
  README.md
  requirements.txt
  notebooks/
    exploration.ipynb
  src/
    clean_data.py
    build_features.py
  data/
    raw/
      learners.csv
    processed/
      learner_features.csv
  reports/
    summary.md
  tests/
    test_clean_data.py
  .gitignore
  .venv/

Use this when you have CSV files, notebooks, charts, and reusable cleaning code.

4. App Or CLI Project Structure

text
content-review-cli/
  README.md
  pyproject.toml
  src/
    content_review/
      __init__.py
      app.py
      models.py
  tests/
    test_app.py
  .gitignore
  .venv/

This structure is better for larger apps and importable modules.

5. Notebook-Friendly Project Structure

text
notebook-project/
  README.md
  requirements.txt
  notebooks/
    analysis.ipynb
  src/
    helpers.py
  data/
    input.csv
  outputs/
    chart.png
  .gitignore
  .venv/

Keep notebooks in notebooks/. Move reusable code to src/.

6. What README.md Should Include

README.md explains the project.

Minimum useful README:

markdown
# Learning Analysis

## Goal
Analyze learner activity from a CSV file.

## Setup
python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt

## Run
python src/analyze.py

For Windows, include PowerShell setup too:

markdown
py -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt

7. What .gitignore Should Include

Beginner .gitignore:

gitignore
.venv/
__pycache__/
*.pyc
.env
.DS_Store
.ipynb_checkpoints/

Use .env for secrets locally, but never commit it.

Example .env:

text
API_KEY=do-not-commit-this

8. requirements.txt vs pyproject.toml

Use requirements.txt for simple learning projects:

text
pandas==2.3.0
matplotlib==3.10.0

Install:

bash
python -m pip install -r requirements.txt

Use pyproject.toml for modern project tooling, especially with uv:

bash
uv init my-project
uv add pandas matplotlib

Beginner rule:

  • use requirements.txt for simple posts and exercises
  • use pyproject.toml for uv or package-style projects

9. Where Data Files Should Go

Small safe files:

text
data/sample.csv

Larger data projects:

text
data/raw/
data/processed/

Do not commit private, paid, or sensitive data.

In code, use relative paths:

python
import pandas as pd

df = pd.read_csv("data/sample.csv")

10. Where Tests Should Go

Use:

text
tests/
  test_clean_data.py

Tests help catch mistakes after edits.

Simple test:

python
def test_total():
    assert 2 + 3 == 5

11. Git Basics

Install Git from:

text
https://git-scm.com/downloads

Common workflow:

bash
git init
git status
git add README.md src tests requirements.txt .gitignore
git commit -m "Initial project structure"

Before git add ., make sure .venv/ and .env are ignored.

12. Bad Folder Structure

Avoid:

text
Desktop/
  final.py
  final2.py
  final_new.py
  chart latest.png
  data copy.csv
  passwords.txt

This becomes confusing very quickly.

13. Good Folder Structure

Prefer:

text
analysis-project/
  README.md
  src/
    analyze.py
  data/
    learners.csv
  tests/
    test_analyze.py
  requirements.txt
  .gitignore

FAQ

Should .venv be inside or outside the project?

Inside the project is easiest for beginners. Just add .venv/ to .gitignore.

Should data files be committed?

Small original practice CSV files are fine. Private, huge, paid, or sensitive data should not be committed.

Should notebooks go in src/?

No. Put notebooks in notebooks/ and reusable Python code in src/.

Do I need tests as a beginner?

For tiny scripts, not always. For projects, yes. Even simple tests improve confidence.

Final Checklist

Your project folder should have:

text
README.md
requirements.txt or pyproject.toml
.gitignore
src/
data/ if needed
tests/ if it is a project
.venv/ ignored by Git

Windows setup command:

powershell
py -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt

macOS setup command:

bash
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt

Good structure reduces confusion before it starts.


Next in this series: Resolving Common Python Setup Errors: A Comprehensive Guide →

Frequently Asked Questions

What is the purpose of the README.md file in a Python project?
The README.md file explains the project and should include the project's goal, setup instructions, and how to run the project.
Should the .venv directory be committed to version control?
No, the .venv directory, which contains the local environment, should not be committed to version control.
What should be included in a beginner's .gitignore file?
A beginner's .gitignore file should include .venv/, __pycache__/, .pyc, .env, .DS_Store, and .ipynb_checkpoints/ to prevent committing unnecessary or sensitive files.
When should you use a pyproject.toml file instead of a requirements.txt file?
A pyproject.toml file is recommended for larger apps and importable modules, as seen in the app or CLI project structure.

Related Work

See how this thinking shows up in shipped systems.