Skip to main content

Streamlined Script Execution with uvr

uv is a blazing fast, modern Python package manager and workflow tool. However, its project-centric design (uv run) prioritizes the current working directory (CWD) when looking for virtual environments and pyproject.toml files. This makes it cumbersome to execute a project-dependent script from outside its root directory, as it forces you to manually pass the --project flag with the absolute path to the script's home.

uvr (uv-runner) acts as an intelligent wrapper that resolves this pain point. It automatically detects the correct project context relative to the script being executed, allowing you to use a clean shebang (#!/usr/bin/env uvr) or call:

uvr [options] script.py

instead of:

uv run --project /path/to/script/project [options] /path/to/script/project/script.py

Key Value: It restores the true portability of standalone and project-tied Python scripts without polluting your command line or breaking your workflow when moving between directories. It also supports an optional offline mode that runs scripts directly against a project .venv without invoking uv run.

Project Virtual Environments

  • If VIRTUAL_ENV points to a usable environment, uvr prefers it. Otherwise, uvr searches upward from the script directory (or current directory for a command) for a project .venv.
  • Python scripts run directly with that environment's interpreter. Commands such as pytest run directly from its bin directory on Unix or Scripts directory on Windows. The selected environment is not synchronized by uv.
  • A uv project without a .venv keeps the normal uv run bootstrap behavior when online. A Poetry project without a usable .venv fails with an error instead of being passed to uv run.

Installation

Prerequisite: uv must be installed and available on your PATH.

To install uvr, use the following command:

uv tool install uvr

To upgrade uvr, use the following command:

uv tool upgrade uvr

Windows Console Modes

Two entry points are installed:

  • uvr — console application. Use from a terminal or for scripts that need a command-line window.
  • uvr-gui — GUI application. Use for scripts started by double-click or for GUI-only programs that must not open a console window.

On Linux and macOS both commands behave the same.

Usage

Several ways to run your Python scripts with uv:

  1. Using uv run --project <project_path> <script_path>:

    • This command explicitly tells uv to run the specified Python script within the context of the project located at <project_path>.

    • This is useful when your script relies on dependencies defined within a specific project directory but is executed from elsewhere.

    • Example:

      uv run --project /path/to/project [options] /path/to/project/script.py [script_options]
      
  2. Using uvr script.py:

    • This is a more direct way to execute your Python script (script.py) using uvr.

    • uvr automatically determines the project directory based on the script path, effectively mimicking the --project flag's behavior.

    • Example:

      uvr [options] [--] script.py [script_options]
      
    • For ambiguity and edge cases, use -- (see the section General Rule for Using the -- Separator).

  3. Shebang Usage:

    • Example:

      #!/usr/bin/env -S uvr [options] [--]
      # Your Python code here...
      
    • Note on -S flag: The -S flag allows passing multiple arguments to the interpreter. It is optional if your env implementation supports it (most modern systems do). However:

      • Without -S: You can only use #!/usr/bin/env uvr without additional options or parameters
      • With -S: You can pass options like #!/usr/bin/env -S uvr --with dep1 --
      • Some older or minimal Unix-like systems may not support the -S flag in env
    • If you pass script arguments, use -- to separate uvr/uv options from script arguments.

  4. Scripts without .py or .pyw extension:

    • Automatic --script option is added if not already present (--script or --gui-script) in options.

    • Without this, uv can in some cases mis-handle execution flow.

    • Example: For a foo script:

      #!/usr/bin/env -S uvr [options] [--]
      # Your Python code here...
      

      This will be executed as uv run [options] --script ... if [options] do not already contain --script or --gui-script.

    • Or, to be more explicit, you can include the --script flag directly in the shebang:

      #!/usr/bin/env -S uvr --script
      
    • Important Exception for Non-Files: If the identified script_path (the argument immediately following options or --) does not point to an actual file on disk, uvr will not automatically add the --script or --gui-script option. This behavior ensures uvr can correctly pass through commands that are executables within the virtual environment (e.g., uvr black ., uvr pytest), rather than a Python script file.

  5. Debug usage:

    • Example:
      uvr -v [options] [--] script.py [script_options]
      uvr -vv [options] [--] script.py [script_options]
      
  6. Offline mode: - When UV_OFFLINE=1 is set or --offline is passed among the uvr pre-options, uvr runs directly from the selected local environment and never invokes uv run. - Offline mode requires a usable environment. Python scripts need its interpreter; commands need to exist in that environment. If either is missing, uvr reports an error instead of trying to bootstrap anything. - This skips uv dependency resolution and lockfile checks entirely. It is stricter than uv --offline, which still runs uv and only disables network access.

    • Examples:
      UV_OFFLINE=1 uvr script.py
      uvr --offline script.py
      uvr --offline -- script.py --some-script-arg
      uvr --offline pytest -q
      

General Rule for Using the -- Separator

The -- argument functions as a standard command-line delimiter. It explicitly separates options intended for uvr (and its underlying uv process) from arguments specifically designated for the Python script being executed.

Arguments appearing before the -- are processed by uvr (uv). Arguments appearing after the -- are passed directly to the invoked Python script.

This explicit separation is crucial for:

  • Preventing Ambiguity: uvr employs a basic heuristic to identify the script path (the first non-hyphenated argument). This can lead to misinterpretation if the script itself accepts options that resemble uvr/uv arguments.

  • Ensuring Precise Argument Passing: By using --, users guarantee that all subsequent arguments are correctly delivered to their script, bypassing uvr's argument parsing logic.

Recommendation: Utilize the -- separator whenever precise control over argument distribution between uvr/uv and the target script is required.

Ctrl+C (SIGINT) Handling

uvr handles KeyboardInterrupt to provide clean CLI behavior when interrupted with Ctrl+C.

  • It suppresses Python traceback noise (unwanted junk output) on user interruption.
  • It exits with status code 130, following the common Unix convention: 128 + 2 (SIGINT is signal number 2).
  • This keeps output clean while still signaling to the parent shell/process that execution was interrupted.

Platform note:

  • On Linux and macOS, 130 matches the common signal-derived convention (128 + SIGINT 2).
  • On Windows, 130 is used intentionally as a consistent, cross-platform interruption code for uvr.

Security Notes

uvr is a convenience wrapper around uv run. It does not add privileges by itself, but it will execute the script/command you pass to it.

Main risks:

  • Running untrusted scripts can execute arbitrary code.
  • Untrusted dependency sources can introduce supply-chain risk.
  • Running as root/Administrator increases impact if something goes wrong.
  • A compromised PATH could resolve a malicious uv binary.

Recommended protections:

  • Run only trusted scripts and trusted dependency sources.
  • Do not run uvr as root/Administrator unless strictly required.
  • In CI, pin dependencies and use a lockfile where possible.
  • Prefer explicit script paths for automation (script.py) over ambiguous invocations.
  • Keep build/runtime environments isolated (virtual environments, containers, CI runners).
  • Ensure your PATH resolves to the expected uv executable.

Scope note:

  • uvr is not a sandbox. It is a command runner helper and should be used with standard secure development practices.

Metadata

Release files for uvr 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for uvr 0.2.0
File Size Uploaded Provenance Actions
uvr-0.2.0.tar.gz 8.6 kB Without provenance Details for uvr-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for uvr 0.2.0
File Interpreter ABI Platform Actions
uvr-0.2.0-py3-none-any.whl Python 3 none any Details for uvr-0.2.0-py3-none-any.whl

Total release size: 17.7 kB

Release files / uvr-0.2.0.tar.gz

Download URL uvr-0.2.0.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4c30db7452088f4e2f884cdce59a61ac385a8791882673977f2f510b63b72513
BLAKE2b-256 checksum
How to use checksums
819586f04033e7c905998ebe344ebf25790f6cb5a25c00e94d37406b5914bad4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.24

Release files / uvr-0.2.0-py3-none-any.whl

Download URL uvr-0.2.0-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1fcdbed94acde25e55d49cc63faa6cda05e96c64b48b1a51b89611d71c0cb53f
BLAKE2b-256 checksum
How to use checksums
b4094b78620bc23a7de0e26376c31df62ac873beb84b6c9e2e07b317529b434f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.24

Security for uvr 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page