You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/1. Initializing/1.3. uv (project).md
+59-49Lines changed: 59 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,13 @@
2
2
description: Discover how to use uv to manage project dependencies and build Python packages, streamlining the process of creating production-ready artifacts.
3
3
---
4
4
5
-
# 1.3. uv (project)
5
+
# 🚀 1.3. uv (project)
6
6
7
-
## What is a package?
7
+
## 📦 What is a package?
8
8
9
-
A [Python package](https://packaging.python.org/en/latest/) is a set of Python modules grouped together that can be installed and used within your projects. Python packages help you manage the functionality of Python by allowing you to add and utilize external libraries and frameworks that are not part of the standard Python library.
9
+
A [Python package](https://packaging.python.org/en/latest/) is a collection of Python modules that can be installed and used in your projects. Packages allow you to leverage external libraries and frameworks, extending Python's built-in capabilities.
10
10
11
-
[uv](https://docs.astral.sh/uv/) simplifies the management of these packages by handling them as dependencies. When using uv, developers can easily specify which packages are needed for their projects through a `pyproject.toml` file. Uv ensures that all specified dependencies are installed in the correct versions, maintaining a stable and conflict-free environment for development. Here’s an example of specifying dependencies with uv:
11
+
[uv](https://docs.astral.sh/uv/) simplifies the management of these packages by treating them as dependencies. With uv, you can declare the packages your project needs in a `pyproject.toml` file. uv then ensures that the correct versions of these dependencies are installed, creating a stable and conflict-free development environment. Here’s a basic example of how to specify dependencies with uv:
You will learn more on how to construct and publish Python Package in the [Package section of this course](../3. Productionizing/3.0. Package.md).
31
31
32
-
## Why do you need a package manager?
32
+
## 🤔 Why do you need a package manager?
33
33
34
-
In the Python ecosystem, the distribution and installation of software through packages is a standard practice. These packages, often available in Wheel or zip formats, encapsulate source code along with vital metadata. Manually handling these packages and their dependencies can quickly become cumbersome, underscoring the need for package managers. Tools like uv automate these processes, boosting productivity and guaranteeing consistent environments across development and deployment.
34
+
In the Python ecosystem, software is typically distributed and installed as packages. These packages, often in Wheel or zip format, contain source code and essential metadata. Manually managing these packages and their dependencies can be a tedious and error-prone process. Package managerslike uv automate these tasks, which boosts productivity and ensures that your development and deployment environments are consistent.
@@ -40,32 +40,31 @@ In the Python ecosystem, the distribution and installation of software through p
40
40
41
41
By default, uv will download and install Python packages from [PyPI](https://pypi.org/), a repository of software for the Python programming language. If needed, [other Python repositories](https://warehouse.pypa.io/repository-projects/) can be configured to provide extra sources of dependencies.
42
42
43
-
## Why should you use uv in your project?
43
+
## ✨ Why should you use uv in your project?
44
44
45
-
Incorporating uv into your project brings several key advantages:
45
+
Using uv in your project offers several key benefits:
46
46
47
-
-**Improved Environment Management**: uv streamlines the management of different project environments, promoting consistent development practices.
48
-
-**Simplified Package Building and Distribution**: It provides a unified workflow for building, distributing, and installing packages, easing the complexities usually associated with these tasks.
49
-
-**Uniform Project Metadata**: uv employs a standardized approach to defining project metadata, including dependencies, authors, and versioning, through a `pyproject.toml` file. This standardization ensures clarity and uniformity.
47
+
-**Improved Environment Management**: uv simplifies the management of project environments, which helps maintain consistency.
48
+
-**Simplified Package Building and Distribution**: It provides a unified workflow for building, distributing, and installing packages, which reduces complexity.
49
+
-**Standardized Project Metadata**: uv uses a standard `pyproject.toml` file to define project metadata, such as dependencies, authors, and versioning. This ensures that your project is easy to understand and maintain.
50
50
51
-
Compared to traditional approaches that involve pip, venv, and manual dependency management, uv offers a more cohesive and friendly experience, merging multiple package and environment management tasks into a single, simplified process.
51
+
Compared to traditional tools like pipand venv, uv provides a more cohesive and user-friendly experience by combining package and environment management into a single, streamlined process.
52
52
53
-
## How can you use uv for your MLOps project?
53
+
## 🛠️ How can you use uv for your MLOps project?
54
54
55
-
Integrating uv into your MLOps project involves several key steps designed to configure and prepare your development environment:
55
+
To integrate uv into your MLOps project, you can follow these steps to set up your development environment:
56
56
57
57
- Begin by creating a new project directory and navigate into it.
58
58
- Run `uv init` in your terminal. This command starts an interactive guide to help set initial project parameters, such as package name, version, description, author, and dependencies. This step generates a `pyproject.toml` file, crucial for your project's configuration under uv.
59
59
- Run `uv sync` to install the project dependencies and source code. This will let you access your project code through `uv run` and its command-line utilities.
60
60
61
-
The `pyproject.toml` file plays a central role in defining your project’s dependencies and settings.
61
+
The `pyproject.toml` file is central to defining your project's dependencies and settings. Let's break down a typical example:
-**`[project]`**: This section contains general metadata about your project, such as its name, version, and description.
106
+
-**`dependencies`**: This is a list of the main dependencies that your project needs to run.
107
+
-**`[project.urls]`**: This section allows you to include helpful links, such as to the project's homepage or documentation.
108
+
-**`[project.scripts]`**: Here, you can define command-line scripts that will be created when your package is installed.
109
+
-**`[build-system]`**: This section specifies the build tool that `uv` will use to create your package.
110
+
121
111
At the end of the installation process, a `uv.lock` file is generated with all the project dependencies that have been installed. You can remove and regenerate the `uv.lock` file if you wish to update the list of dependencies.
122
112
123
-
## How can you install dependencies for your project with uv?
113
+
## ➕ How can you install dependencies for your project with uv?
124
114
125
-
Uv differentiates between main (production) and development dependencies, offering an organized approach to dependency management. To add dependencies, use the following commands:
115
+
uv distinguishes between main (production) and development dependencies, which allows for a more organized approach to dependency management. To add dependencies, you can use the following commands:
126
116
127
117
```bash
128
118
# For main dependencies
@@ -134,13 +124,13 @@ $ uv add --group dev ipykernel
134
124
135
125
Executing these commands updates the `pyproject.toml` file, accurately managing and versioning your project's dependencies.
136
126
137
-
## What is the difference between main and dev dependencies in uv?
127
+
## Main vs. Dev Dependencies in uv
138
128
139
-
In uv, dependencies are divided into two types: [main dependencies](https://docs.astral.sh/uv/concepts/projects/dependencies/#project-dependencies) and [development (dev) dependencies](https://docs.astral.sh/uv/concepts/projects/dependencies/#development-dependencies).
129
+
In uv, dependencies are categorized into two types: [main dependencies](https://docs.astral.sh/uv/concepts/projects/dependencies/#project-dependencies) and [development (dev) dependencies](https://docs.astral.sh/uv/concepts/projects/dependencies/#development-dependencies).
140
130
141
-
**Main Dependencies**: These are essential for your project's production environment—your application can't run without them. For example, libraries like Pandas or XGBoost would be main dependencies for an MLOps project.
131
+
-**Main Dependencies**: These are essential for your project to run in a production environment. For example, libraries like pandas or scikit-learn are typically main dependencies in an MLOps project.
142
132
143
-
**Development Dependencies**: These are used only during development and testing, such as testing frameworks (e.g., pytest) or linters (e.g., ruff). They are not required in production.
133
+
-**Development Dependencies**: These are only used for development and testing purposes. Examples include testing frameworks like `pytest` or linters like `ruff`. They are not required for the application to run in production.
144
134
145
135
Here’s a simple example in a `pyproject.toml` file:
146
136
@@ -158,11 +148,31 @@ dev = [
158
148
159
149
This setup helps keep production environments lean by excluding unnecessary development tools.
160
150
161
-
## Can you use uv to download Python dependencies from your own organization's code repository?
151
+
## 🏢 Using Custom Repositories
152
+
153
+
uv supports [custom package repositories](https://docs.astral.sh/uv/concepts/projects/dependencies/#dependency-sources), including private and organizational ones. This allows you to use proprietary packages alongside those from the public PyPI. You can easily add a custom repository and configure authentication using uv's commands, which ensures secure and flexible dependency management.
154
+
155
+
## ⚡ Common `uv` Commands
156
+
157
+
Here is a quick reference for some of the most common `uv` commands:
158
+
159
+
-**`uv init`**: Initializes a new project by creating a `pyproject.toml` file.
160
+
-**`uv add`**: Adds a new dependency to your project.
161
+
-**`uv sync`**: Installs the dependencies listed in your `pyproject.toml` file.
162
+
-**`uv run`**: Executes a command in the project's virtual environment.
163
+
164
+
## 🔒 The `uv.lock` File
165
+
166
+
The `uv.lock` file is generated after you install your project's dependencies. It records the exact versions of all the packages that were installed, including their dependencies. This is crucial for ensuring that your project is reproducible. When you share your project with others, they can use the `uv.lock` file to create an identical environment, which helps to avoid bugs and inconsistencies.
167
+
168
+
## 🔑 Key Takeaways
162
169
163
-
Uv supports incorporating [custom package repositories, including private or organizational ones](https://docs.astral.sh/uv/concepts/projects/dependencies/#dependency-sources). This capability allows for the use of proprietary packages in conjunction with those from the public PyPI. Adding a custom repository and setting up authentication is facilitated by uv's configuration commands, offering secure and adaptable dependency management.
170
+
-**Unified Tool**: `uv` streamlines Python project management by combining the functionalities of `pip`, `venv`, `pipx`, and `pyenv` into a single, fast tool.
171
+
-**`pyproject.toml`**: This file is central to `uv` projects, defining metadata, dependencies (main and development), and build configurations.
0 commit comments