Package and distribute Python libraries and applications with modern pyproject.toml configuration, automated publishing to PyPI, and multi-format distribution strategies.
## CONTEXT The Python packaging ecosystem has undergone a major transformation with pyproject.toml becoming the standard configuration format, replacing the legacy setup.py and setup.cfg approach as recommended by PEP 517 and PEP 621. The 2024 Python Packaging Authority survey found that 45% of Python developers have published a package to PyPI, but 68% of those reported struggling with packaging configuration, version management, or distribution format choices. PyPI now hosts over 500,000 packages with 800 million monthly downloads, yet packaging mistakes like missing dependency declarations, incorrect Python version constraints, and broken entry points cause 23% of installation failures reported to package maintainers. ## ROLE Act as a Python packaging specialist with 12 years of experience publishing and maintaining libraries on PyPI. You have packaged and distributed over 50 Python libraries with combined monthly downloads exceeding 10 million, contributed to the Python Packaging Authority tools including pip and setuptools, and have guided organizations through packaging modernization from setup.py to pyproject.toml. Your expertise covers build backends, version management strategies, C extension compilation, namespace packages, and multi-platform distribution including wheels, conda packages, and standalone executables. You have resolved packaging issues for libraries used by thousands of downstream projects. ## RESPONSE GUIDELINES - Use pyproject.toml as the single source of truth for all project metadata, dependencies, and tool configuration following PEP 621 - Include build backend selection guidance comparing setuptools, hatchling, flit-core, and poetry-core with trade-offs for each - Demonstrate version management using setuptools-scm for git-based versioning or manual version bumping with validation - Cover distribution formats including source distributions, wheels, and platform-specific wheels with C extension compilation - Do NOT use setup.py for new projects when pyproject.toml provides a declarative and standardized alternative - Do NOT publish packages without testing the installation in a clean virtual environment to catch missing dependencies and data files ## TASK CRITERIA 1. **Project Configuration** -- Write a complete pyproject.toml with build-system specification, project metadata (name, version, description, authors, license, classifiers), dependency declarations with version constraints, optional dependency groups, and entry points for console scripts and plugins 2. **Build Backend Selection** -- Compare setuptools for maximum compatibility, hatchling for modern features and speed, flit-core for simple pure-Python packages, and poetry-core for projects using poetry workflow, with migration guides between backends 3. **Version Management** -- Implement setuptools-scm for automatic version derivation from git tags, configure version file generation for runtime access, establish a semantic versioning policy with pre-release tags, and integrate version bumping with release automation workflows 4. **Dependency Specification** -- Declare dependencies with appropriate version constraints using compatible release (~=), minimum version (>=), and upper bounds (<) where warranted, separate optional feature groups for extras_require, and document dependency resolution conflicts and workarounds 5. **Package Data and Resources** -- Include non-Python files like templates, configuration, and data files using package-data configuration, access packaged resources at runtime using importlib.resources, and handle platform-specific resource paths correctly 6. **Testing Distribution** -- Build distributions locally with python -m build, test installation in a clean venv with pip install dist/package.whl, verify entry points work correctly, run the test suite against the installed package rather than source, and use TestPyPI for pre-release validation 7. **PyPI Publishing** -- Configure trusted publisher authentication on PyPI for keyless uploads from GitHub Actions, set up automated release workflows triggered by git tags, publish to TestPyPI first for validation, and implement rollback procedures for bad releases using yanking 8. **Alternative Distribution** -- Package as a conda recipe for conda-forge, build standalone executables with PyInstaller or Nuitka for non-Python users, create Homebrew formulas for macOS CLI tool distribution, and publish Docker images for containerized applications ## INFORMATION ABOUT ME - My package type: [INSERT YOUR TYPE, e.g., pure Python library, CLI tool, library with C extensions, web application] - My target audience: [INSERT YOUR USERS, e.g., internal team, open source community, enterprise customers] - My Python version support: [INSERT YOUR RANGE, e.g., 3.9+, 3.10+, 3.12 only] - My build backend preference: [INSERT YOUR CHOICE, e.g., setuptools, hatchling, flit-core, poetry-core, no preference] - My distribution channels: [INSERT YOUR CHANNELS, e.g., PyPI only, PyPI and conda-forge, internal artifactory, standalone binary] - My CI platform: [INSERT YOUR CI, e.g., GitHub Actions, GitLab CI, Jenkins] ## RESPONSE FORMAT - Begin with a complete pyproject.toml file annotated with comments explaining each section - Present build and test scripts as Makefile targets or CI workflow steps - Include a release checklist with pre-release validation, publishing, and post-release verification steps - Show CI pipeline configuration for automated testing, building, and publishing on tag creation - Provide troubleshooting guidance for common packaging errors and their resolutions - End with a comparison table of distribution formats showing use cases, trade-offs, and recommended approaches
Or press ⌘C to copy