uv
🔧 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_project2. uv add <package>Adds a package to the project’s dependencies and updates pyproject.toml
Example:
uv add flask3. uv remove <package>Removes a package from the project’s dependencies and updates pyproject.toml
Example:
uv remove flask4. uv syncSynchronizes the project’s environment with the dependencies specified in pyproject.toml
Example:
uv sync5. uv lockGenerates or updates the uv.lock file, locking the exact versions of dependencies
Example:
uv lock6. uv run <script.py>Runs a Python script within the project’s environment
Example:
uv run app.py7. uv python install <version>Installs a specific Python version for the project
Example:
uv python install 3.118. uv python use <version>Sets the project’s Python version to the specified version
Example:
uv python use 3.119. uv pip install <package>Installs a package using pip within the project’s environment
Example:
uv pip install requests10. 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 venvCreates a virtual environment for the project.uv versionDisplays the current version ofuv.uv helpProvides help and documentation foruvcommands.
✅ Advantages of Using uv
Speed
uvis significantly faster than traditional package managers likepip, offering 10–100x speed improvements for package installation and dependency resolutionUnified Tooling Combines the functionalities of multiple tools into one, simplifying the development workflow.
Reproducibility Ensures consistent environments with
pyproject.tomlanduv.lockfiles.Python Version Management Easily switch between Python versions within projects.
Environment Isolation Manages project-specific environments to avoid dependency conflicts.