uv – Python’s Fastest Package Installer and Resolver : Mike

uv – Python’s Fastest Package Installer and Resolver
by: Mike
blow post content copied from  Mouse Vs Python
click here to view original post

There’s a new Python package installer out now and it’s called uv. The uv package installer and resolver is made by Astral. Uv is written in Rust instead of Python and is super fast! Astral is best known for Python’s fastest formatter, Ruff. The uv package is meant to be a drop-in replacement for pip and pip-tools. According to Astral, “uv is 8-10x faster than pip and pip-tools without caching, and 80-115x faster when running with a warm cache (e.g., recreating a virtual environment or updating a dependency)”.

Astral is also taking over the development of Rye, an experimental Python packaging tool from Armin Ronacher. From the sounds of Astral’s announcement, Rye and uv will become one tool as the two projects have a shared vision for Python packaging.

Installing uv

You can install uv using Curl:

curl -LsSf https://astral.sh/uv/install.sh | sh

Or you can use pip:

pip install uv

Now that you have uv installed, you can start installing packages!

Using uv

Let’s try running uv in your terminal:

c:\code> uv
Usage: uv.exe [OPTIONS] <COMMAND>

  pip    Resolve and install Python packages
  venv   Create a virtual environment
  cache  Manage the cache
  help   Print this message or the help of the given subcommand(s)

  -q, --quiet                  Do not print any output
  -v, --verbose                Use verbose output
      --color <COLOR>          Control colors in output [default: auto] [possible values: auto, always, never]
  -n, --no-cache               Avoid reading from or writing to the cache [env: UV_NO_CACHE=]
      --cache-dir <CACHE_DIR>  Path to the cache directory [env: UV_CACHE_DIR=]
  -h, --help                   Print help (see more with '--help')
  -V, --version                Print version

You’ll need to create and activate a Python virtual environment to install packages with uv.

Here’s an example:

C:\code> uv venv test
Using Python 3.11.5 interpreter at C:\Users\wheifrd\AppData\Local\Programs\Python\Python311\python.exe
Creating virtualenv at: test
Activate with: test\Scripts\activate

C:\code> .\test\Scripts\activate
(test) C:\books>

Now you’re ready to install a Python package. You can use numpy for a test run:

(test) C:\books> uv pip install numpy
Resolved 1 package in 615ms
Downloaded 1 package in 2.81s
Installed 1 package in 332ms
 + numpy==1.26.4

As you might expect, you can also use uv to install:

  • a list of space-delimited packages
  • a requirements.txt file
  • a pyproject.toml file

If you need to generate a locked requirements.txt file, you can run uv pip compile.

Wrapping Up

Astral hopes to create a “Cargo for Python” with the release of uv. While it’s still early, this project is well worth watching as the Rust package itself is amazingly fast and useful even though it’s only been out for about a year. You can read more about uv in Astral’s blog post.


The post uv – Python’s Fastest Package Installer and Resolver appeared first on Mouse Vs Python.

February 27, 2024 at 07:39PM
Click here for more details...

The original post is available in Mouse Vs Python by Mike
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.