src layout vs flat layout in Python projects

python
Author

Lawrence Wu

Published

March 18, 2025

I haven’t seen these terms “src layout” and “flat layout” before when referring to Python project conventions that put source code in either a top level folder that is the package name or nesting it under a src/ folder. This article provides a lot of detail and actually some reasons why a src/ layout is probably better. Also reading this Overview of Python Packaging was very informative too.

Quoting the article:

The “flat layout” refers to organising a project’s files in a folder or repository, such that the various configuration files and import packages are all in the top-level directory.

.
├── README.md
├── noxfile.py
├── pyproject.toml
├── setup.py
├── awesome_package/
│   ├── __init__.py
│   └── module.py
└── tools/
    ├── generate_awesomeness.py
    └── decrease_world_suck.py

The “src layout” deviates from the flat layout by moving the code that is intended to be importable (i.e. import awesome_package, also known as import packages) into a subdirectory. This subdirectory is typically named src/, hence “src layout”.

.
├── README.md
├── noxfile.py
├── pyproject.toml
├── setup.py
├── src/
│    └── awesome_package/
│       ├── __init__.py
│       └── module.py
└── tools/
    ├── generate_awesomeness.py
    └── decrease_world_suck.py

Here’s a breakdown of the important behaviour differences between the src layout and the flat layout: