Packaging and publishing
A Python package is described by a pyproject.toml file: name, version, dependencies and how to build it. uv build turns your project into a wheel (.whl) that anyone can install with pip install, and uv publish uploads it to PyPI. Entry points let users run your tool as a normal command.
Project layout
slugkit/
├── pyproject.toml
├── README.md
├── src/
│ └── slugkit/
│ ├── __init__.py
│ └── core.py
└── tests/
└── test_core.pyimport re
def slugify(text: str) -> str:
"""Turn any title into a URL-friendly slug."""
text = re.sub(r"[^a-z0-9]+", "-", text.lower())
return text.strip("-")
def main() -> None:
import sys
print(slugify(" ".join(sys.argv[1:])))from slugkit.core import slugify
__all__ = ["slugify"]
__version__ = "0.1.0"pyproject.toml
[project]
name = "slugkit"
version = "0.1.0"
description = "Turn titles into URL slugs"
readme = "README.md"
requires-python = ">=3.10"
authors = [{ name = "Your Name", email = "you@example.com" }]
license = "MIT"
dependencies = []
[project.scripts]
slugkit = "slugkit.core:main"
[dependency-groups]
dev = ["pytest>=8"]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"[project]holds the metadata PyPI shows: name, version, description, Python versions.dependencieslists what users need installed; keep version ranges loose for libraries.[project.scripts]creates aslugkitcommand that runsmain().[dependency-groups]holds tools only you need while developing, like pytest.[build-system]says which tool builds the package; Hatchling is a common default.
Try it locally
$ uv sync # create .venv and install the project
$ uv run slugkit "Hello, Python World!"
hello-python-world
$ uv run pytest -q
. [100%]
1 passedBuild and publish
$ uv build
Building source distribution...
Building wheel from source distribution...
Successfully built dist/slugkit-0.1.0.tar.gz
Successfully built dist/slugkit-0.1.0-py3-none-any.whl
$ uv publish --publish-url https://test.pypi.org/legacy/ # practise on TestPyPI first
$ uv publish # the real PyPIVersions
Most packages use semantic versioning, MAJOR.MINOR.PATCH: bump PATCH for bug fixes, MINOR for new features that don't break anything, and MAJOR for breaking changes. A version can never be re-uploaded to PyPI, so every release needs a new number.
Practice
Package tools compare versions as numbers, not text. Write parse_version(v: str) -> tuple[int, ...] that turns "3.15.0" into (3, 15, 0). Then print "3.9.1" < "3.15.0" as plain strings, the same comparison with your function, and the newest of ["0.9.0", "0.10.2", "0.10.10"] using max(..., key=parse_version).
False True 0.10.10