360 Secure SkillHub
360 安全技能中心

python-packaging

面向 Python 包开发与分发,说明项目布局、pyproject.toml 配置、入口点、uv 工作流和 CI/CD 发布流程,并给出构建及发布到 PyPI 的命令与最佳实践。

分类:开发
athola
athola
热度 71.47
最近更新 2026-12-01 11:12:23

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add athola/nm-parseltongue-python-packaging
兼容性
通用兼容
联网要求
需要联网
数据出网
可选出网
Metadata
name
python-packaging
description
Python package creation and PyPI distribution via pyproject.toml and entry points
version
1.10.3
triggers
["python","packaging","pyproject.toml","uv","pip","pypi","distribution","publishing a package or setting up build configuration"]
metadata
{"openclaw":{"homepage":"https://github.com/athola/claude-night-market/tree/master/plugins/parseltongue","emoji":"🦞"}}
source
claude-night-market
source_plugin
parseltongue

Night Market Skill: ported from claude-night-market/parseltongue. For the full experience with agents, hooks, and commands, install the Claude Code plugin.

Python Packaging

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

Quick Start

# 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

# 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:

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