Skip to main content

Python Tutorial

This section covers Python engineering practices, tooling, and modern development workflows.

Topics

DocumentDescription
Python Engineering GuideProject structure, dependency management, and best practices
pyproject.toml GuideModern Python project configuration with pyproject.toml
uv GuideFast Python package manager and project management
Python Tools IntroductionCode quality tools: linters, formatters, and type checkers

Code Quality Tools Overview

Python has a mature ecosystem of code quality tools that help maintain consistency, catch bugs early, and enforce standards.

Tool Categories

CategoryPurposeExamples
LintersFind errors, bugs, and style issuesPylint, Flake8, Ruff
FormattersEnforce consistent code styleBlack, Ruff
Type CheckersVerify type annotationsMyPy, Pyright
Import SortersOrganize import statementsisort, Ruff

Ruff is a modern all-in-one Python linter and formatter written in Rust. It replaces Flake8, isort, Black, and more with a single, extremely fast tool.

Why Ruff?

AspectTraditional StackRuff
Tools neededFlake8 + isort + Black + MyPyRuff alone
Speed30-60 seconds1-3 seconds
ConfigurationMultiple config filesSingle pyproject.toml section
Auto-fixLimitedComprehensive

Quick Start

# Install
pip install ruff

# Lint and auto-fix
ruff check --fix src/

# Format
ruff format src/

Basic Configuration

[tool.ruff]
line-length = 88
target-version = "py38"

[tool.ruff.lint]
select = ["E", "F", "UP", "B", "SIM", "I", "N"]
ignore = ["E501"]

Traditional Tools (for reference)

ToolPurposeSpeedStatus
PylintComprehensive linting (200+ rules)SlowMature, still useful for deep analysis
BlackUncompromising formatterMediumWidely adopted standard
MyPyStatic type checkingSlowEssential for typed codebases
Flake8Linting wrapper (PyFlakes + pycodestyle)MediumBeing replaced by Ruff

For a detailed comparison and migration guide, see Python Tools Introduction.