Skip to main content

Create and run uv scripts with POSIX standardized shebang line

Project description

uvrs

This program is meant to be used in a shebang line, like this:

#!/usr/bin/env uvrs

Unlike the shebang line recommended by uv's documentation, the above shebang does not rely on the non-standard -S option (see uv issue 11876).

Installation

This should be installed as a globally available tool (so the above shebang line works):

uv tool install -p 3.14 uvrs

That will install uvrs using Python 3.14 (for nicely colorized help text).

Primary Usage

The primary purpose of the uvrs command is to accept a filename to be run as a uv script.

The uvrs command is not designed to run a script on its own. If you need to run a script, use uv run for that.

The uvrs command can also be used to:

  1. Create new uv scripts with a uvrs shebang line
  2. Update existing uv scripts to use a uvrs shebang line

Creating new uv scripts

To initialize a new uv script with a uvrs shebang line use the init command:

uvrs init ~/bin/my-script --python 3.12

This will create the file ~/bin/my-script using uv init --script ~/bin/my-script --python 3.12 and then add an appropriate shebang line to the beginning of the script:

#!/usr/bin/env uvrs
# /// script
# requires-python = ">=3.12"
# dependencies = []
# ///


def main() -> None:
    print("Hello from my-script!")


if __name__ == "__main__":
    main()

Updating existing uv scripts

To update an existing uv script to use the uvrs shebang, use the fix command:

uvrs fix ~/bin/my-script

If the file does not yet have a shebang line, this shebang line will be added:

#!/usr/bin/env uvrs

If the file being fixed already has a shebang line which uses uv run, the shebang will be updated to use uvrs instead.

Managing dependencies

To update the dependencies within inline script metadata, use uvrs add and uvrs remove.

To add a new dependency:

uvrs add ~/bin/my-script 'rich'

This runs uv add --script ~/bin/my-script 'rich' followed by uv sync --script ~/bin/my-script, so the dependency is installed immediately.

To remove a new dependency:

uvrs remove ~/bin/my-script 'rich'

This runs uv remove --script ~/bin/my-script 'rich' and then uv sync --script ~/bin/my-script to keep the resolved environment up to date.

The goal

Eventually, I would like to see a similar tool integrated into uv.

Until that time, I plan to maintain this uvrs tool.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uvrs-0.6.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uvrs-0.6.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file uvrs-0.6.1.tar.gz.

File metadata

  • Download URL: uvrs-0.6.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for uvrs-0.6.1.tar.gz
Algorithm Hash digest
SHA256 f1d28ce704f18607dc6c9a358356ed6261bca4db3f504d4bfd33595c42090cf3
MD5 947cbba9396c9e85b952406fc67e26f1
BLAKE2b-256 a901088da044d6849e16be17e27a14bc46c618e0e2e15d75ad4c3fc6fdd1fcdd

See more details on using hashes here.

File details

Details for the file uvrs-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: uvrs-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for uvrs-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c5f11560be3f8a01d439c740e088513758bacd226fdae64d64d1d97f67cd545e
MD5 f124b07aa5f37d5f47b69f1a4bab12e9
BLAKE2b-256 efe589e32218659e46a32b699b8e02d892442e80304dd3e6a14ef06a63f9cb3d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page