
Quiz
Anatomy of a Project
A shareable Python project usually looks like this:
lantern-tools/
├── pyproject.toml # name, version, dependencies
├── README.md
├── src/
│ └── lantern_tools/ # the importable package
│ ├── __init__.py
│ ├── core.py
│ └── cli.py
└── tests/
└── test_core.py
pyproject.tomlis the project's ID card. It holds the name and version, which Python versions it supports, its dependencies, and how to build it.- The distribution name (
lantern-tools, used withpip install) can contain hyphens. The import name (lantern_tools, used withimport) must be a valid identifier, so it uses underscores. __init__.pyturns a folder into a regular package and runs when the package is imported.tests/sits outside the package, so tests don't get shipped to users.
Why src/?
Python always looks for imports in the current folder first. With the
package tucked inside src/, import lantern_tools only works once
you've installed the project (for example with pip install -e .).
That way your tests check the code exactly as users will get it.