python3 on most distributions — the interpreter executes your bytecode on a virtual machine.apt install python3) target CPython. Alternative implementations (PyPy, MicroPython) exist for speed or embedded use but are not interchangeable without testing extensions and wheels.
site-packages and usually a copy/symlink of the interpreter (python -m venv .venv). Imports resolve against that env first, not the system Python.pip install --user and global installs — venvs are the standard for reproducible deploys.#!/usr/bin/env python3 instead of a hard-coded interpreter path?
env looks up python3 on PATH, so the script works across distros and local venv activation. A hard path like #!/usr/local/bin/python3 breaks on machines where Python lives elsewhere.PATH explicitly or call the venv’s interpreter directly (/opt/app/.venv/bin/python) for determinism.
PYTHONPATH prepends directories to sys.path so Python can import modules outside the default locations. Useful for monorepos or ad-hoc tooling.pip install -e .), PYTHONPATH only when controlled and documented.
pip vs pipx?
pipx install black). Ideal for operator laptops, not for app dependency management inside a service repo.
pyproject.toml and how does PEP 621 fit in?
pyproject.toml is the standard place to declare build system and project metadata (PEP 518 onward). PEP 621 defines the [project] table: name, version, dependencies, optional deps, scripts entry points.setup.py-only workflows for many teams.
[build-system] requires requires + build-backend so pip knows how to build the wheel.requirements.txt, requirements.in + pip-compile, and Poetry lockfiles.
requirements.txt for reproducibility.poetry.lock or pdm.lock locks the full graph with metadata; installs are deterministic from the lockfile.
pip install -e . (editable install) mean for internal tools?
easy-install.pth (or equivalent) so code changes are immediately importable without reinstalling. Used when developing shared libraries or CLI tools in a monorepo.uv, pip, and Poetry differ for CI speed and reproducibility?
~/.cache/pip or uv cache in GHA for build time wins.argparse enough vs Click or Typer for ops CLIs?
subprocess.run(..., shell=True) dangerous?
shell=True, the string passes through a shell, so metacharacters (; | $()) are interpreted. Untrusted input can become command injection.shell=False with a list argv ["ansible-playbook", "site.yml"] and no user-controlled shell grammar.
subprocess.run without shell=True so the OS passes argv directly to the program. Validate allowlists for hostnames, paths, and job names.env={**os.environ, "FOO": value} with controlled values. Never interpolate untrusted strings into shell one-liners.
pathlib over os.path for automation?
pathlib.Path gives object-oriented paths, overloads / for joining, and clear methods (read_text, glob, mkdir(parents=True)). Fewer string bugs across Windows vs Linux when you must support both.os.path still fine in legacy code; new internal tools should standardize on pathlib.
Path.resolve() for symlink clarity in deploy scripts.level, trace_id, user) for filtering and alerting.structlog or logging formatters emit one JSON object per line; ship to the collector via stdout (12-factor).
pytest-cov, pytest-xdist). Less boilerplate than unittest classes for glue code and policy tests.pytest --cov=src --cov-report=xml and upload XML to Sonar, Codecov, or fail the job if coverage drops below threshold..coveragerc to omit generated or migration paths. Coverage is a guardrail, not proof of correctness.
pre-commit run --all-files. Same checks locally and in pipeline reduce “lint failed on main” churn..pre-commit-config.yaml in the repo; pin hook revisions for reproducibility.
client and resource?
list_objects_v2), returns dicts.s3.Bucket) built on clients — ergonomic for simple CRUD, less control for every API edge case.AWS_ACCESS_KEY_ID), shared credentials file, SSO / IAM Identity Center, instance/container role, etc.Session(profile_name=...) in dev scripts for clarity.client.get_paginator('list_objects_v2') then paginate(Bucket=...) — handles NextToken / ContinuationToken correctly.NextMarker are error-prone. Paginators are the standard pattern in automation and data pipelines.
python:3.12-slim). Smaller images, fewer CVEs, faster pulls.gcc, git, or .git history in production layers.
pip install?
pip install, then COPY application source. Code changes won’t bust the dependency layer.COPY . . before pip — any file edit reinstalls everything, slowing CI.
pip install --no-cache-dir in images to control size vs host cache tradeoffs.kubectl from subprocess — client library gives structured errors and retries.ps.manylinux).asyncio, encoding defaults). Roll forward with automated AMIs or GitOps image bumps; keep rollback tag.pyupgrade or Ruff rules to modernize syntax after upgrade.
WorkingDirectory breaking relative paths; missing venv in ExecStart; buffered stdout hiding logs (use PYTHONUNBUFFERED=1 or -u); user permissions; Restart= policies masking crash loops.EnvironmentFile or drop-ins for secrets; use Type=notify only if the app supports sd_notify.