The difference between directory / distribution / package names in python packaging

March 6, 2024

For example:

  • in project A:
# project A
 
# project structure
poetry-demo                  <--- directory name
├── pyproject.toml
├── README.rst
├── poetry_demo              <--- package name
   └── __init__.py
 
# pyproject.toml
[tool.poetry]
name = "poetry-demo"         <--- distribution name (this needs to use hyphens)
version = "0.1.0"
  • in project B:
# project B
 
# pyproject.toml
[tool.poetry.dependencies]
poetry-demo = "0.1.0"        <--- distribution name
 
# installation
pip install poetry-demo      <--- distribution name
 
# usage
import poetry_demo           <--- package name