home / skills / athola / claude-night-market / python-packaging

This skill guides Python package creation and distribution using pyproject.toml, entry points, and CI/CD for PyPI publishing.

npx playbooks add skill athola/claude-night-market --skill python-packaging

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

Files (5)
SKILL.md
4.1 KB
---
name: python-packaging
description: 'Consult this skill for Python package creation and distribution. Use
  when creating Python packages, configuring pyproject.toml, setting up entry points,
  publishing to PyPI, CI/CD for packages. Do not use when testing packages - use python-testing
  instead. DO NOT use when: optimizing package performance - use python-performance.'
category: packaging
tags:
- python
- packaging
- pyproject.toml
- uv
- pip
- pypi
- distribution
tools:
- package-analyzer
- build-runner
usage_patterns:
- package-creation
- pypi-publishing
- cli-tool-development
- library-distribution
complexity: beginner
estimated_tokens: 200
progressive_loading: true
modules:
- uv-workflow.md
- pyproject-patterns.md
- entry-points.md
- ci-cd-integration.md
---
## Table of Contents

- [Quick Start](#quick-start)
- [When to Use](#when-to-use)
- [Core Decisions](#core-decisions)
- [1. Layout Choice](#1-layout-choice)
- [2. Project Structure](#2-project-structure)
- [Detailed Topics](#detailed-topics)
- [Best Practices](#best-practices)
- [Exit Criteria](#exit-criteria)


# Python Packaging

Modern Python packaging with pyproject.toml, uv, and best practices for distribution.

## Quick Start

```bash
# Create new project with uv
uv init my-package
cd my-package

# Add dependencies
uv add requests click

# Build package
uv build

# Publish to PyPI
uv publish
```
**Verification:** Run the command with `--help` flag to verify availability.

## When To Use

- Creating distributable Python libraries
- Building CLI tools
- Publishing to PyPI
- Setting up development environments
- Managing project dependencies

## When NOT To Use

- Testing packages - use python-testing
  instead
- Optimizing package performance - use python-performance
- Testing packages - use python-testing
  instead
- Optimizing package performance - use python-performance

## Core Decisions

### 1. Layout Choice

```yaml
# Source layout (recommended)
src/my_package/
    __init__.py
    module.py

# Flat layout (simple)
my_package/
    __init__.py
    module.py
```
**Verification:** Run the command with `--help` flag to verify availability.

**Source layout benefits:**
- Clear separation of source and tests
- Prevents accidental imports of uninstalled code
- Better for packages with complex structure

### 2. Project Structure

**Minimal Project:**
```
**Verification:** Run `pytest -v` to verify tests pass.
my-project/
├── pyproject.toml
├── README.md
├── src/
│   └── my_package/
│       └── __init__.py
└── tests/
    └── test_init.py
```
**Verification:** Run `pytest -v` to verify tests pass.

**Complete Project:**
```
**Verification:** Run the command with `--help` flag to verify availability.
my-project/
├── pyproject.toml
├── README.md
├── LICENSE
├── .gitignore
├── src/
│   └── my_package/
│       ├── __init__.py
│       ├── cli.py
│       ├── core.py
│       └── utils.py
├── tests/
│   ├── conftest.py
│   └── test_core.py
└── docs/
    └── index.md
```
**Verification:** Run `pytest -v` to verify tests pass.

## Detailed Topics

See modules for detailed information:

- **[uv Workflow](modules/uv-workflow.md)** - Complete uv commands and troubleshooting
- **[pyproject.toml Patterns](modules/pyproject-patterns.md)** - Configuration examples for different package types
- **[Entry Points](modules/entry-points.md)** - Console scripts, GUI scripts, and plugins
- **[CI/CD Integration](modules/ci-cd-integration.md)** - GitHub Actions and automated publishing

## Best Practices

1. **Use source layout** for anything beyond simple packages
2. **Pin direct dependencies** with minimum versions
3. **Use optional dependency groups** for dev/docs/test
4. **Include py.typed** for type hint support
5. **Add detailed README** with usage examples
6. **Use semantic versioning** (MAJOR.MINOR.PATCH)
7. **Test on multiple Python versions** before publishing

## Exit Criteria

- Modern pyproject.toml configuration
- Clear dependency specification
- Proper version management
- Tests included and passing
- Build process reproducible
- Publishing pipeline automated

Overview

This skill helps you create, configure, build, and publish Python packages using modern tooling (pyproject.toml, uv, build/publish workflows). It guides layout decisions, dependency management, entry points, and CI/CD setup to produce reproducible distributions. Use it to move from a project skeleton to a published package on PyPI with clear verification steps.

How this skill works

The skill inspects project layout and pyproject.toml patterns, recommends a source layout for non-trivial packages, and outlines commands for creating, building, and publishing using uv and standard build tools. It provides clear checklists for dependency pinning, entry point configuration, packaging metadata, and automated CI/CD publishing. It also lists verification steps such as running tests and using --help on generated CLIs.

When to use it

  • When creating a distributable Python library or application
  • When adding CLI entry points or plugin-style entry points
  • When preparing a package for PyPI publishing
  • When setting up pyproject.toml and dependency groups
  • When implementing CI/CD to automate builds and releases

Best practices

  • Prefer the src/ source layout to avoid accidental local imports
  • Pin direct dependencies with minimum versions and use extras for dev/test/docs
  • Include py.typed for libraries that expose type hints
  • Follow semantic versioning and keep changelog entries for releases
  • Verify builds and tests (pytest) across supported Python versions before release

Example use cases

  • Initialize a new package with uv, add dependencies, build, and publish to PyPI
  • Convert an existing project to a modern pyproject.toml layout and configure entry points
  • Set up GitHub Actions to run tests, build wheels, and publish on tagged releases
  • Create a CLI tool with console_scripts entry point and provide --help verification
  • Group optional dependencies (dev, test, docs) to keep runtime installs minimal

FAQ

Should I use src/ layout or flat layout?

Use src/ for anything beyond a trivial package; it prevents importing the local source and scales better for complex projects.

How do I verify my package before publishing?

Run tests (pytest -v) across targeted Python versions, build the distribution locally (uv build), and test the installed package including CLI --help and basic import/use cases.