Python: my new uv setup for development

The power of the sun, in the palm of my hand.

uv is a new, fast Python packaging tool. Since the August 20 update, uv can now manage both versions of Python and Python-powered tools.

I’ve been playing around with uv since shortly after its release, thoroughly enjoying its coherent design and speed. After playing around with the new features, I decided to switch to uv for Python and tool management on my development laptop. This meant ditching my old setup with Mise (previously pyenv), pipx, and Pip. It’s nice to have fewer tools to worry about.

I use Ansible to manage my laptop setup, as covered previously. I updated this setup to:

  1. Use uv python install to manage Python versions. I like that this one command can install and update multiple Python versions.
  2. Use uv tool install and uv tool upgrade to manage Python-powered tools. uv puts tool executables in ~/.local/bin on my machine, which I have on my $PATH.
  3. Run uv cache prune to clean up unused cache entries from old versions of Python packages. I run my Ansible playbook every two weeks, so it’s a good time to clean up caches to prevent them from growing huge.

Here are the Ansible tasks I wrote to run these commands (source):

# ...

# This task installs and updates uv
- name: Install homebrew packages
  homebrew:
    name: '{{ homebrew_packages }}'
    state: latest
  tags:
  - brew

# ...

- name: uv install latest Pythons
  command: >
    uv python install
    3.8
    3.9
    3.10
    3.11
    3.12
    3.13
  tags:
  - uv

- name: uv install tools
  command: >
    uv tool install
    --python 3.12
    {{ item.name }}
    {% if item.with is defined %}
    {% for w in item.with %}--with {{ w }}{% endfor %}
    {% endif %}
  loop: '{{ uv_tools }}'
  tags:
  - uv

- name: uv upgrade tools
  command: >
    uv tool upgrade
    {{ item.name }}
    {% if item.with is defined %}
    {% for w in item.with %}--upgrade-package {{ w }}{% endfor %}
    {% endif %}
  loop: '{{ uv_tools }}'
  tags:
  - uv

- name: uv prune cache
  command: uv cache prune
  tags:
  - uv

And here’s the uv_tools variable that controls the installed tools (source):

uv_tools:
- name: black
- name: build
- name: flake8
- name: httpie
- name: ipython
- name: pre-commit
  with:
  - pre-commit-uv
- name: tox
  with:
  - tox-uv
- name: twine
- name: virtualenv
- name: yt-dlp

Note pre-commit-uv and tox-uv, which add uv support to pre-commit and tox, respectively. Thanks to Bernát Gábor for making them. These are worth adding if you’re using those tools.

Fin

I hope this post can help you try configuring your development machine with uv.

Thanks to the Astral team for uverything,

—Adam


😸😸😸 Check out my new book on using GitHub effectively, Boost Your GitHub DX! 😸😸😸


Subscribe via RSS, Twitter, Mastodon, or email:

One summary email a week, no spam, I pinky promise.

Related posts:

Tags: ,