Documentation Index
Fetch the complete documentation index at: https://mintlify.com/astral-sh/uv/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Python scripts are single files intended for standalone execution. uv manages script dependencies automatically without requiring manual environment management.Every Python installation has an environment for packages. uv automatically creates isolated virtual environments for scripts and prefers declarative dependencies.
Running scripts without dependencies
Execute any Python script withuv run:
example.py
Scripts with standard library imports
No special setup needed for standard library modules:example.py
Passing arguments
Pass arguments to your script after the script name:example.py
Reading from stdin
Running scripts with dependencies
When your script requires external packages, declare dependencies explicitly. uv creates environments on-demand instead of using long-lived virtual environments.Requesting dependencies per invocation
For a script requiringrich:
example.py
--with:
If used in a project,
--with dependencies are included in addition to project dependencies. Use --no-project to opt-out.Declaring script dependencies
Initialize a script with metadata
Create a script with inline metadata using the PEP 723 format:
Add dependencies
Use This adds a
uv add --script to declare dependencies:script section at the top of your file:example.py
Python version requirements
Specify required Python versions in the script metadata:example.py
Using a shebang for executable scripts
Make scripts executable withoutuv run:
Shebang with dependencies
example
Advanced features
Using alternative package indexes
Specify a custom package index:Locking dependencies
Explicitly lock script dependencies:example.py.lock adjacent to your script. Subsequent operations reuse the locked dependencies.
Improving reproducibility
Limit packages to those released before a specific date:example.py
Using different Python versions
Request arbitrary Python versions per invocation:example.py
GUI scripts (Windows)
On Windows, scripts with.pyw extension run using pythonw:
example.pyw
Complete example
Here’s a complete workflow for creating a self-contained script:Next steps
Command reference
View all uv run options
Using tools
Run and install Python tools
Python versions
Learn about Python version management
Working with projects
Manage multi-file Python projects