uv-init
Initialize uv project environments
TLDR
Initialize a project in the current directory
Initialize a project with a certain name
Create a project in a given directory
Create a project for a Python library
Specify the build system
Only create a pyproject.toml
Set the project description
SYNOPSIS
The concept of 'uv-init' typically involves:
uv venv [LOCATION] [OPTIONS]
uv install [PACKAGES...] [OPTIONS]
uv sync [OPTIONS]
PARAMETERS
LOCATION
For `uv venv`, the directory path where the new virtual environment should be created (e.g., `.venv`). If omitted, creates it in `.venv` in the current directory.
--python PYTHON_EXECUTABLE_PATH
Specifies the path to the Python interpreter to use for creating the virtual environment or for dependency resolution during installation. Example: `--python /usr/bin/python3.10`.
--python-version VERSION
Specifies a Python version (e.g., `3.10`, `3.11`) to use for the environment or for resolving dependencies. `uv` will attempt to locate or download the specified version.
--seed
For `uv venv`, ensures that essential tools like `pip` are installed within the newly created virtual environment. This is typically the default behavior.
--name NAME
For `uv venv`, assigns a custom name to the virtual environment. This name might be used for easier reference, especially when managing multiple environments.
-r FILE, --requirement FILE
For `uv install` or `uv sync`, specifies a path to a requirements file (e.g., `requirements.txt`) containing a list of packages and their versions to install.
--dev
For `uv install` or `uv sync`, includes development dependencies (e.g., from `[project.optional-dependencies.dev]` in `pyproject.toml` if supported by the project layout).
--offline
For `uv install` or `uv sync`, prevents `uv` from accessing the network. It will only use packages available in its local cache, useful for offline development or reproducible builds.
--strict
For `uv install` or `uv sync`, enforces strict dependency resolution. If `uv` detects any conflicting package versions that cannot be resolved, the command will fail rather than attempting a less strict installation.
[PACKAGES...]
For `uv install`, a space-separated list of package names (and optional version specifiers) to install directly into the active environment (e.g., `uv install 'requests<3' Flask`).
DESCRIPTION
The command `uv-init` is not a standard, standalone Linux command. Instead, it refers to the process of initializing a Python project and its development environment using the `uv` tool. `uv` is a modern, fast, and robust Python package installer and resolver, designed as a direct replacement for `pip` and `virtualenv`, and a viable alternative to `pip-tools`, `Poetry`, or `Pipenv`.
Project initialization with `uv` primarily involves two key steps:
1. Environment Creation: Using `uv venv` to create an isolated Python virtual environment where project dependencies will be installed.
2. Dependency Installation: Utilizing `uv install` or `uv sync` to install required packages, typically specified in a `requirements.txt` file or `pyproject.toml`'s `[project.dependencies]` section.
This combined workflow effectively initializes a new Python project, setting up its dedicated environment and installing its initial set of dependencies, making `uv` a powerful tool for streamlining Python development workflows.
CAVEATS
It is crucial to understand that `uv-init` is not a literal command you can type and execute. It is a conceptual term referring to the initialization actions performed using the `uv` tool, primarily `uv venv` and `uv install` or `uv sync`. `uv` itself is a relatively new and rapidly evolving tool; while stable, its exact command structure and features may see minor adjustments in future versions. Users should ensure they have `uv` installed (e.g., via `curl -LsSf https://astral.sh/uv/install.sh | sh`) before attempting these operations.
COMMON INITIALIZATION WORKFLOW
A typical `uv` initialization workflow for a new Python project usually follows these steps:
1. Create a virtual environment: uv venv .venv
2. Activate the environment: source .venv/bin/activate (on Linux/macOS) or .venv\Scripts\activate (on Windows)
3. Install dependencies from a file: uv sync (if `pyproject.toml` or `requirements.txt` exists) or uv install -r requirements.txt
This sequence ensures an isolated, reproducible, and performant development setup.
WHY USE UV FOR INITIALIZATION?
`uv` offers significant advantages for project initialization and ongoing dependency management:
1. Speed: It is orders of magnitude faster than `pip` and `conda` for resolving and installing dependencies due to its Rust implementation and efficient algorithms.
2. Reproducibility: `uv`'s robust resolver helps ensure that builds are more consistent across different environments.
3. Unified Tooling: It aims to combine the functionalities of `pip`, `pip-tools`, and `virtualenv` into a single, cohesive command-line interface, simplifying the Python toolchain.
HISTORY
`uv` emerged from `Astral.sh` (formerly `Rye`), an organization dedicated to building fast and efficient tools for Python development. Written in Rust, `uv` was designed from the ground up to address performance and reliability issues present in traditional Python package managers like `pip`. It aims to provide a unified, significantly faster, and more robust experience for dependency resolution and package installation, quickly gaining traction within the Python community since its public announcement in late 2023.