home / skills / laurigates / claude-plugins / python-packaging

python-packaging skill

/python-plugin/skills/python-packaging

This skill helps you build and publish Python packages with UV, manage versioning, and publish to PyPI, streamlining wheel and sdist creation.

npx playbooks add skill laurigates/claude-plugins --skill python-packaging

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
4.4 KB
---
model: haiku
created: 2025-12-16
modified: 2026-02-06
reviewed: 2025-12-16
name: python-packaging
description: |
  Build and publish Python packages with uv and modern build tools. Covers uv build,
  uv publish, pyproject.toml, versioning, entry points, and PyPI publishing.
  Use when user mentions building packages, publishing to PyPI, uv build, uv publish,
  package distribution, or Python wheel/sdist creation.
allowed-tools: Bash, Read, Grep, Glob
---

# Python Packaging

Quick reference for building and publishing Python packages with UV and modern build tools.

## When This Skill Applies

- Building Python packages (wheels, sdists)
- Publishing to PyPI or private indexes
- Package versioning
- Build system configuration
- Editable installations

## Quick Reference

### Building Packages

```bash
# Build package
uv build

# Build specific formats
uv build --wheel
uv build --sdist

# Output location: dist/
```

### Publishing

```bash
# Publish to PyPI
uv publish

# With token
uv publish --token $PYPI_TOKEN

# To Test PyPI
uv publish --publish-url https://test.pypi.org/legacy/
```

### Package Structure

```
my-package/
├── pyproject.toml
├── README.md
├── LICENSE
├── src/
│   └── my_package/
│       ├── __init__.py
│       ├── __version__.py
│       └── main.py
└── tests/
```

## pyproject.toml Configuration

```toml
[project]
name = "my-package"
version = "0.1.0"
description = "A great package"
readme = "README.md"
requires-python = ">=3.11"
license = {text = "MIT"}
authors = [
    {name = "Your Name", email = "[email protected]"}
]
keywords = ["python", "package"]
classifiers = [
    "Development Status :: 4 - Beta",
    "Intended Audience :: Developers",
    "Programming Language :: Python :: 3",
    "Programming Language :: Python :: 3.11",
]

dependencies = [
    "requests>=2.31.0",
]

[project.optional-dependencies]
dev = ["pytest", "ruff", "mypy"]

[project.urls]
Homepage = "https://github.com/user/my-package"
Documentation = "https://my-package.readthedocs.io"
Repository = "https://github.com/user/my-package.git"
Issues = "https://github.com/user/my-package/issues"

[project.scripts]
my-cli = "my_package.cli:main"

[build-system]
requires = ["uv_build>=0.9.2,<0.10.0"]
build-backend = "uv_build"
```

## Versioning

```toml
[project]
version = "0.1.0"  # Manual versioning

# Dynamic versioning (from git tags)
dynamic = ["version"]

[tool.uv]
version-provider = "git"
```

## Entry Points

```toml
[project.scripts]
my-cli = "my_package.cli:main"

[project.gui-scripts]
my-gui = "my_package.gui:main"

[project.entry-points."my_plugin"]
plugin1 = "my_package.plugins:plugin1"
```

## Build Backends

### UV Build (default)

```toml
[build-system]
requires = ["uv_build>=0.9.2,<0.10.0"]
build-backend = "uv_build"
```

### Setuptools

```toml
[build-system]
requires = ["setuptools>=68", "wheel"]
build-backend = "setuptools.build_meta"
```

### Hatchling

```toml
[build-system]
requires = ["hatchling>=1.18"]
build-backend = "hatchling.build"
```

## Common Workflows

### Publish to PyPI

```bash
# 1. Build
uv build

# 2. Check built packages
ls dist/

# 3. Publish
uv publish --token $PYPI_TOKEN
```

### Test PyPI First

```bash
# Publish to Test PyPI
uv publish --publish-url https://test.pypi.org/legacy/ \
           --token $TEST_PYPI_TOKEN

# Test installation
pip install --index-url https://test.pypi.org/simple/ my-package
```

## Package Classifiers

Common classifiers:

```toml
classifiers = [
    # Development Status
    "Development Status :: 3 - Alpha",
    "Development Status :: 4 - Beta",
    "Development Status :: 5 - Production/Stable",

    # Audience
    "Intended Audience :: Developers",
    "Intended Audience :: Science/Research",

    # License
    "License :: OSI Approved :: MIT License",

    # Python Versions
    "Programming Language :: Python :: 3",
    "Programming Language :: Python :: 3.11",
    "Programming Language :: Python :: 3.12",

    # Framework
    "Framework :: Django",
    "Framework :: FastAPI",

    # Topic
    "Topic :: Software Development :: Libraries",
    "Topic :: Scientific/Engineering",
]
```

Full list: https://pypi.org/classifiers/

## See Also

- `uv-project-management` - Project setup and dependencies
- `python-development` - Core Python patterns
- `uv-workspaces` - Building workspace packages

## References

- UV build: https://docs.astral.sh/uv/guides/publish/
- PyPI: https://pypi.org/
- Detailed guide: See REFERENCE.md

Overview

This skill teaches building and publishing Python packages using UV and modern build tools. It covers uv build and uv publish commands, pyproject.toml configuration, versioning strategies, entry points, and publishing to PyPI or Test PyPI. The guidance focuses on practical commands, file layout, and common workflows for wheel/sdist creation and distribution.

How this skill works

It inspects the pyproject.toml and project layout to determine build metadata, build formats, and entry points. It uses uv build to produce wheels and sdists in dist/ and uv publish to upload artifacts to PyPI or a specified index, optionally using tokens or a publish URL. It supports static and dynamic versioning (manual version in pyproject or git-provided version) and maps project.scripts / entry-points to CLI and plugin entry points.

When to use it

  • You need to create wheel and sdist artifacts for release.
  • You want to publish a package to PyPI or Test PyPI using CI or locally.
  • You are configuring pyproject.toml: metadata, dependencies, scripts, or build backend.
  • You need dynamic versioning from git tags for continuous releases.
  • You want to add CLI or plugin entry points to expose commands to users.

Best practices

  • Keep source in a src/ layout and include README.md and LICENSE at project root.
  • Declare build-backend and uv_build requirement in [build-system] to use uv build reliably.
  • Test publishes to Test PyPI before pushing to the real index and verify pip install from the test index.
  • Use environment tokens (PYPI_TOKEN) for CI publish steps; never commit credentials to source.
  • Prefer dynamic versioning with git tags for automated releases, or centralize version in a single file for manual control.

Example use cases

  • Build a release locally: run uv build, check dist/, then uv publish --token $PYPI_TOKEN.
  • Publish a pre-release to Test PyPI: uv publish --publish-url https://test.pypi.org/legacy/ --token $TEST_PYPI_TOKEN and verify pip install --index-url.
  • Configure pyproject.toml with [project.scripts] to expose a CLI: my-cli = "my_package.cli:main" and distribute as a console script.
  • Switch build backend: set [build-system] to hatchling or setuptools for compatibility with specific tooling.
  • Enable git-based dynamic versioning: set dynamic = ["version"] and [tool.uv] version-provider = "git" for CI-driven version tags.

FAQ

How do I build only a wheel or only an sdist?

Use uv build --wheel to build wheels only, or uv build --sdist to build source distributions only.

How can I test publishing without affecting PyPI?

Publish to Test PyPI using uv publish --publish-url https://test.pypi.org/legacy/ and a test token, then pip install from the test index to validate installation.