Modern tooling
uv, ruff, pyproject.toml, packaging, and current Python project workflows.
How to Export a Conda Environment YAML File in Python
Generate a mock conda environment YAML export with a reusable Python function and the PyYAML library.
import yaml
def conda_env_mock(name="demo_env", channels=None, packages=None):
channels = channels or ["defaults"]
packages = packages or [
"python=3.11",
"pip",
"numpy=1.24.3",
"pandas=2.0.3",
]
env_dict = {
"name": name,
"channels": channels,
…
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.
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…
How to Parse Taskfile YAML in Python
Load a Taskfile.yaml with PyYAML and simulate task execution by returning each task's commands.
import yaml
from pathlib import Path
def load_taskfile(taskfile_path: str) -> dict:
"""Load and parse a Taskfile.yaml file into a dict."""
data = Path(taskfile_path).read_text()
return yaml.safe_load(data)
def run_task(taskfile: dict, task_name: str) -> dict:
"""Simulate running a task by returning i…
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.