Claude
Skills
Sign in
โ† Back

python

Included with Lifetime
$97 forever

Adaptive Python development guide with tiered complexity levels (Minimal/Standard/Full). Automatically selects appropriate guidance based on project context - from simple scripts (just clean Python code) to full production systems (complete tooling ecosystem). Covers modern conventions, testing, tooling, security, and best practices. Use when writing Python code, converting scripts, setting up projects, or building production systems. Keywords: PEP-8, Ruff, pytest, mypy, simple scripts, project structure, PyPI, packaging, type hints, clean code

Securityassets

What this skill does


# Python Development Skill

Comprehensive guide to modern Python development covering conventions, testing, tooling, security, performance, and ecosystem best practices (2024-2025 standards).

## Tier 2 Quick Start

**For multi-file projects, team collaboration, and maintained code:**

```bash
# Install Python 3.12 and uv (see Installation guides)
# Windows: winget install Python.Python.3.12 && winget install astral-sh.uv
# macOS: brew install [email protected] uv
# Linux: apt install python3.13 && curl -LsSf https://astral.sh/uv/install.sh | sh

# Create new project with modern structure
uv init my-project
cd my-project

# Add dependencies
uv add requests httpx pydantic

# Add development dependencies
uv add --dev pytest pytest-cov ruff mypy

# Set up code quality (create pyproject.toml config - see assets/pyproject-toml-template.toml)
# Configure Ruff, mypy, pytest

# Write tests (pytest)
# tests/test_example.py - mirror src/ structure

# Run quality checks
uv run ruff check .          # Linting
uv run ruff format .         # Formatting
uv run mypy .                # Type checking
uv run pytest                # Run tests
uv run pytest --cov          # With coverage
```

## When to Use This Skill

Invoke this skill when you need guidance on:

- **Installation & Setup**: Installing Python 3.12/3.14, uv, setting up development environment
- **Code Style**: Following PEP-8, configuring Ruff/Black, naming conventions
- **Project Structure**: Organizing code with src/ layout, imports, package structure
- **Dependency Management**: Using uv, Poetry, pip, virtual environments, pyproject.toml
- **Testing**: Writing pytest tests, fixtures, parametrization, coverage, mocking
- **Type Hints**: Modern typing patterns, mypy configuration, protocols, generics
- **Code Quality**: Setting up Ruff, mypy, Bandit, pre-commit hooks, CI/CD
- **Async Programming**: asyncio patterns, async/await, TaskGroup, structured concurrency
- **Security**: OWASP best practices, input validation, dependency scanning
- **Performance**: Profiling, optimization patterns, Cython
- **Packaging**: pyproject.toml, PyPI publishing, versioning, distribution
- **Common Libraries**: Standard library essentials, ecosystem overview
- **Documentation**: Docstrings (PEP-257), Sphinx, documentation generation

## Overview

This skill provides modern Python development guidance aligned with current best practices (2024-2025):

**Core Standards:**

- **Style**: PEP-8 (enforced via Ruff)
- **Type Hints**: PEP-484, PEP-526, modern syntax (PEP-604: `str | None`)
- **Packaging**: PEP-517, PEP-518 (pyproject.toml)
- **Docstrings**: PEP-257
- **Testing**: pytest (industry standard)
- **Dependency Management**: uv (fastest) or Poetry (feature-rich)

**Modern Tooling (2024-2025):**

- **Linter/Formatter**: Ruff (replaces flake8, isort, optionally Black)
- **Type Checker**: mypy with strict mode
- **Test Framework**: pytest
- **Dependency Manager**: uv or Poetry
- **Security Scanner**: Bandit + pip-audit
- **Project Config**: pyproject.toml (universal)

**Project Structure:**

- src/ layout (modern standard, not flat layout)
- Absolute imports preferred over relative
- Tests mirror src/ structure
- pyproject.toml for all configuration

**Official Sources:**
All guidance backed by official Python documentation, PEPs, and tool documentation:

- docs.python.org
- peps.python.org
- docs.astral.sh/ruff
- docs.astral.sh/uv
- mypy-lang.org
- docs.pytest.org

## Quick Tier Selection

**Choose your complexity level:**

### ๐ŸŽฏ Tier 1: Minimal (Simple Scripts)

โ†’ Single-file utilities, converting scripts, one-off automation
โ†’ Just Python code - no tooling overhead
โ†’ [Jump to Minimal Guidance](#tier-1-minimal-simple-scripts)

### ๐Ÿ“ฆ Tier 2: Standard (Organized Projects)

โ†’ Multi-file modules, team projects, maintained code
โ†’ Modern project structure + testing
โ†’ [Jump to Standard Guidance](#tier-2-standard-organized-projects)

### ๐Ÿš€ Tier 3: Full (Production Systems)

โ†’ PyPI packages, enterprise systems, production deployments
โ†’ Complete tooling ecosystem
โ†’ [Jump to Full Guidance](#tier-3-full-production-systems)

**Not sure?** Default to Tier 2 (Standard) - it covers most use cases.

---

## Tier 1: Minimal (Simple Scripts)

**For:** Single-file utilities, script conversions, and simple automation.

### Setup

Just Python 3.12+ - no additional tooling required:

- โœ… No uv, no virtual environment needed
- โœ… No pyproject.toml, no src/ layout
- โœ… Optional: Install Ruff for quick linting (`pip install ruff`)

### Code Standards

Follow these simple principles:

- **PEP-8 naming**: `snake_case` for functions/variables, `PascalCase` for classes
- **Type hints**: Add for clarity (helps readers understand your code)
- **Docstrings**: Simple descriptions of what functions do
- **pathlib**: Use `pathlib.Path` for file operations (not `os.path`)
- **Built-ins**: Use Python's built-in `json`, `datetime`, `sys` modules

### Example: Simple Logging Script

```python
#!/usr/bin/env python3
"""Simple logging utility - converts event to JSON."""

import json
import sys
from datetime import datetime, timezone
from pathlib import Path


def log_event(event_name: str, data: dict) -> None:
    """
    Log an event to daily JSONL file.

    Args:
        event_name: Name of the event
        data: Event data to log
    """
    log_dir = Path(__file__).parent / "logs"
    log_dir.mkdir(exist_ok=True)

    now = datetime.now(timezone.utc)
    log_file = log_dir / f"{now:%Y-%m-%d}.jsonl"

    entry = {
        "timestamp": now.isoformat(),
        "event": event_name,
        "data": data
    }

    with open(log_file, "a", encoding="utf-8") as f:
        f.write(json.dumps(entry) + "\n")


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: script.py <event_name>", file=sys.stderr)
        sys.exit(1)
    event_name = sys.argv[1]
    data = json.loads(sys.stdin.read())
    log_event(event_name, data)
```

### Optional: Quick Linting

If you want to check your code style:

```bash
# Install Ruff (optional)
pip install ruff

# Check code
ruff check script.py

# Format code
ruff format script.py
```

### When to Upgrade to Tier 2

Consider upgrading to Tier 2 (Standard) when:

- โœ… Script grows to 3+ files
- โœ… Multiple people working on code
- โœ… Need automated testing
- โœ… Managing external dependencies
- โœ… Code will be maintained long-term

---

## Tier 2: Standard (Organized Projects)

**For:** Multi-file modules, team projects, and maintained code.

Modern Python project setup with proper structure, testing, and quality tools.

### Installation

Install Python 3.12+ and uv (modern dependency manager). See platform-specific guides:

- [Installation Overview](references/installation/overview.md) - Concepts and version policy
- [Windows Installation](references/installation/windows.md) - WinGet, Python Launcher
- [macOS Installation](references/installation/macos.md) - Homebrew installation
- [Linux Installation](references/installation/linux.md) - apt/dnf or build from source

### Project Setup and Organization

**Conventions and Style** - Follow PEP-8 with Ruff for linting and formatting:

- See [Conventions and Style Guide](references/conventions-and-style.md)

**Project Structure** - Use modern src/ layout for proper packaging:

- See [Project Structure Guide](references/project-structure.md)

**Dependency Management** - Choose between uv (fastest), Poetry (feature-rich), or pip+venv:

- See [Dependency Management Guide](references/dependency-management.md)

### Testing and Quality

**Testing** - Use pytest with fixtures, parametrization, and coverage:

- See [Testing Methodology Guide](references/testing-methodology.md)

**Type Hints** - Modern typing with mypy, protocols, and generics:

- See [Type Hints Guide](references/type-hints.md)

**Code Quality** - Set up Ruff, mypy, Bandit, and pre-commit hooks:

- See [Code Quality Tools Guide](references/code-quality-tools.md)

### Advanced Development

**Async Programming** - asy

Related in Security