skills/technical-patterns/python-skill/SKILL.md
ALWAYS LOAD THIS SKILL before setting up any Python environment or installing packages. Defines the standard: uv, Python 3.13, uv pip install, .venv at project root. Triggers: "set up python", "install python", "create a venv", "virtual environment", "pip install", "install packages", "uv pip", "uv venv", "python version", "VIRTUAL_ENV", "venv conflict", "which python", "activate", "deactivate", "run the script", "run with uv", "uv run", "pyproject.toml", "install dependencies", "install requirements", "install the package", "editable install", "pip install -e", "latest package", "latest version", "current version", "newest version".
npx skillsauth add policyengine/policyengine-claude pythonInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
All PolicyEngine Python work uses uv with Python 3.13 and a local .venv.
uv — fast Python package and project managerInstall uv if not present:
curl -LsSf https://astral.sh/uv/install.sh | sh
Always create a .venv at the project root using Python 3.13:
uv venv --python 3.13
source .venv/bin/activate
On Windows:
uv venv --python 3.13
.venv\Scripts\activate
Always use uv pip install, never bare pip install:
# Install a package
uv pip install policyengine
# Install from requirements file
uv pip install -r requirements.txt
# Install the current project in editable mode
uv pip install -e .
# Install with extras
uv pip install -e ".[dev]"
If the user asks for the "latest", "current", or "newest" version of a Python package, verify it from PyPI immediately before installing or pinning it. Do not treat search snippets, local installed versions, lockfiles, stale docs, or repo dependency constraints as proof of latest.
export PACKAGE=policyengine
# Authoritative PyPI metadata.
python - <<'PY'
import json
import os
import urllib.request
package = os.environ["PACKAGE"]
with urllib.request.urlopen(
f"https://pypi.org/pypi/{package}/json",
timeout=20,
) as response:
print(json.load(response)["info"]["version"])
PY
# Cross-check available versions when pip can reach PyPI.
python -m pip index versions "$PACKAGE"
Then install the exact verified version and confirm the resolved distribution:
VERSION=1.2.3
uv pip install "${PACKAGE}==${VERSION}"
python - <<'PY'
from importlib import metadata
import os
package = os.environ["PACKAGE"]
print(f"{package}=={metadata.version(package)}")
direct_url = metadata.distribution(package).read_text("direct_url.json")
if direct_url:
print(direct_url)
PY
For extras, query the base distribution and pin the extra install to that same
version, for example uv pip install "policyengine[us]==4.14.2".
After activating the venv, run Python normally:
python script.py
python -m pytest
Or run without activating using uv:
uv run python script.py
uv run pytest
# Confirm Python version (should be 3.13.x)
python --version
# Confirm uv is being used
which pip # should point to .venv
uv pip list
uv venv --python 3.13
source .venv/bin/activate
uv pip install -e ".[dev]"
# Edit pyproject.toml to add the dependency, then:
uv pip install -e .
uv run pytest
# or after activating:
pytest
If you see a warning like:
warning: `VIRTUAL_ENV=/Users/.../.venv` does not match the project environment path `.venv` and will be ignored
This means a different venv is active (e.g. a global one at ~/.venv). Fix with:
# Option 1: Deactivate and use uv run
deactivate
uv run python script.py
# Option 2: Use --active flag to force uv to use the active env
uv run --active python script.py
# Option 3: Activate the correct project venv explicitly
source /path/to/project/.venv/bin/activate
python script.py
Do not mix venvs between projects. Each project should have its own .venv at the repo root.
python -m venv — always uv venvpip install — always uv pip install--python 3.13).venvuv run <cmd> as an alternative to activating the venv manuallydeactivate then uv runtools
ONLY use this skill when users explicitly ask about the PolicyEngine Python package installation, REST API endpoints, API authentication, rate limits, or policyengine.py client library. DO NOT use for household benefit/tax calculations — ALWAYS use policyengine-us or policyengine-uk instead. This skill is about the API/client tooling itself, not about calculating benefits or taxes.
development
ALWAYS USE THIS SKILL for PolicyEngine microsimulation, population-level analysis, winners/losers calculations. Triggers: microsimulation, share who would lose/gain, policy impact, national average, weighted analysis, cost, revenue impact, budgetary, estimate the cost, federal revenues, tax revenue, budget score, how much would it cost, how much would the policy cost, total cost of, aggregate impact, cost to the government, revenue loss, fiscal impact, poverty impact, child poverty, deep poverty, poverty rate, poverty reduction, how many people lifted out of poverty, SPM poverty, distributional impact, state tax, state-level, California, New York, UBI, universal basic income, flat tax, standard deduction, winners and losers, winners, losers, inequality, Gini, decile, SALT, marginal tax rate, effective tax rate. NOT for single-household calculations like "what would my benefit be" - use policyengine-us or policyengine-uk for those. Use this skill's code pattern; explore codebase for parameter paths if needed.
development
PolicyEngine API v2 - Next-generation microservices architecture with monorepo structure
development
ALWAYS LOAD THIS SKILL for PolicyEngine PR reviews, including when the user invokes $review-program or Codex /review on a PolicyEngine PR. Performs read-only code validation, source-reference checks, regulatory review, optional PDF audit, summary reporting, and optional GitHub comment posting.