<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Zeyang Lin</title>
    <description>The latest articles on Forem by Zeyang Lin (@linzeyang).</description>
    <link>https://forem.com/linzeyang</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F854737%2F45ccb943-5a4a-434d-a0fb-7f1ecfa0aca9.jpeg</url>
      <title>Forem: Zeyang Lin</title>
      <link>https://forem.com/linzeyang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/linzeyang"/>
    <language>en</language>
    <item>
      <title>UV is the latest attempt to rule All Python tools</title>
      <dc:creator>Zeyang Lin</dc:creator>
      <pubDate>Fri, 01 Mar 2024 08:23:18 +0000</pubDate>
      <link>https://forem.com/linzeyang/uv-is-the-latest-attempt-to-rule-all-python-tools-4j24</link>
      <guid>https://forem.com/linzeyang/uv-is-the-latest-attempt-to-rule-all-python-tools-4j24</guid>
      <description>&lt;p&gt;In short, &lt;a href="https://github.com/astral-sh/uv"&gt;&lt;code&gt;uv&lt;/code&gt;&lt;/a&gt; is a command line tool written in &lt;a href="https://www.rust-lang.org/"&gt;&lt;code&gt;Rust&lt;/code&gt;&lt;/a&gt; for &lt;code&gt;Python&lt;/code&gt; developers, which aims to be &lt;em&gt;"a comprehensive project and package manager that is extremely fast, reliable, and easy to use"&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If you are still interested, I hope you can spend a couple of minutes so that I can give you a quick tour of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick fact sheet
&lt;/h2&gt;

&lt;p&gt;language: Rust&lt;/p&gt;

&lt;p&gt;version: 0.1.13 (at the time of writing)&lt;/p&gt;

&lt;p&gt;repo: &lt;a href="https://github.com/astral-sh/uv"&gt;github&lt;/a&gt; (7.7k stars)&lt;/p&gt;

&lt;p&gt;pypi: &lt;a href="https://pypi.org/project/uv/"&gt;pypi&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;docs: N/A&lt;/p&gt;

&lt;p&gt;supported python versions: 3.8 through 3.12 (inclusive)&lt;/p&gt;

&lt;p&gt;supported os: Windows, Linux, MacOS&lt;/p&gt;

&lt;h2&gt;
  
  
  Drop-in replacement for pip and more
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;uv&lt;/code&gt; is from the creator of &lt;a href="https://github.com/astral-sh/ruff"&gt;&lt;code&gt;ruff&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://github.com/charliermarsh"&gt;Charlie Marsh&lt;/a&gt; and &lt;a href="https://github.com/astral-sh/"&gt;astralsh&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ruff&lt;/code&gt;, the linting and formating tool written is Rust as well, has already gain fame and popularity during the past year or so, and I believe many of Python developers have been using it for quite a while.&lt;/p&gt;

&lt;p&gt;And &lt;code&gt;uv&lt;/code&gt; is no doubt their next step in improving the Python toolchain eco.&lt;/p&gt;

&lt;p&gt;Although you can easily install &lt;code&gt;uv&lt;/code&gt; using &lt;code&gt;pip&lt;/code&gt; or &lt;code&gt;pipx&lt;/code&gt; just like any other Python tool,&lt;br&gt;
essentially it does not rely on your Python interpreter to be installed.&lt;/p&gt;

&lt;p&gt;It provides just the binary executable and you can get it easily by running the quick script following&lt;br&gt;
the insructions in its git repo. And that's it, no Python or Rust runtime required till this point.&lt;/p&gt;

&lt;p&gt;Creating a virtual environment is now as easy as &lt;code&gt;uv venv&lt;/code&gt;, though you now need at least one Python interpreter ready to make it work.&lt;/p&gt;

&lt;p&gt;The virtual env it creates is just a standard Python venv, except it does not include &lt;code&gt;pip&lt;/code&gt; by default (however if you need pip you can let it be included by using extra flag, or install it manually after).&lt;/p&gt;

&lt;p&gt;Some of your daily (pip) commands can then be like (but faster):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uv pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt
uv pip &lt;span class="nb"&gt;install &lt;/span&gt;&lt;span class="nv"&gt;black&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;24.2.0
uv pip compile pyprojects.toml &lt;span class="nt"&gt;-o&lt;/span&gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Fast in deed
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fha0hlrbdnbuu0hy9t6qk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fha0hlrbdnbuu0hy9t6qk.png" alt="speed-comparison-1" width="800" height="211"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcopw4cf7dksx5bzp7c3o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcopw4cf7dksx5bzp7c3o.png" alt="speed-comparison-2" width="800" height="189"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just like &lt;code&gt;ruff&lt;/code&gt; is known as being an extremely fast linter, &lt;code&gt;uv&lt;/code&gt;'s speed is also impressive.&lt;/p&gt;

&lt;p&gt;Here is a short &lt;code&gt;requirements.txt&lt;/code&gt; from one of my repos:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fastapi==0.109.2
pydantic[email]==2.6.1
python-multipart==0.0.9
uvicorn[standard]==0.27.1

coverage&amp;gt;=7.4.0
httpx&amp;gt;=0.26.0
memray&amp;gt;=1.11.0
pytest&amp;gt;=8.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And I gave &lt;code&gt;uv&lt;/code&gt; a try using github actions. The result on &lt;code&gt;ubuntu-latest&lt;/code&gt; with Python 3.12 looks like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; Run uv pip install -r requirements.dev.txt
Resolved 40 packages in 185ms
Downloaded 40 packages in 268ms
Installed 40 packages in 24ms
 + annotated-types==0.6.0
 + anyio==4.3.0
 + certifi==2024.2.2
 + click==8.1.7
 + coverage==7.4.2
 + dnspython==2.6.1
 + email-validator==2.1.0.post1
 + fastapi==0.109.2
 + h11==0.14.0
 + httpcore==1.0.3
 + httptools==0.6.1
 + httpx==0.26.0
 + idna==3.6
 + iniconfig==2.0.0
 + jinja2==3.1.3
 + linkify-it-py==2.0.3
 + markdown-it-py==3.0.0
 + markupsafe==2.1.5
 + mdit-py-plugins==0.4.0
 + mdurl==0.1.2
 + memray==1.11.0
 + packaging==23.2
 + pluggy==1.4.0
 + pydantic==2.6.1
 + pydantic-core==2.16.2
 + pygments==2.17.2
 + pytest==8.0.1
 + python-dotenv==1.0.1
 + python-multipart==0.0.9
 + pyyaml==6.0.1
 + rich==13.7.0
 + sniffio==1.3.0
 + starlette==0.36.3
 + textual==0.52.1
 + typing-extensions==4.9.0
 + uc-micro-py==1.0.3
 + uvicorn==0.27.1
 + uvloop==0.19.0
 + watchfiles==0.21.0
 + websockets==12.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, this process, including solving the dependencies, downloading them and installing them, took just &lt;strong&gt;less than half a second&lt;/strong&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  Features in need
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;uv&lt;/code&gt;'s vision, according to the blog, is&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;a single binary that bootstraps your Python installation and gives you everything you need to be productive with Python, bundling not only pip, pip-tools, and virtualenv, but also pipx, tox, poetry, pyenv, ruff, and more.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And appearantly at the current point, it is still quite far away from that.&lt;/p&gt;

&lt;p&gt;The only major top-level sub-commands the cli currently supports are&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;venv&lt;/li&gt;
&lt;li&gt;pip&lt;/li&gt;
&lt;li&gt;cache&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It thus can only create a virtual environment, install dependencies into it and outputs a "lock" file, etc.&lt;/p&gt;

&lt;p&gt;I want it to list installed packages, or run commands using the interpreter inside the virtual env, just like what &lt;code&gt;poetry&lt;/code&gt; is capable of right now.&lt;/p&gt;

&lt;p&gt;Not to mention that it cannot run tests, switch virtual environments or lint source files.&lt;/p&gt;

&lt;p&gt;But it's still in its early age, and the pace is like one patch version every couple of days, isn't it?&lt;/p&gt;

&lt;h2&gt;
  
  
  What about Rye
&lt;/h2&gt;

&lt;p&gt;The ambitions of &lt;code&gt;uv&lt;/code&gt; share a lot with those from &lt;code&gt;Rye&lt;/code&gt;, a tool (which happens to be written in Rust as well) created by Armin Ronacher, the creator of &lt;code&gt;Flask&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What's more, the team behind &lt;code&gt;uv&lt;/code&gt;, &lt;code&gt;astralsh&lt;/code&gt;, is actually taking over the dev work of &lt;code&gt;Rye&lt;/code&gt; according to their &lt;a href="https://astral.sh/blog/uv"&gt;blog&lt;/a&gt;, and ultimately going to migrate &lt;code&gt;Rye&lt;/code&gt; to &lt;code&gt;uv&lt;/code&gt; in the future.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We saw this as a rare opportunity to team up, and to avoid fragmenting the Python ecosystem. As such, in collaboration with Armin, we're excited to be taking over Rye. Our goal is to evolve uv into a production-ready "Cargo for Python", and to provide a smooth migration path from Rye to uv when the time is right.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Some thoughts
&lt;/h2&gt;

&lt;p&gt;The name &lt;code&gt;uv&lt;/code&gt; seems not relevant to &lt;a href="https://github.com/libuv/libuv"&gt;&lt;code&gt;libuv&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://github.com/MagicStack/uvloop"&gt;&lt;code&gt;uvloop&lt;/code&gt;&lt;/a&gt; or &lt;a href="https://github.com/encode/uvicorn"&gt;&lt;code&gt;uvicorn&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Maybe it's short for "universal/ultimate/unified virtualenv manager"?&lt;/p&gt;

&lt;p&gt;The dedicated docs pages of &lt;code&gt;uv&lt;/code&gt; are not present at the time of writing, which is a pitty.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://astral.sh/blog/uv"&gt;uv: Python packaging in Rust&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/astral-sh/uv"&gt;uv on Github&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>rust</category>
      <category>python</category>
      <category>cli</category>
    </item>
  </channel>
</rss>
