Why Python projects use a src directory
I recently started building a small Python tool to convert some markdown files. I noticed that modern Python project generators (like those based on uv) default to putting all the code inside a src/ directory.
I’m not an expert on Python packaging, and I was questioning why we need this hierarchy for a simple script that will never be published to PyPI.
After some digging, I found that the src/ directory layout is a widely accepted convention because it enforces clean isolation. It prevents Python from accidentally importing local code instead of the installed package during testing. Even though my tool was small, standardizing on the src/ layout (e.g., src/my_app/module) avoids a lot of future headaches as the codebase grows.
It’s one of those things where it’s better to just follow the established ecosystem patterns rather than fighting them. I hope this helps anyone else wondering about Python project structures.