When running multi-line Python code or code with quotes, apostrophes, or f-strings via Bash, always use heredoc syntax instead of python -c to avoid shell quoting issues.
When you need to run Python code via Bash, never use python -c "..." for anything beyond trivial one-liners. Shell quoting breaks with f-strings, apostrophes, nested quotes, and escape sequences.
uv run python << 'PYTHON_CODE'
import json
data = {"name": "it's working", "value": f"{1 + 2}"}
print(json.dumps(data, indent=2))
PYTHON_CODE
The single quotes around 'PYTHON_CODE' prevent shell variable expansion, so $variables and backticks are treated as literal Python code.
uv run --with requests python << 'PYTHON_CODE'
import requests
resp = requests.get("https://api.example.com/data")
print(resp.json())
PYTHON_CODE
uv run python (not bare python or python3)<< 'PYTHON_CODE' (not << PYTHON_CODE)PYTHON_CODE must be on its own line with no leading whitespacepython -c for code containing quotes, f-strings, or multiple statements