uv

uv
Author

Benedict Thekkel

🔧 Key Commands and Their Usage

1. uv init <project-name>Initializes a new Python project, creating essential files like pyproject.toml, .python-version, and a sample script

Example:

uv init my_project

2. uv add <package>Adds a package to the project’s dependencies and updates pyproject.toml

Example:

uv add flask

3. uv remove <package>Removes a package from the project’s dependencies and updates pyproject.toml

Example:

uv remove flask

4. uv syncSynchronizes the project’s environment with the dependencies specified in pyproject.toml

Example:

uv sync

5. uv lockGenerates or updates the uv.lock file, locking the exact versions of dependencies

Example:

uv lock

6. uv run <script.py>Runs a Python script within the project’s environment

Example:

uv run app.py

7. uv python install <version>Installs a specific Python version for the project

Example:

uv python install 3.11

8. uv python use <version>Sets the project’s Python version to the specified version

Example:

uv python use 3.11

9. uv pip install <package>Installs a package using pip within the project’s environment

Example:

uv pip install requests

10. uv pip uninstall <package>Uninstalls a package using pip within the project’s environment

Example:

uv pip uninstall requests

🧰 Additional Features

  • uv tool run <command> Executes a command provided by a Python package without installing it globally.

  • uv tool install <tool> Installs a command-line tool provided by a Python package.

  • uv venv Creates a virtual environment for the project.

  • uv version Displays the current version of uv.

  • uv help Provides help and documentation for uv commands.


✅ Advantages of Using uv

  • Speeduv is significantly faster than traditional package managers like pip, offering 10–100x speed improvements for package installation and dependency resolution

  • Unified Tooling Combines the functionalities of multiple tools into one, simplifying the development workflow.

  • Reproducibility Ensures consistent environments with pyproject.toml and uv.lock files.

  • Python Version Management Easily switch between Python versions within projects.

  • Environment Isolation Manages project-specific environments to avoid dependency conflicts.

Back to top