Hasty Briefsbeta

Bilingual

Self-contained Python scripts with uv

a year ago
  • #Uv
  • #Scripting
  • #Python
  • Using `uv` in the shebang line makes Python scripts self-contained executables.
  • The script `jam_users.py` interacts with an API to manage test users, leveraging `httpx`, `IPython`, and `loguru`.
  • Traditional methods require global installation or virtual environments, which `uv` simplifies.
  • Embedding dependencies in script comments with `# /// script` tags allows `uv` to handle them automatically.
  • Making the script executable with `chmod +x` and a custom shebang (`#!/usr/bin/env -S uv run --script`) enables direct execution.
  • This approach eliminates dependency and virtual environment management, making scripts portable across Unix systems with `uv` installed.