Project Structure & Best Practices
Organize professional Python projects with proper directory structure, configuration, documentation, and development tooling.
15 min•By Priygop Team•Updated 2026
Project Structure
Project Structure
# Professional Python project structure:
structure = """
my_project/
├── README.md # Project overview
├── LICENSE # License file
├── pyproject.toml # Modern config (replaces setup.py)
├── requirements.txt # Dependencies
├── .gitignore # Git ignore patterns
├── .env.example # Env var template
├── src/
│ └── my_project/
│ ├── __init__.py # Package init
│ ├── main.py # Entry point
│ ├── config.py # Configuration
│ ├── models/ # Data models
│ │ ├── __init__.py
│ │ └── user.py
│ ├── services/ # Business logic
│ │ ├── __init__.py
│ │ └── auth.py
│ └── utils/ # Utilities
│ ├── __init__.py
│ └── helpers.py
├── tests/
│ ├── __init__.py
│ ├── conftest.py # pytest fixtures
│ ├── test_models.py
│ └── test_services.py
└── docs/
└── architecture.md
"""
print(structure)
# pyproject.toml example
print("=== pyproject.toml ===")
print("""[project]
name = "my-project"
version = "1.0.0"
description = "My Python project"
requires-python = ">=3.10"
dependencies = ["requests>=2.28", "click>=8.0"]
[project.scripts]
my-cli = "my_project.main:cli"
[tool.pytest.ini_options]
testpaths = ["tests"]
[tool.black]
line-length = 88
[tool.ruff]
line-length = 88""")
# Best practices
print("\n=== Best Practices ===")
for bp in [
"Use src/ layout for packages",
"Keep tests in separate tests/ directory",
"Use pyproject.toml over setup.py",
"Include README.md and LICENSE",
"Use .env for secrets (never commit!)",
"Add type hints throughout",
]:
print(f" ✅ {bp}")Tip
Tip
Use Docker for consistent environments. Pin Python version in Dockerfile. Use multi-stage builds for smaller images.
Diagram
Loading diagram…
Always use virtual environments. pip freeze > requirements.txt. Use pyproject.toml (modern).
Common Mistake
Warning
Deploying without environment variables for configuration. Never hardcode database URLs, API keys, or secrets.
Quick Quiz
Practice Task
Note
(1) Write a Dockerfile for your Python app. (2) Create a docker-compose.yml. (3) Deploy to a cloud platform.