Manuals / Python / Ch 11

E · ShipIntermediate40 min read

11. Packaging lite — pyproject.toml & entry points

Python · 52 pages source format

You do not need to publish to PyPI yet. pyproject.toml declares project metadata and dependencies. pip install -e . makes your package importable. Entry points turn modules into CLI commands.

What you'll learn

  • pyproject.toml basics
  • pip install -e .
  • Console scripts entry points
  • src layout packaging

Minimal pyproject.toml

PEP 621 project table: name, version, dependencies. Build backend can be hatchling or setuptools — keep it minimal.

[project]
name = "py-journey"
version = "0.1.0"
dependencies = ["httpx>=0.27", "pytest>=8.0"]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

Do this now

Add pyproject.toml to py-journey with project name, version 0.1.0, dependencies from requirements.txt.

Clear?

Editable install

pip install -e . installs package in development mode — imports work without PYTHONPATH hacks.

Do this now

Run pip install -e . in venv. Import from helpers without sys.path manipulation.

Pro tip. Playwright frameworks use this pattern — src/ package + editable install in CI.

Clear?

CLI entry point

[project.scripts] health-check = "py_journey.health_check:main" maps command to function.

[project.scripts]
health-check = "py_journey.health_check:main"

Do this now

Wire health_check CLI as console script. Run health-check --help after install.

Clear?

What you are not doing yet

No PyPI publish, no complex monorepos, no poetry vs pip debate. Just enough structure to share a tool across repos.

Do this now

Document in README: how to clone, venv, pip install -e ., run tests.

Clear?

Checklist