Build, test, type-check, version, package, and publish production Python libraries to PyPI. Use this skill when creating a pip-installable SDK, CLI, plugin, or utility; choosing `src/` vs flat layout; selecting setuptools, hatchling, flit, or poetry; configuring pyproject.toml, py.typed, Ruff, mypy, pre-commit, GitHub Actions, TestPyPI, Trusted Publishing, setuptools_scm, PEP 440, SemVer, or release governance.
Take a battle-tested, community-ready, end-to-end (to-end) Python library, SDK, CLI, plugin, or utility request, transform it into a modern PyPA package with structure, backend, versioning, typing, quality, CI, and publishing decisions, and output the files and release steps needed for a production-grade PyPI release.
Follow the decision trees in order before writing code. This skill applies to utility libraries, SDKs, CLI tools, framework plugins, and data libraries.
When to invoke
"Create a Python package I can publish to PyPI."
"Build a pip-installable SDK with pyproject.toml."
"Choose setuptools_scm, hatchling, flit, or poetry for this library."
"Set up py.typed, Ruff, mypy, pre-commit, and GitHub Actions."
"Publish this package with Trusted Publishing or TestPyPI."
Scaffold script: run python skills/python-pypi-package-builder/scripts/scaffold.py --name your-package-name
to generate the entire directory layout, stub files, and pyproject.toml in one command.
Trigger details
Load this skill whenever the user wants to:
Create, scaffold, or publish a Python package or library to PyPI
Build a pip-installable SDK, utility, CLI tool, or framework extension
Set up pyproject.toml, linting, mypy, pre-commit, or GitHub Actions for a Python project
Understand versioning (setuptools_scm, PEP 440, semver, static versioning)
Publish to PyPI using Trusted Publishing (OIDC) or API tokens
Refactor an existing package to follow modern Python packaging standards
Add type hints, protocols, ABCs, or dataclasses to a Python library
Apply OOP/SOLID design patterns to a Python package
Choose between build backends (setuptools, hatchling, flit, poetry)
Also trigger for phrases like: "build a Python SDK", "publish my library", "set up PyPI CI",
"create a pip package", "how do I publish to PyPI", "pyproject.toml help", "PEP 561 typed",
"setuptools_scm version", "semver Python", "PEP 440", "git tag release", "Trusted Publishing".
Package type decision
Identify what the user is building before writing any code. Each type has distinct patterns.
Decision Table
Type
Core Pattern
Entry Point
Key Deps
Example Packages
Utility library
Module of pure functions + helpers
Import API only
Minimal
arrow, humanize, boltons, more-itertools
API client / SDK
Class with methods, auth, retry logic
Import API only
httpx or requests
boto3, stripe-python, openai
CLI tool
Command functions + argument parser
[project.scripts] or [project.entry-points]
click or typer
black, ruff, httpie, rich
Framework plugin
Plugin class, hook registration
[project.entry-points."framework.plugin"]
Framework dep
pytest-*, django-*, flask-*
Data processing library
Classes + functional pipeline
Import API only
Optional: numpy, pandas
pydantic, marshmallow, cerberus
Mixed / generic
Combination of above
Varies
Varies
Many real-world packages
Decision Rule: Ask the user if unclear. A package can combine types (e.g., SDK with a CLI
entry point) — use the primary type for structural decisions and add secondary type patterns on top.
For implementation patterns of each type, see references/library-patterns.md.
Package Naming Rules
PyPI name: all lowercase, hyphens — my-python-library
Avoid shadowing popular packages (verify pip install <name> fails first)
Folder structure decision
Decision Tree
Does the package have 5+ internal modules OR multiple contributors OR complex sub-packages?
├── YES → Use src/ layout
│ Reason: prevents accidental import of uninstalled code during development;
│ separates source from project root files; PyPA-recommended for large projects.
│
├── NO → Is it a single-module, focused package (e.g., one file + helpers)?
│ ├── YES → Use flat layout
│ └── NO (medium complexity) → Use flat layout, migrate to src/ if it grows
│
└── Is it multiple related packages under one namespace (e.g., myorg.http, myorg.db)?
└── YES → Use namespace/monorepo layout
Quick Rule Summary
Situation
Use
New project, unknown future size
src/ layout (safest default)
Single-purpose, 1–4 modules
Flat layout
Large library, many contributors
src/ layout
Multiple packages in one repo
Namespace / monorepo
Migrating old flat project
Keep flat; migrate to src/ at next major version
Build backend decision
Decision Tree
Does the user need version derived automatically from git tags?
├── YES → Use setuptools + setuptools_scm
│ (git tag v1.0.0 → that IS your release workflow)
│
└── NO → Does the user want an all-in-one tool (deps + build + publish)?
├── YES → Use poetry (v2+ supports standard [project] table)
│
└── NO → Is the package pure Python with no C extensions?
├── YES, minimal config preferred → Use flit
│ (zero config, auto-discovers version from __version__)
│
└── YES, modern & fast preferred → Use hatchling
(zero-config, plugin system, no setup.py needed)
Does the package have C/Cython/Fortran extensions?
└── YES → MUST use setuptools (only backend with full native extension support)
Backend Comparison
Backend
Version source
Config
C extensions
Best for
setuptools + setuptools_scm
git tags (automatic)
pyproject.toml + optional setup.py shim
Yes
Projects with git-tag releases; any complexity
hatchling
manual or plugin
pyproject.toml only
No
New pure-Python projects; fast, modern
flit
__version__ in __init__.py
pyproject.toml only
No
Very simple, single-module packages
poetry
pyproject.toml field
pyproject.toml only
No
Teams wanting integrated dep management
For all four complete pyproject.toml templates, see references/pyproject-toml.md.
PyPA packaging flow
This is the canonical end-to-end flow from source code to user install.
Every step must be understood before publishing.
1. SOURCE TREE
Your code in version control (git)
└── pyproject.toml describes metadata + build system
2. BUILD
python -m build
└── Produces two artifacts in dist/:
├── *.tar.gz → source distribution (sdist)
└── *.whl → built distribution (wheel) — preferred by pip
3. VALIDATE
twine check dist/*
└── Checks metadata, README rendering, and PyPI compatibility
4. TEST PUBLISH (first release only)
twine upload --repository testpypi dist/*
└── Verify: pip install --index-url https://test.pypi.org/simple/ your-package
5. PUBLISH
twine upload dist/* ← manual fallback
OR GitHub Actions publish.yml ← recommended (Trusted Publishing / OIDC)
6. USER INSTALL
pip install your-package
pip install "your-package[extra]"
Key PyPA Concepts
Concept
What it means
sdist
Source distribution — your source + metadata; used when no wheel is available
wheel (.whl)
Pre-built binary — pip extracts directly into site-packages; no build step
PEP 517/518
Standard build system interface via pyproject.toml [build-system] table
PEP 621
Standard [project] table in pyproject.toml; all modern backends support it
PEP 639
license key as SPDX string (e.g., "MIT", "Apache-2.0") — not {text = "MIT"}
PEP 561
py.typed empty marker file — tells mypy/IDEs this package ships type information
For complete CI workflow and publishing setup, see references/ci-publishing.md.
Project structure templates
A. src/ Layout (Recommended default for new projects)
Each sub-package has its own pyproject.toml. They share the your_org namespace via PEP 420
implicit namespace packages (no __init__.py in the namespace root).
MAJOR.MINOR.PATCH
MAJOR: Breaking API change (remove/rename public function/class/arg)
MINOR: New feature, fully backward-compatible
PATCH: Bug fix, no API change
Dynamic versioning with setuptools_scm (recommended for git-tag workflows)
# How it works:
git tag v1.0.0 → installed version = 1.0.0
git tag v1.1.0 → installed version = 1.1.0
(commits after tag) → version = 1.1.0.post1 (suffix stripped for PyPI)
# In code — NEVER hardcode when using setuptools_scm:
from importlib.metadata import version, PackageNotFoundError
try:
__version__ = version("your-package")
except PackageNotFoundError:
__version__ = "0.0.0-dev" # Fallback for uninstalled dev checkouts
Critical: always set fetch-depth: 0 in every CI checkout step. Without full git history,
setuptools_scm cannot find tags and the build version silently falls back to 0.0.0+dev.
# your_package/__init__.py
__version__ = "1.0.0" # Update this before every release
Version specifier best practices for dependencies
# In [project] dependencies:
"httpx>=0.24" # Minimum version — PREFERRED for libraries
"httpx>=0.24,<1.0" # Upper bound only when a known breaking change exists
"httpx==0.27.0" # Pin exactly ONLY in applications, NOT libraries
# NEVER do this in a library — it breaks dependency resolution for users:
# "httpx~=0.24.0" # Too tight
# "httpx==0.27.*" # Fragile
Version bump → release flow
# 1. Update CHANGELOG.md — move [Unreleased] entries to [x.y.z] - YYYY-MM-DD
# 2. Commit the changelog
git add CHANGELOG.md
git commit -m "chore: prepare release vX.Y.Z"
# 3. Tag and push — this triggers publish.yml automatically
git tag vX.Y.Z
git push origin main --tags
# 4. Monitor GitHub Actions → verify on https://pypi.org/project/your-package/
For complete pyproject.toml templates for all four backends, see references/pyproject-toml.md.
Progressive disclosure and bundled resources
After understanding decisions and structure:
Set up pyproject.toml → references/pyproject-toml.md
All four backend templates (setuptools+scm, hatchling, flit, poetry), full tool configs,
py.typed setup, versioning config.
Write your library code → references/library-patterns.md
OOP/SOLID principles, type hints (PEP 484/526/544/561), core class design, factory functions,
__init__.py, plugin/backend pattern, CLI entry point.
Set up CI/CD and publish → references/ci-publishing.mdci.yml, publish.yml with Trusted Publishing (OIDC, no API tokens), CHANGELOG format,
release checklist.
Polish for community/OSS → references/community-docs.md
README sections, docstring format, CONTRIBUTING, SECURITY, issue templates, anti-patterns
table, and master release checklist.
Design backends, config, transport, CLI → references/architecture-patterns.md
Backend system (plugin/strategy pattern), Settings dataclass, HTTP transport layer,
CLI with click/typer, backend injection rules.
Choose and implement a versioning strategy → references/versioning-strategy.md
PEP 440 canonical forms, SemVer rules, pre-release identifiers, setuptools_scm deep-dive,
flit static versioning, decision engine (DEFAULT/BEGINNER/MINIMAL).
Govern releases and secure the publish pipeline → references/release-governance.md
Branch strategy, branch protection rules, OIDC Trusted Publishing setup, tag author
validation in CI, tag format enforcement, full governed publish.yml.
1---2name: python-pypi-package-builder-23description: Build, test, type-check, version, package, and publish production Python libraries to PyPI. Use this skill when creating a pip-installable SDK, CLI, plugin, or utility; choosing `src/` vs flat layout; selecting setuptools, hatchling, flit, or poetry; configuring pyproject.toml, py.typed, Ruff, mypy, pre-commit, GitHub Actions, TestPyPI, Trusted Publishing, setuptools_scm, PEP 440, SemVer, or release governance.4---56# Python PyPI package builder78Take a battle-tested, community-ready, end-to-end (`to-end`) Python library, SDK, CLI, plugin, or utility request, transform it into a modern PyPA package with structure, backend, versioning, typing, quality, CI, and publishing decisions, and output the files and release steps needed for a production-grade PyPI release.910Follow the decision trees in order before writing code. This skill applies to utility libraries, SDKs, CLI tools, framework plugins, and data libraries.1112## When to invoke1314- "Create a Python package I can publish to PyPI."15- "Build a pip-installable SDK with pyproject.toml."16- "Choose setuptools_scm, hatchling, flit, or poetry for this library."17- "Set up py.typed, Ruff, mypy, pre-commit, and GitHub Actions."18- "Publish this package with Trusted Publishing or TestPyPI."1920## Decision map2122| Section in this file | What it covers |23|---|---|24| [1. Skill Trigger](#1-skill-trigger) | When to load this skill |25| [2. Package Type Decision](#2-package-type-decision) | Identify what you are building |26| [3. Folder Structure Decision](#3-folder-structure-decision) | src/ vs flat vs monorepo |27| [4. Build Backend Decision](#4-build-backend-decision) | setuptools / hatchling / flit / poetry |28| [5. PyPA Packaging Flow](#5-pypa-packaging-flow) | The canonical publish pipeline |29| [6. Project Structure Templates](#6-project-structure-templates) | Full layouts for every option |30| [7. Versioning Strategy](#7-versioning-strategy) | PEP 440, semver, dynamic vs static |3132| Reference file | What it covers |33|---|---|34| `references/pyproject-toml.md` | All four backend templates, `setuptools_scm`, `py.typed`, tool configs |35| `references/library-patterns.md` | OOP/SOLID, type hints, core class design, factory, protocols, CLI |36| `references/testing-quality.md` | `conftest.py`, unit/backend/async tests, ruff/mypy/pre-commit |37| `references/ci-publishing.md` | `ci.yml`, `publish.yml`, Trusted Publishing, TestPyPI, CHANGELOG, release checklist |38| `references/community-docs.md` | README, docstrings, CONTRIBUTING, SECURITY, anti-patterns, master checklist |39| `references/architecture-patterns.md` | Backend system (plugin/strategy), config layer, transport layer, CLI, backend injection |40| `references/versioning-strategy.md` | PEP 440, SemVer, pre-release, setuptools_scm deep-dive, flit static, decision engine |41| `references/release-governance.md` | Branch strategy, branch protection, OIDC, tag author validation, prevent invalid tags |42| `references/tooling-ruff.md` | Ruff-only setup (replaces black/isort), mypy config, pre-commit, asyncio_mode=auto |4344**Scaffold script:** run `python skills/python-pypi-package-builder/scripts/scaffold.py --name your-package-name`45to generate the entire directory layout, stub files, and `pyproject.toml` in one command.4647---4849## Trigger details5051Load this skill whenever the user wants to:5253- Create, scaffold, or publish a Python package or library to PyPI54- Build a pip-installable SDK, utility, CLI tool, or framework extension55- Set up `pyproject.toml`, linting, mypy, pre-commit, or GitHub Actions for a Python project56- Understand versioning (`setuptools_scm`, PEP 440, semver, static versioning)57- Understand PyPA specs: `py.typed`, `MANIFEST.in`, `RECORD`, classifiers58- Publish to PyPI using Trusted Publishing (OIDC) or API tokens59- Refactor an existing package to follow modern Python packaging standards60- Add type hints, protocols, ABCs, or dataclasses to a Python library61- Apply OOP/SOLID design patterns to a Python package62- Choose between build backends (setuptools, hatchling, flit, poetry)6364**Also trigger for phrases like:** "build a Python SDK", "publish my library", "set up PyPI CI",65"create a pip package", "how do I publish to PyPI", "pyproject.toml help", "PEP 561 typed",66"setuptools_scm version", "semver Python", "PEP 440", "git tag release", "Trusted Publishing".6768---6970## Package type decision7172Identify what the user is building **before** writing any code. Each type has distinct patterns.7374### Decision Table7576| Type | Core Pattern | Entry Point | Key Deps | Example Packages |77|---|---|---|---|---|78| **Utility library** | Module of pure functions + helpers | Import API only | Minimal | `arrow`, `humanize`, `boltons`, `more-itertools` |79| **API client / SDK** | Class with methods, auth, retry logic | Import API only | `httpx` or `requests` | `boto3`, `stripe-python`, `openai` |80| **CLI tool** | Command functions + argument parser | `[project.scripts]` or `[project.entry-points]` | `click` or `typer` | `black`, `ruff`, `httpie`, `rich` |81| **Framework plugin** | Plugin class, hook registration | `[project.entry-points."framework.plugin"]` | Framework dep | `pytest-*`, `django-*`, `flask-*` |82| **Data processing library** | Classes + functional pipeline | Import API only | Optional: `numpy`, `pandas` | `pydantic`, `marshmallow`, `cerberus` |83| **Mixed / generic** | Combination of above | Varies | Varies | Many real-world packages |8485**Decision Rule:** Ask the user if unclear. A package can combine types (e.g., SDK with a CLI86entry point) — use the primary type for structural decisions and add secondary type patterns on top.8788For implementation patterns of each type, see `references/library-patterns.md`.8990### Package Naming Rules9192- PyPI name: all lowercase, hyphens — `my-python-library`93- Python import name: underscores — `my_python_library`94- Check availability: https://pypi.org/search/ before starting95- Avoid shadowing popular packages (verify `pip install <name>` fails first)9697---9899## Folder structure decision100101### Decision Tree102103```104Does the package have 5+ internal modules OR multiple contributors OR complex sub-packages?105├── YES → Use src/ layout106│ Reason: prevents accidental import of uninstalled code during development;107│ separates source from project root files; PyPA-recommended for large projects.108│109├── NO → Is it a single-module, focused package (e.g., one file + helpers)?110│ ├── YES → Use flat layout111│ └── NO (medium complexity) → Use flat layout, migrate to src/ if it grows112│113└── Is it multiple related packages under one namespace (e.g., myorg.http, myorg.db)?114 └── YES → Use namespace/monorepo layout115```116117### Quick Rule Summary118119| Situation | Use |120|---|---|121| New project, unknown future size | `src/` layout (safest default) |122| Single-purpose, 1–4 modules | Flat layout |123| Large library, many contributors | `src/` layout |124| Multiple packages in one repo | Namespace / monorepo |125| Migrating old flat project | Keep flat; migrate to `src/` at next major version |126127---128129## Build backend decision130131### Decision Tree132133```134Does the user need version derived automatically from git tags?135├── YES → Use setuptools + setuptools_scm136│ (git tag v1.0.0 → that IS your release workflow)137│138└── NO → Does the user want an all-in-one tool (deps + build + publish)?139 ├── YES → Use poetry (v2+ supports standard [project] table)140 │141 └── NO → Is the package pure Python with no C extensions?142 ├── YES, minimal config preferred → Use flit143 │ (zero config, auto-discovers version from __version__)144 │145 └── YES, modern & fast preferred → Use hatchling146 (zero-config, plugin system, no setup.py needed)147148Does the package have C/Cython/Fortran extensions?149└── YES → MUST use setuptools (only backend with full native extension support)150```151152### Backend Comparison153154| Backend | Version source | Config | C extensions | Best for |155|---|---|---|---|---|156| `setuptools` + `setuptools_scm` | git tags (automatic) | `pyproject.toml` + optional `setup.py` shim | Yes | Projects with git-tag releases; any complexity |157| `hatchling` | manual or plugin | `pyproject.toml` only | No | New pure-Python projects; fast, modern |158| `flit` | `__version__` in `__init__.py` | `pyproject.toml` only | No | Very simple, single-module packages |159| `poetry` | `pyproject.toml` field | `pyproject.toml` only | No | Teams wanting integrated dep management |160161For all four complete `pyproject.toml` templates, see `references/pyproject-toml.md`.162163---164165## PyPA packaging flow166167This is the canonical end-to-end flow from source code to user install.168**Every step must be understood before publishing.**169170```1711. SOURCE TREE172 Your code in version control (git)173 └── pyproject.toml describes metadata + build system1741752. BUILD176 python -m build177 └── Produces two artifacts in dist/:178 ├── *.tar.gz → source distribution (sdist)179 └── *.whl → built distribution (wheel) — preferred by pip1801813. VALIDATE182 twine check dist/*183 └── Checks metadata, README rendering, and PyPI compatibility1841854. TEST PUBLISH (first release only)186 twine upload --repository testpypi dist/*187 └── Verify: pip install --index-url https://test.pypi.org/simple/ your-package1881895. PUBLISH190 twine upload dist/* ← manual fallback191 OR GitHub Actions publish.yml ← recommended (Trusted Publishing / OIDC)1921936. USER INSTALL194 pip install your-package195 pip install "your-package[extra]"196```197198### Key PyPA Concepts199200| Concept | What it means |201|---|---|202| **sdist** | Source distribution — your source + metadata; used when no wheel is available |203| **wheel (.whl)** | Pre-built binary — pip extracts directly into site-packages; no build step |204| **PEP 517/518** | Standard build system interface via `pyproject.toml [build-system]` table |205| **PEP 621** | Standard `[project]` table in `pyproject.toml`; all modern backends support it |206| **PEP 639** | `license` key as SPDX string (e.g., `"MIT"`, `"Apache-2.0"`) — not `{text = "MIT"}` |207| **PEP 561** | `py.typed` empty marker file — tells mypy/IDEs this package ships type information |208209For complete CI workflow and publishing setup, see `references/ci-publishing.md`.210211---212213## Project structure templates214215### A. src/ Layout (Recommended default for new projects)216217```218your-package/219├── src/220│ └── your_package/221│ ├── __init__.py # Public API: __all__, __version__222│ ├── py.typed # PEP 561 marker — EMPTY FILE223│ ├── core.py # Primary implementation224│ ├── client.py # (API client type) or remove225│ ├── cli.py # (CLI type) click/typer commands, or remove226│ ├── config.py # Settings / configuration dataclass227│ ├── exceptions.py # Custom exception hierarchy228│ ├── models.py # Data classes, Pydantic models, TypedDicts229│ ├── utils.py # Internal helpers (prefix _utils if private)230│ ├── types.py # Shared type aliases and TypeVars231│ └── backends/ # (Plugin pattern) — remove if not needed232│ ├── __init__.py # Protocol / ABC interface definition233│ ├── memory.py # Default zero-dep implementation234│ └── redis.py # Optional heavy implementation235├── tests/236│ ├── __init__.py237│ ├── conftest.py # Shared fixtures238│ ├── unit/239│ │ ├── __init__.py240│ │ ├── test_core.py241│ │ ├── test_config.py242│ │ └── test_models.py243│ ├── integration/244│ │ ├── __init__.py245│ │ └── test_backends.py246│ └── e2e/ # Optional: end-to-end tests247│ └── __init__.py248├── docs/ # Optional: mkdocs or sphinx249├── scripts/250│ └── scaffold.py251├── .github/252│ ├── workflows/253│ │ ├── ci.yml254│ │ └── publish.yml255│ └── ISSUE_TEMPLATE/256│ ├── bug_report.md257│ └── feature_request.md258├── .pre-commit-config.yaml259├── pyproject.toml260├── CHANGELOG.md261├── CONTRIBUTING.md262├── SECURITY.md263├── LICENSE264├── README.md265└── .gitignore266```267268### B. Flat Layout (Small / focused packages)269270```271your-package/272├── your_package/ # ← at root, not inside src/273│ ├── __init__.py274│ ├── py.typed275│ └── ... (same internal structure)276├── tests/277└── ... (same top-level files)278```279280### C. Namespace / Monorepo Layout (Multiple related packages)281282```283your-org/284├── packages/285│ ├── your-org-core/286│ │ ├── src/your_org/core/287│ │ └── pyproject.toml288│ ├── your-org-http/289│ │ ├── src/your_org/http/290│ │ └── pyproject.toml291│ └── your-org-cli/292│ ├── src/your_org/cli/293│ └── pyproject.toml294├── .github/workflows/295└── README.md296```297298Each sub-package has its own `pyproject.toml`. They share the `your_org` namespace via PEP 420299implicit namespace packages (no `__init__.py` in the namespace root).300301### Internal Module Guidelines302303| File | Purpose | When to include |304|---|---|---|305| `__init__.py` | Public API surface; re-exports; `__version__` | Always |306| `py.typed` | PEP 561 typed-package marker (empty) | Always |307| `core.py` | Primary class / main logic | Always |308| `config.py` | Settings dataclass or Pydantic model | When configurable |309| `exceptions.py` | Exception hierarchy (`YourBaseError` → specifics) | Always |310| `models.py` | Data models / DTOs / TypedDicts | When data-heavy |311| `utils.py` | Internal helpers (not part of public API) | As needed |312| `types.py` | Shared `TypeVar`, `TypeAlias`, `Protocol` definitions | When complex typing |313| `cli.py` | CLI entry points (click/typer) | CLI type only |314| `backends/` | Plugin/strategy pattern | When swappable implementations |315| `_compat.py` | Python version compatibility shims | When 3.9–3.13 compat needed |316317---318319## Versioning strategy320321### PEP 440 — The Standard322323```324Canonical form: N[.N]+[{a|b|rc}N][.postN][.devN]325326Examples:327 1.0.0 Stable release328 1.0.0a1 Alpha (pre-release)329 1.0.0b2 Beta330 1.0.0rc1 Release candidate331 1.0.0.post1 Post-release (e.g., packaging fix only)332 1.0.0.dev1 Development snapshot (not for PyPI)333```334335### Semantic Versioning (recommended)336337```338MAJOR.MINOR.PATCH339340MAJOR: Breaking API change (remove/rename public function/class/arg)341MINOR: New feature, fully backward-compatible342PATCH: Bug fix, no API change343```344345### Dynamic versioning with setuptools_scm (recommended for git-tag workflows)346347```bash348# How it works:349git tag v1.0.0 → installed version = 1.0.0350git tag v1.1.0 → installed version = 1.1.0351(commits after tag) → version = 1.1.0.post1 (suffix stripped for PyPI)352353# In code — NEVER hardcode when using setuptools_scm:354from importlib.metadata import version, PackageNotFoundError355try:356 __version__ = version("your-package")357except PackageNotFoundError:358 __version__ = "0.0.0-dev" # Fallback for uninstalled dev checkouts359```360361Required `pyproject.toml` config:362```toml363[tool.setuptools_scm]364version_scheme = "post-release"365local_scheme = "no-local-version" # Prevents +g<hash> from breaking PyPI uploads366```367368**Critical:** always set `fetch-depth: 0` in every CI checkout step. Without full git history,369`setuptools_scm` cannot find tags and the build version silently falls back to `0.0.0+dev`.370371### Static versioning (flit, hatchling manual, poetry)372373```python374# your_package/__init__.py375__version__ = "1.0.0" # Update this before every release376```377378### Version specifier best practices for dependencies379380```toml381# In [project] dependencies:382"httpx>=0.24" # Minimum version — PREFERRED for libraries383"httpx>=0.24,<1.0" # Upper bound only when a known breaking change exists384"httpx==0.27.0" # Pin exactly ONLY in applications, NOT libraries385386# NEVER do this in a library — it breaks dependency resolution for users:387# "httpx~=0.24.0" # Too tight388# "httpx==0.27.*" # Fragile389```390391### Version bump → release flow392393```bash394# 1. Update CHANGELOG.md — move [Unreleased] entries to [x.y.z] - YYYY-MM-DD395# 2. Commit the changelog396git add CHANGELOG.md397git commit -m "chore: prepare release vX.Y.Z"398# 3. Tag and push — this triggers publish.yml automatically399git tag vX.Y.Z400git push origin main --tags401# 4. Monitor GitHub Actions → verify on https://pypi.org/project/your-package/402```403404For complete pyproject.toml templates for all four backends, see `references/pyproject-toml.md`.405406---407408## Progressive disclosure and bundled resources409410After understanding decisions and structure:4114121. **Set up `pyproject.toml`** → `references/pyproject-toml.md`413 All four backend templates (setuptools+scm, hatchling, flit, poetry), full tool configs,414 `py.typed` setup, versioning config.4154162. **Write your library code** → `references/library-patterns.md`417 OOP/SOLID principles, type hints (PEP 484/526/544/561), core class design, factory functions,418 `__init__.py`, plugin/backend pattern, CLI entry point.4194203. **Add tests and code quality** → `references/testing-quality.md`421 `conftest.py`, unit/backend/async tests, parametrize, ruff/mypy/pre-commit setup.4224234. **Set up CI/CD and publish** → `references/ci-publishing.md`424 `ci.yml`, `publish.yml` with Trusted Publishing (OIDC, no API tokens), CHANGELOG format,425 release checklist.4264275. **Polish for community/OSS** → `references/community-docs.md`428 README sections, docstring format, CONTRIBUTING, SECURITY, issue templates, anti-patterns429 table, and master release checklist.4304316. **Design backends, config, transport, CLI** → `references/architecture-patterns.md`432 Backend system (plugin/strategy pattern), Settings dataclass, HTTP transport layer,433 CLI with click/typer, backend injection rules.4344357. **Choose and implement a versioning strategy** → `references/versioning-strategy.md`436 PEP 440 canonical forms, SemVer rules, pre-release identifiers, setuptools_scm deep-dive,437 flit static versioning, decision engine (DEFAULT/BEGINNER/MINIMAL).4384398. **Govern releases and secure the publish pipeline** → `references/release-governance.md`440 Branch strategy, branch protection rules, OIDC Trusted Publishing setup, tag author441 validation in CI, tag format enforcement, full governed `publish.yml`.4424439. **Simplify tooling with Ruff** → `references/tooling-ruff.md`444 Ruff-only setup replacing black/isort/flake8, mypy config, pre-commit hooks,445 asyncio_mode=auto (remove @pytest.mark.asyncio), migration guide.446## Output template447448```markdown449### Python package build result450451**Status:** scaffolded | updated | published | blocked452**Package:** `<pypi-name>` / import name `<import_name>`453**Type:** utility library | API client / SDK | CLI tool | framework plugin | data processing library | mixed454**Layout:** `src/` | flat | namespace / monorepo455**Backend:** `setuptools` + `setuptools_scm` | `hatchling` | `flit` | `poetry`456**Versioning:** PEP 440 / SemVer / static / dynamic git-tag457458**Files created or changed**459- `pyproject.toml`: <backend, metadata, dependencies, tool config>460- `<package>/py.typed`: <present and empty>461- `tests/`: <unit/integration/e2e coverage added>462- `.github/workflows/ci.yml`: <quality gates>463- `.github/workflows/publish.yml`: <Trusted Publishing or manual fallback>464- `README.md`, `CHANGELOG.md`, `CONTRIBUTING.md`, `SECURITY.md`: <status>465466**Commands**467- `python -m build`: pass | fail468- `twine check dist/*`: pass | fail469- `pytest`: pass | fail470- `ruff check .`: pass | fail471- `mypy`: pass | fail472473**Release path**474- TestPyPI: `twine upload --repository testpypi dist/*` then `pip install --index-url https://test.pypi.org/simple/ your-package`475- PyPI: Trusted Publishing workflow or `twine upload dist/*`476```477478## Quality gate479480- [ ] Package type, layout, backend, and versioning choices were made using the decision tables in this skill.481- [ ] PyPI name is lowercase with hyphens, import name uses underscores, and availability was checked at (https://pypi.org/search/).482- [ ] `pyproject.toml` uses PEP 517/518 and PEP 621 metadata, with PEP 639 SPDX `license` syntax.483- [ ] Typed packages include an empty `py.typed` marker for PEP 561 and suitable PEP 484/526/544 hints.484- [ ] Libraries avoid exact dependency pins unless there is a documented compatibility reason.485- [ ] Dynamic `setuptools_scm` projects set `local_scheme = "no-local-version"` and CI checkout uses `fetch-depth: 0`.486- [ ] Build artifacts in `dist/` pass `python -m build` and `twine check dist/*`.487- [ ] Tests, Ruff, mypy, and pre-commit configuration match the selected package complexity.488- [ ] Publishing uses Trusted Publishing / OIDC where possible; API tokens are fallback only and never committed.489- [ ] Release governance covers `CHANGELOG.md`, valid `vX.Y.Z` tags, branch protection, and https://pypi.org/project/your-package/ verification.490- [ ] Bundled references and `scripts/scaffold.py` are used on demand rather than copied blindly.491492## References493494- [PyPI package search](https://pypi.org/search/)495- [TestPyPI simple index](https://test.pypi.org/simple/)496- [Example PyPI project verification URL](https://pypi.org/project/your-package/)
Run npx skillmds@latest add paulasilvatech/python-pypi-package-builder-2 in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Build, test, type-check, version, package, and publish production Python libraries to PyPI. Use this skill when creating a pip-installable SDK, CLI, plugin, or utility; choosing `src/` vs flat layout; selecting setuptools, hatchling, flit, or poetry; configuring pyproject.toml, py.typed, Ruff, mypy, pre-commit, GitHub Actions, TestPyPI, Trusted Publishing, setuptools_scm, PEP 440, SemVer, or release governance. It is listed under Coding & Dev Tools on SkillMD.
SkillMD's automated safety review verdict for this skill is WARNING. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
paulasilvatech (@paulasilvatech) published this skill. Their other Agent Skills are listed on their SkillMD profile.