python

15 commands

15 shown

Create virtual environment Create and activate an isolated Python environment python3 -m venv .venv && source .venv/bin/activate #python Install from requirements Install dependencies without using pip cache pip install -r requirements.txt --no-cache-dir #python Freeze installed packages Save exact versions of all installed packages pip freeze > requirements.txt #python Show outdated packages List packages with newer versions available pip list --outdated --format=columns #python Run module as script Serve current directory over HTTP on port 8080 python3 -m http.server 8080 #python One-liner JSON pretty print Pretty-print a JSON file using stdlib python3 -m json.tool < input.json #python Profile script CPU profiling sorted by cumulative time python3 -m cProfile -s cumulative script.py | head -30 #python#performance#debug Debug with pdb Start script under the Python debugger python3 -m pdb script.py #python#debug Set breakpoint in code Built-in breakpoint() is equivalent to import pdb; pdb.set_trace() breakpoint() # Python 3.7+ — drops into pdb at this line #python#debug Run tests with pytest Stop at first failure, verbose, short traceback pytest -x -v --tb=short tests/ #python#debug Check syntax without running Compile to bytecode only to catch syntax errors python3 -m py_compile script.py && echo OK #python#debug Format code with black Preview changes then apply Black formatting black --check --diff . && black . #python Lint with ruff Fast linter + auto-fix (replaces flake8, isort, pyupgrade) ruff check . --fix #python Type check with mypy Strict static type checking for a package mypy --strict --ignore-missing-imports src/ #python#debug Inspect object attributes List public attributes of any Python object python3 -c "import json; print([x for x in dir(json) if not x.startswith('_')])" #python#debug
no commands match