python-pypi-package-builder
它能做什么
这份指南可以帮你构建、测试并把 Python 库发布到 PyPI(Python 的软件包“应用商店”)。从代码组织到最终发布,它涵盖了整个流程,确保你的软件包运行良好,并且便于其他开发者使用。
适用场景
- ✓当你想创建第一个可以分享的 Python 库时。
- ✓当你需要把 Python 软件包发布到 PyPI 时。
- ✓当你想整理和测试已有的 Python 项目时。
技能链接
https://github.com/github/awesome-copilot/blob/main/skills/python-pypi-package-builder/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我该如何创建并发布一个名为 'my_utility' 的 Python 库?”
每周 5 个新技能,1 分钟读完。
工作原理
这份指南会帮你选择最合适的代码组织方式,以及用于构建、测试和发布软件包的工具。它还会讲解如何为软件包设置版本号,并介绍“类型提示”(type hints)等现代功能的用法。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Python PyPI Package Builder Skill
A complete, battle-tested guide for building, testing, linting, versioning, typing, and publishing a production-grade Python library to PyPI — from first commit to community-ready release.
AI Agent Instruction: Read this entire file before writing a single line of code or creating any file. Every decision — layout, backend, versioning strategy, patterns, CI — has a decision rule here. Follow the decision trees in order. This skill applies to any Python package type (utility, SDK, CLI, plugin, data library). Do not skip sections.
Quick Navigation
| Section in this file | What it covers |
|---|---|
| 1. Skill Trigger | When to load this skill |
| 2. Package Type Decision | Identify what you are building |
| 3. Folder Structure Decision | src/ vs flat vs monorepo |
| 4. Build Backend Decision | setuptools / hatchling / flit / poetry |
| 5. PyPA Packaging Flow | The canonical publish pipeline |
| 6. Project Structure Templates | Full layouts for every option |
| 7. Versioning Strategy | PEP 440, semver, dynamic vs static |
| Reference file | What it covers |
|---|---|
references/pyproject-toml.md |
All four backend templates, setuptools_scm, py.typed, tool configs |
references/library-patterns.md |
OOP/SOLID, type hints, core class design, factory, protocols, CLI |
references/testing-quality.md |
conftest.py, unit/backend/async tests, ruff/mypy/pre-commit |
references/ci-publishing.md |
ci.yml, publish.yml, Trusted Publishing, TestPyPI, CHANGELOG, release checklist |
references/community-docs.md |
README, docstrings, CONTRIBUTING, SECURITY, anti-patterns, master checklist |
references/architecture-patterns.md |
Backend system (plugin/strategy), config layer, transport layer, CLI, backend injection |
references/versioning-strategy.md |
PEP 440, SemVer, pre-release, setuptools_scm deep-dive, flit static, decision engine |
references/release-governance.md |
Branch strategy, branch protection, OIDC, tag author validation, prevent invalid tags |
references/tooling-ruff.md |
Ruff-only setup (replaces black/isort), mypy config, pre-commit, asyncio_mode=auto |
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.
1. Skill Trigger
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) - Understand PyPA specs:
py.typed,MANIFEST.in,RECORD, classifiers - 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".
2. 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 |
…
常见问题
什么是 PyPI?
PyPI 是 Python Package Index(Python 软件包索引)的缩写,是一个在线仓库,Python 开发者可以在这里发布和分享库(软件包),供其他人安装并在项目中使用。
什么是“构建后端”(setuptools、hatchling、flit、poetry)?
这些是 Python 用来打包代码的不同工具,它们会把你的代码转换成可以通过 pip 安装、也能发布到 PyPI 的格式。每种工具都有各自的优势。
什么是“类型提示”?
“类型提示”是你在 Python 代码中添加的注解,用来说明变量或函数期望的或返回的数据类型。它有助于及早发现错误,也让代码更容易理解。
详情
作者的原始描述
End-to-end skill for building, testing, linting, versioning, and publishing a production-grade Python library to PyPI. Covers all four build backends (setuptools+setuptools_scm, hatchling, flit, poetry), PEP 440 versioning, semantic versioning, dynamic git-tag versioning, OOP/SOLID design, type hints (PEP 484/526/544/561), Trusted Publishing (OIDC), and the full PyPA packaging flow. Use for: creat
repo: github/awesome-copilot
热度
- GitHub 星标
- 40k
- 排名
- #7352
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
acquire-codebase-knowledge
40k帮你的智能体理解并编写现有代码项目的文档。它有助于新成员快速上手,或者快速了解项目架构。
acreadiness-assess
40k让你的智能体评估一个项目对 AI 的准备程度,并生成报告。它有助于了解项目在使用 AI 工具方面的准备情况。
acreadiness-generate-instructions
40k帮你的智能体根据评估结果编写 AI 工具的指令文件。它有助于改善 AI 与代码的交互方式,并弥补已发现的不足。
acreadiness-policy
40k让你的智能体协助制定或应用 AI 项目评估的政策。它有助于规范项目的评估方式,并确保合规。