python-packaging
Create distributable Python packages with proper project structure, setup.py/pyproject.toml, and publishing to PyPI. Use when packaging Python libraries, creating CLI tools, or distributing Python code.
Python Packaging - Python Packbuilding and Publishing Guide
Skill Overview
Python Packaging provides complete guidance for creating distributable Python packages, covering project structure, pyproject.toml configuration, wheel building, and the full PyPI publishing workflow.
Use Cases
- Create a Python Library: Package reusable Python code into a library so others can install it via
pip - Develop CLI Tools: Build command-line applications and configure entry points for global command invocation
- Publish to PyPI: Publish a completed Python package to a Python package index for use by developers worldwide
Core Features
- Project Structure Initialization: Create a directory structure that follows Python packaging standards, including required files like
__init__.py,README,LICENSE, and more - Build Configuration Management: Write or generate
pyproject.tomlorsetup.pyto configure metadata, dependencies, and entry points - Packaging and Publishing: Use
setuptoolsor modern build tools to generate wheels and source distributions, then upload them to PyPI viatwineor other tools
Frequently Asked Questions
How do I publish a Python project to PyPI?
The publishing process includes: preparing the project structure, writing a pyproject.toml configuration file, using build tools to generate distribution packages, registering an account on PyPI, and using twine to upload the package. For the first release, you must register the package name; for subsequent updates, just increment the version number and upload again.
Should I use setup.py or pyproject.toml?
It’s recommended to use pyproject.toml, the configuration file for Python’s modern packaging standard (PEP 518/621). While setup.py is still widely supported, it is considered an older approach. New projects should prefer pyproject.toml, unless you need compatibility with very old Python versions or use a build backend that hasn’t been migrated yet.
What files are needed for Python packaging?
The minimal set of files for packaging includes: the project source code directory, pyproject.toml (or setup.py), README.md, and LICENSE. It’s also recommended to include: MANIFEST.in (to control packaged content), a tests/ directory, .github/ workflow configurations, and CHANGELOG.md to record version changes.