Python Tutorial 0/52 lessons ~6 min read Lesson 30
Packages & Project Layout
A production Python project uses src/ layout + pyproject.toml — the modern standard since PEP 621.
Course progress0%
Focus
8 guided sections
Practice signal
Examples included
Career prep
Interview Q&A included
Introduction
A production Python project uses src/ layout + pyproject.toml — the modern standard since PEP 621.
Understanding the topic
Core concepts to understand:
pyproject.tomlreplaces setup.py.src/layout prevents import shadowing.tests/mirrors package tree.pip install -e .for editable installs.
Syntax reference
Visual flow / code:
toml
myproj/├── pyproject.toml├── README.md├── src/│ └── myproj/│ ├── __init__.py│ └── core.py└── tests/└── test_core.py# pyproject.toml (excerpt)[project]name = "myproj"version = "0.1.0"dependencies = ["requests>=2.31"]
Execution workflow
1Packages & Project Layout Workflow
1 / 4pyproject.toml replaces setup.py
pyproject.toml replaces setup.py.
Real-world use
src/ layout + pyproject.toml is what Poetry, Hatch, uv, and PyPA recommend. It's the foundation for shipping pip-installable libraries.
Best practices
- Use src/ layout always.
- pyproject.toml + uv/poetry for modern projects.
- Editable install for dev.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1IntermediateQuestionWhy src/ layout?+
Answer
With a
src/ layout, the package is not on sys.path just because you run from the project root. Tests therefore import the installed package, not the working directory copy. This catches missing files or packaging mistakes that a flat layout can hide, and it prevents accidental imports of uninstalled code.Follow-up
How do you run tests against it during development?
2BeginnerQuestionWhat replaces setup.py today?+
Answer
pyproject.toml is the standard place for project metadata (PEP 621) and for declaring the build backend (PEP 517/518), such as setuptools, hatchling, or flit. To be precise, setup.py is not banned and setuptools still supports it, but running it directly (python setup.py install) is deprecated. Builds should go through python -m build or pip.Follow-up
What goes in the
[build-system] table?3IntermediateQuestionEditable install — what does it do?+
Answer
An editable install (
pip install -e .) installs the project's metadata into the environment but points imports at your source directory instead of copying files. Edits to the code take effect without reinstalling. Modern backends implement it through PEP 660, typically with a .pth file or an import hook.Follow-up
When do you still need to reinstall an editable package?
Summary
In summary: src/ + pyproject.toml = modern. Editable installs for active dev.
Ready to mark this lesson complete?Track your journey across the entire course.