Project layout: src layout, tests, config separation, and clear package boundaries
A maintainable layout separates source code, tests, configuration, and documentation. The src layout (src/mypkg/) prevents accidental imports from the working directory and forces installation for testing. Tests live in a separate tests/ directory, ideally mirroring the package structure. Configuration is in pyproject.toml, with environment-specific config in environment variables or a config module. Documentation goes in docs/, and scripts in scripts/ or bin/. The goal is that a new developer can find things quickly and that imports behave the same in development and production.
src layout: src/mypkg/ keeps the package isolated and avoids path issues.
tests/ directory with unit, integration, and e2e subfolders as needed.
pyproject.toml for build system, dependencies, and tool config.
README, LICENSE, and docs/ for documentation.
Separate configuration from code: use environment variables or a config module, not hardcoded values.
Common mistake: putting tests inside the package, which ships tests to users.
Common mistake: flat layout with modules in the root, which causes import shadowing and path confusion.
Version note: src layout is recommended by PyPA and most modern tools. It is not version-specific.
0-2 years experience
2-5 years experience
5-8 years experience
8+ years experience