Skip to content

Python Packaging — setuptools, pip, and pyproject.toml

DodaTech Updated 2026-06-29 1 min read

In this tutorial, you will learn about Python Packaging. We cover key concepts, practical examples, and best practices to help you master this topic.

Sharing Python code requires packaging. Whether you're distributing a library, a CLI tool, or deploying an application, understanding Python packaging is essential.

In this tutorial, you'll learn how to create, build, and distribute Python packages. DodaTech packages its security tools as pip-installable packages for easy deployment.

What You'll Learn

  • pyproject.toml: the modern packaging standard
  • setuptools: building and installing packages
  • pip: installing and managing dependencies
  • Virtual environments: isolating project dependencies
  • Publishing to PyPI and private repositories

pyproject.toml — Modern Packaging

This is the current standard for Python packaging (PEP 621):

[build-system]
requires = ["setuptools>=68.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "mytool"
version = "1.0.0"
description = "A useful CLI tool"
readme = "README.md"
license = {text = "MIT"}
requires-python = ">=3.9"

dependencies = [
    "requests>=2.28",
    "click>=8.0",
]

[project.optional-dependencies]
dev = [
    "pytest>=7.0",
    "black>=23.0",
    "mypy>=1.0",
]

[project.scripts]
mytool = "mytool.cli:main"

Virtual Environments

# Create a virtual environment
python3 -m venv .venv

# Activate it
source .venv/bin/activate  # Linux/Mac
# .venv\Scriptsctivate   # Windows

# Install from requirements
pip install -r requirements.txt

# Install your package in development mode
pip install -e .

# Freeze current dependencies
pip freeze > requirements.txt

Practice Questions

  1. Create a pyproject.toml for a simple library with one dependency.

  2. Add console_scripts entry point for a CLI tool.

  3. Create a setup.cfg alternative for traditional packaging.

  4. Add optional dev dependencies (pytest, black, mypy).

  5. Build and install your package locally with pip install -e .

  6. Create a MANIFEST.in to include non-Python files.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro