Project layout and pyproject.toml
Project layout and pyproject.toml
A Python project has two layout problems. The first is imports: from relay.tickets import Ticket has to find relay, and where Python looks depends on the current directory, which is why a test suite that passes from the project root fails from one level down. The second is configuration: pytest, ruff, mypy and the build tool each want settings, and a project that scatters them across five dotfiles is one nobody wants to maintain.
Both have a standard answer now. Put the package in a src/ directory and install it into the environment, so imports resolve the same way everywhere. And put all configuration in pyproject.toml, which every modern tool reads, so there is one file to open.
Continue reading
Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.