Command Cheat Sheet
Command Cheat Sheet
Commands this book actually uses. Run them from the directory that holds the file or the pyproject.toml.
Python
| Command | What it does |
|---|---|
uv run python file.py |
Run a program with the project’s Python 3.14 |
uv run python -c "print('desk')" |
Run a one-liner |
uv run python -m cProfile -s tottime file.py |
Profile a program |
Inside a program, spawn that same interpreter with sys.executable, not a bare python on PATH.
uv
| Command | What it does |
|---|---|
uv lock |
Write/update the lockfile |
uv sync |
Install the locked environment |
uv add pkg |
Add a dependency |
uv build |
Build sdist + wheel into dist/ |
uv audit |
Scan locked deps for known issues |
uv pip install dist/*.whl |
Install a wheel you just built |
ruff
| Command | What it does |
|---|---|
uv run ruff check . |
Lint |
uv run ruff check --fix file.py |
Lint and apply safe fixes |
uv run ruff format . |
Format |
Silence is success for ruff check.
pytest
| Command | What it does |
|---|---|
uv run pytest |
Run tests |
uv run pytest -q |
Quieter |
uv run pytest path/to/test_file.py |
One file |
Tiny reminders
Run a complete program:
uv run python hello.py# hello.py
def main() -> None:
print("desk is open")
if __name__ == "__main__":
main()desk is open
Child process (list of args, no shell):
# run_child.py
import subprocess
import sys
def main() -> None:
result = subprocess.run(
[sys.executable, "-c", "print('ticket 7')"],
capture_output=True,
text=True,
check=True,
)
print(result.stdout, end="")
if __name__ == "__main__":
main()uv run python run_child.pyticket 7
Secrets stay in the environment (DESK_API_KEY), never in the file you commit.
Times you store are UTC (datetime.now(timezone.utc)), not naive local clocks.
Text files: Path.read_text(encoding="utf-8") and write_text(..., encoding="utf-8").