Python packaging

From kumaran-is/claude-code-onboarding · View interactive version

Python packaging is an AI agent skill from the GitHub repository kumaran-is/claude-code-onboarding. Python project structure patterns — pyproject.toml for services and internal tools, source vs flat layout, CLI entry points with Click/argparse, dynamic versioning, and editable installs. Use when structuring a new Python project or building internal CLI tools.

How to use this skill

Skill file

Iron Law

USE SOURCE LAYOUT (src/) FOR ALL SERVICES AND INSTALLABLE TOOLS — flat layout works for scripts but causes import confusion in larger projects and CI environments

Python Packaging

Project structure patterns for Python 3.14 services, internal tools, and CLI applications.

Scope

This skill covers the workspace-relevant subset of Python packaging:

Out of scope for this workspace: PyPI publishing, wheels, namespace packages, C extensions, private package index. The workspace builds services and internal tools, not distributable libraries.

Layout Decision

New project?
│
├── FastAPI service / internal service
│   └── Source layout: src/<package>/ ← default for all services
│
├── Internal CLI tool (deployment scripts, data tools)
│   └── Source layout with [project.scripts] entry point
│
└── Quick one-off script
    └── Flat layout (single .py file or simple directory)

Reference File

Load resources/implementation-playbook.md for:

Key pyproject.toml Sections

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "my-service"
version = "0.1.0"
requires-python = ">=3.14"
dependencies = [
    "fastapi>=0.135.2",
    "pydantic>=2.0.0",
]

[project.scripts]
my-cli = "my_package.cli:main"  # CLI entry point

[tool.hatch.build.targets.wheel]
packages = ["src/my_package"]

CLI Entry Point Pattern

# src/my_tool/cli.py
import click

@click.group()
def main():
    """Internal deployment tool."""
    pass

@main.command()
@click.argument("environment")
@click.option("--dry-run", is_flag=True)
def deploy(environment: str, dry_run: bool):
    """Deploy to environment."""
    click.echo(f"Deploying to {environment} (dry_run={dry_run})")

if __name__ == "__main__":
    main()

Install and run: uv pip install -e . then my-cli deploy staging --dry-run

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.