A package is a folder with __init__.py. Imports look like kioskpkg.prices. Use a package when one module is no longer enough.
Goal
Create kioskpkg/, import kioskpkg.prices, and print a total.
A tiny package
from pathlib import Path
root = Path("kioskpkg")
root.mkdir(exist_ok=True)
(root / "__init__.py").write_text(
'"""Nairobi kiosk package."""\n',
encoding="utf-8",
)
(root / "prices.py").write_text(
'''TAX = 0.16
def line_total(units, price):
return round(units * price * (1 + TAX), 2)
''',
encoding="utf-8",
)
from kioskpkg.prices import line_total
print(line_total(3, 10.5))
print("pkg file:", Path("kioskpkg/prices.py").exists())Re-export from __init__.py
from pathlib import Path
root = Path("kioskpkg")
root.mkdir(exist_ok=True)
(root / "prices.py").write_text(
'''def city_label(city):
return str(city or "").strip().title()
''',
encoding="utf-8",
)
(root / "__init__.py").write_text(
"from kioskpkg.prices import city_label\n",
encoding="utf-8",
)
import kioskpkg
print(kioskpkg.city_label("mombasa"))Callers can import kioskpkg and use city_label without knowing the inner module.
Tip
Keep the folder name a valid identifier: kioskpkg, not kiosk-pkg.