Live data from Hacker News

Fun with uv and PEP 723

cottongeeks.com

81–90 of 231 posts

Re: Fun with uv and PEP 723

#81
post #71

Some years ago I thought it would be interesting to develop a tool to make a python script automatically install its own dependencies (like uvx in the article), but without requiring any other external tool, except python itself, to be installed. The downside is that there are a bunch of seemingly weird lines you have to paste at the begging of the script :D If anyone is curios it's on pypi (pysolate).

Also this thing that never took off: https://github.com/fal-ai/isolate

Not quite the same but interesting!

Re: Fun with uv and PEP 723

#82

There has been a flurry of `uv` posts on HN recently. I don't have any experience with it, is it really the future, or is it a fad? As Ive gotten older I've grown weary of third party tools, and almost always try to stick with the first party built in methods for a given task. Does uv provide enough benefit to make me reconsider?

I’m a moron when it comes to python tooling but switching a project to uv was a pleasant experience. It seems well thought out and the speed is genuinely a feature compared to other python tooling I’ve used.

Re: Fun with uv and PEP 723

#83
post #69

Last time I looked at switching from poetry to uv I had an issue with pinning certain dependencies to always install from a private PyPI repository. Is there a way to do that now? (also: possible there's always been a way and I'm an idiot)

You mean something like https://docs.astral.sh/uv/concepts/indexes/ ?

Re: Fun with uv and PEP 723

#84

There has been a flurry of `uv` posts on HN recently. I don't have any experience with it, is it really the future, or is it a fad? As Ive gotten older I've grown weary of third party tools, and almost always try to stick with the first party built in methods for a given task. Does uv provide enough benefit to make me reconsider?

A lot of people like all-in-one tools, and uv offers an opinionated approach that works. It's essentially the last serious attempt at this since Poetry, except that uv is also supporting a variety of new Python packaging standards up front (most notably https://peps.python.org/pep-0621/ , which Poetry lagged on for years - see https://github.com/python-poetry/roadmap/issues/3 ) and seems committed to keeping on top of new ones.

How much you can benefit depends on your use case. uv is a developer tool that also manages installations of Python itself (and maintains separate environments for which you can choose a Python version). If you're just trying to install someone else's application from PyPI - say https://pypi.org/project/pycowsay/ as an example - you'll likely have just as smooth of an experience via pipx (although installation will be even slower than with pip, since it's using pip behind the scenes and adding its own steps). On the other hand, to my understanding, to use uv as a developer you'll still need to choose and install a build backend such as Flit or Hatchling, or else rely on the default Setuptools.

One major reason developers are switching to uv is lockfile support. It's worth noting here that an interoperable standard for lockfiles was recently approved (https://peps.python.org/pep-0751/), uv will be moving towards it, and other tools like pip are moving towards supporting it (the current pip can write such lockfiles, and installing from them is on the roadmap: https://github.com/pypa/pip/issues/13334).

If you, like me, prefer to follow the UNIX philosophy, a complete developer toolchain in 2025 looks like:

* Python itself (if you want standalone binaries like the ones uv uses, you can get them directly; you can also build from source like I do; if you want to manage Python installations then https://github.com/pyenv/pyenv is solid, or you can use the multi-language https://asdf-vm.com/guide/introduction.html with https://github.com/asdf-community/asdf-python I guess)

* Ability to create virtual environments (the standard library takes care of this; some niche uses are helped out by https://virtualenv.pypa.io/)

* Package installer (Pip can handle this) and manager (if you really want something to "manage" packages by installing into an environment and simultaneously updating your pyproject.toml, or things like that; but just fixing the existing environment is completely viable, and installers already resolve dependencies for whatever it is they're currently installing)

* Build frontend (the standard is https://build.pypa.io/en/stable/; for programmatic use, you can work with https://pyproject-hooks.readthedocs.io/en/latest/ directly)

* Build backend (many options here - by design! but installers will assume Setuptools by default, since the standard requires them to, for backwards compatibility reasons)

* Support for uploading packages to PyPI (the standard is https://twine.readthedocs.io/en/stable/)

* Optional: typecheckers, linters, an IDE etc.

A user on the other hand only needs

* Some version of Python (the one provided with a typical Linux distribution will generally work just fine; Windows users should usually just install the current version, with the official installer, unless they know something they want to install isn't compatible)

* Ability to create virtual environments and also install packages into them (https://pipx.pypa.io/stable/ takes care of both of these, as long as the package is an "application" with a defined entry point; I'm making https://github.com/zahlman/paper which will lift that restriction, for people who want to `import` code but not necessarily publish their own project)

* Ability to actually run the installed code (pipx handles this by symlinking from a standard application path to a wrapper script inside the virtual environment; the wrappers specify the absolute path to the virtual environment's Python, which is generally all that's needed to "use" that virtual environment for the program. It also provides a wrapper to run Pip within a specific environment that it created. PAPER will offer something a bit more sophisticated here, for both aspects.)

Re: Fun with uv and PEP 723

#85

What's going on? This whole thread reads like paid amazon reviews

What's going on is "we have 14 standards so we need to create a 15th" actually worked this time

It works far more of the time than people give it credit for. There are a lot of good XKCDs, but that one is by far the worst one ever made, as far as being a damaging meme goes.

Re: Fun with uv and PEP 723

#86

There has been a flurry of `uv` posts on HN recently. I don't have any experience with it, is it really the future, or is it a fad? As Ive gotten older I've grown weary of third party tools, and almost always try to stick with the first party built in methods for a given task. Does uv provide enough benefit to make me reconsider?

Yes, IMO it does. I wrote my first lines of Python 16 years ago and have worked with raw pip & venv, PDM and Poetry. None of those solutions come close to how easy it is to use (and migrate to) uv. Just give it a try for half an hour, you likely won't want to use anything else after that.

Re: Fun with uv and PEP 723

#87

There has been a flurry of `uv` posts on HN recently. I don't have any experience with it, is it really the future, or is it a fad? As Ive gotten older I've grown weary of third party tools, and almost always try to stick with the first party built in methods for a given task. Does uv provide enough benefit to make me reconsider?

It is difficult to use Python for utility scripts on the average Linux machine. Deploying Python projects almost require using a container. Popular distros try managing Python packages through the standard package manager rather than pip but not all packages are readily available. Sometimes you're limited by Python version and it can be non-trivial to have multiple versions installed at once. Python packaging has bec…

> Deploying Python projects almost require using a container.

Really? `apt install pipx; pipx install sphinx` (for example) worked flawlessly for me. Pipx is really just an opinionated wrapper that invokes a vendored copy of Pip and the standard library `venv`.

The rest of your post seems to acknowledge that virtual environments generally work just fine. (Uv works by creating them.)

> Sometimes you're limited by Python version and it can be non-trivial to have multiple versions installed at once.

I built them from source and make virtual environments off of them, and pass the `--python` argument to Pipx.

> If you use anything outside the standard library the only reliable way to run a script is installing it in a virtual environment. Doing that manually is a hassle and pyenv can be stupidly slow and wastes disk space.

If you're letting it install separate copies of Python, sure. (The main use case for pyenv is getting one separate copy of each Python version you need, if you don't want to build from source, and then managing virtual environments based off of that.) If you're letting it bootstrap Pip into the virtual environment, sure. But you don't need to do either of those things. Pip can install cross-environment since 22.3 (Pipx relies on this).

Uv does save disk space, especially if you have multiple virtual environments that use the same packages, by hard-linking them.

> With uv it's fast and easy to set up throw away venvs or run utility scripts with their dependencies easily. With the PEP-723 scheme in the linked article running a utility script is even easier since its dependencies are self-declared and a virtual environment is automatically managed.

Pipx implements PEP 723, which was written to be an ecosystem-wide standard.

Re: Fun with uv and PEP 723

#88
post #69

Last time I looked at switching from poetry to uv I had an issue with pinning certain dependencies to always install from a private PyPI repository. Is there a way to do that now? (also: possible there's always been a way and I'm an idiot)

Yes, see: https://docs.astral.sh/uv/concepts/projects/dependencies/#in...

Re: Fun with uv and PEP 723

#89

Does this create a separate environment for each script? If so, won't that create lots of bloat?

It does create separate environments.

Each environment itself only takes a few dozen kilobytes to make some folders and symlinks (at least on Linux). People think of Python virtual environments as bloated (and slow to create) because Pip gets bootstrapped into them by default. But there is no requirement to do so.

The packages take up however much space they take up; the cost there is unavoidable. Uv hard-links packages into the separate environments from its cache, so you only pay a disk-space cost for shared packages once (plus a few more kilobytes for more folders).

(Note: none of this depends on being written in Rust, but Pip doesn't implement this caching strategy. Pip can, however, install cross-environment since 22.3, so you don't actually need the bootstrap. Pipx depends on this, managing its own vendored copy of Pip to install into multiple environments. But it's still using a copy of Pip that interacts with a Pip-styled cache, so it still can't do the hard-link trick.)

Re: Fun with uv and PEP 723

#90
If momentum for uv in the community continues, I’d love to see it distributed more broadly. uv can already be installed easily on macOS via Homebrew (like pyenv). uv can also be installed on Windows via WinGet (unlike pyenv). It would be nice to see it packaged for Linux as well.
Post reply on HN