← Back to all products
$19
Python Packaging Guide
Modern Python packaging with pyproject.toml, setuptools, Poetry, publishing to PyPI, and versioning strategies.
MakeConfigPythonYAMLTOMLShellJSONMarkdownCI/CD
📁 File Structure 16 files
python-packaging-guide/
├── LICENSE
├── README.md
├── configs/
│ ├── .pre-commit-config.yaml
│ ├── mypy.ini
│ └── ruff.toml
├── guides/
│ └── python-packaging-guide.md
├── scripts/
│ ├── publish.sh
│ └── setup-dev.sh
├── src/
│ └── example_package/
│ ├── __init__.py
│ ├── core.py
│ └── py.typed
└── templates/
├── MANIFEST.in
├── Makefile
├── pyproject.toml
└── setup.cfg
📖 Documentation Preview README excerpt
Python Packaging Guide
Ship your Python library to PyPI with confidence.
Production-ready templates, configs, and scripts for modern Python packaging — from pyproject.toml to automated publishing.
---
What You Get
- Complete pyproject.toml template with setuptools, optional deps, and tool configs
- setup.cfg for backwards compatibility with older build systems
- MANIFEST.in with correct include/exclude patterns for sdist
- Makefile with common dev targets (install, test, lint, build, publish)
- Example package source with PEP 561 type stub marker
- publish.sh script for building and uploading to PyPI / TestPyPI
- setup-dev.sh for bootstrapping dev environments
- Linter/formatter configs for Ruff, mypy, and pre-commit
- Comprehensive packaging guide covering versioning, wheels, namespaces, and CI
File Tree
python-packaging-guide/
├── README.md
├── LICENSE
├── manifest.json
├── templates/
│ ├── pyproject.toml # Modern project metadata & build config
│ ├── setup.cfg # Backwards-compatible setup config
│ ├── MANIFEST.in # Source distribution includes/excludes
│ └── Makefile # Dev workflow targets
├── src/
│ └── example_package/
│ ├── __init__.py # Version & public API exports
│ ├── core.py # Example module with proper structure
│ └── py.typed # PEP 561 marker
├── scripts/
│ ├── publish.sh # Build + upload to PyPI
│ └── setup-dev.sh # Bootstrap dev environment
├── configs/
│ ├── ruff.toml # Ruff linter/formatter config
│ ├── .pre-commit-config.yaml # Pre-commit hook definitions
│ └── mypy.ini # Strict mypy config
└── guides/
└── python-packaging-guide.md
Getting Started
1. Copy the template into your project
cp templates/pyproject.toml my-project/pyproject.toml
2. Customize project metadata
[project]
*... continues with setup instructions, usage examples, and more.*
📄 Code Sample .py preview
src/example_package/core.py
"""Core module demonstrating proper Python module structure.
This module serves as a template — replace these functions with your
actual library logic while preserving the structural patterns.
"""
from __future__ import annotations
import logging
from typing import Any
logger = logging.getLogger(__name__)
def greet(name: str) -> str:
"""Return a greeting message.
Args:
name: The name to greet.
Returns:
A formatted greeting string.
"""
return f"Hello, {name}!"
def process_data(data: list[dict[str, Any]]) -> list[dict[str, Any]]:
"""Process a list of records, filtering out invalid entries.
Args:
data: List of dictionaries representing data records.
Returns:
Filtered and validated records.
"""
results: list[dict[str, Any]] = []
for record in data:
if not isinstance(record, dict):
logger.warning("Skipping non-dict record: %r", record)
continue
if "id" not in record:
logger.warning("Skipping record without 'id': %r", record)
continue
results.append(record)
logger.info("Processed %d/%d records", len(results), len(data))
return results
def main() -> None:
"""CLI entry point for the example package."""
# ... 2 more lines ...