Reference library

Modern tooling

uv, ruff, pyproject.toml, packaging, and current Python project workflows.

6 matches
Modern tooling easy

How to Generate a Mock Rollbar Error Report in Python

Create a realistic fake Rollbar error report with random timestamps, levels, messages, and counts for testing and demos.

rollbar mock-data error-reporting
Python
import json
import random
import time
from datetime import datetime, timedelta


def mock_rollbar_report(n_errors=5):
    messages = [
        "TypeError: unsupported operand type(s) for +: 'int' and 'str'",
        "KeyError: 'user_id'",
        "ValueError: invalid literal for int() with base 10: 'abc'",
        "At…
13 0 Open
Modern tooling easy

How to Generate a Mock devcontainer.json Config in Python

Build a reproducible devcontainer.json file with Python, composing name, image, extensions, forwarded ports, and a post-create command as a dict.

devcontainer json config
Python
import json
from pathlib import Path


def create_devcontainer_config(
    image: str = "mcr.microsoft.com/devcontainers/python:3.11",
    name: str = "python-dev-container",
    ports: list[int] | None = None,
    post_create: str | None = None,
) -> dict:
    config = {
        "name": name,
        "image": image,
…
14 0 Open
Modern tooling easy

How to List Pre-commit Hooks from YAML Config in Python

Parse a .pre-commit-config.yaml file with PyYAML and print every hook ID paired with its source repository.

pre-commit yaml pyyaml
Python
import yaml

pre_commit_config = """
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.5.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
  - repo: https://github.com/psf/black
    rev: 23.11.0
    hooks:
      - id: black
"""

def list_hooks(c…
15 0 Open
Modern tooling easy

How to Mock docker compose up Healthcheck in Python

Simulate docker compose up with a healthcheck cycle using Python loops, delays, and simulated service statuses.

docker healthcheck simulation
Python
import subprocess
import time

def run_healthcheck():
    """Mock a docker compose up with a healthcheck cycle."""
    services = ["web", "db", "cache"]
    
    print("Starting docker compose services...")
    for service in services:
        print(f"[{service}] starting...")
        time.sleep(0.1)
        print(f"[…
15 0 Open
Modern tooling medium

How to set up mypy strict mode in Python

Demonstrates how to configure and run mypy in strict mode to enforce full type annotation coverage across a Python project.

mypy type-hints strict-mode
Python
from typing import Dict, Optional


def describe_user(name: str, age: int, email: Optional[str] = None) -> Dict[str, object]:
    """Build a user description dictionary with strict type annotations."""
    user: Dict[str, object] = {"name": name, "age": age}
    if email is not None:
        user["email"] = email
    …
14 0 Open
Modern tooling easy

pytest mark slow skip integration

Uses pytest markers to select fast tests, skip unfinished ones, and run integration checks with verbose output.

pytest markers testing
Python
import pytest

def test_fast():
    assert 1 + 1 == 2

@pytest.mark.slow
def test_slow():
    import time
    time.sleep(1)
    assert 5 * 5 == 25

@pytest.mark.skip(reason="Not ready for production")
def test_skipped():
    assert 2 + 2 == 5

@pytest.mark.integration
def test_integration():
    database = {"users": […
17 0 Open

Browse by section

Each section groups closely related Python snippets.

Modern tooling — Python code examples

What you will find here

This page collects modern tooling snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.