Tech News
← Back to articles

Switching Pip to Uv in a Dockerized Flask / Django App

read original related products more articles

Switching pip to uv in a Dockerized Flask / Django App

I noticed about a 10x speed up across a number of projects, we'll avoid using a venv and run things as a non-root user too.

Prefer video? Here is it on YouTube.

I was surprised at how painless it was to switch things over. You can see the git diffs to make the change for both of my example Flask and Django projects. In this post we’ll go into more detail about these changes and how to use a few uv commands.

Let’s start with defining our project’s dependencies.

You can create a pyproject.toml file and delete your requirements.txt after you’ve entered your project’s dependencies and their versions into pyproject.toml .

You only need to add your top level dependencies, uv will make a lock file for you automatically which is somewhat comparable to what pip freeze would produce except uv’s lock file has proper dependency trees and is way better.

Here’s a very small diff that shows an example of what to do, adjust it as needed:

# pyproject.toml +[project] +dependencies = [ + "redis==5.2.1", +] # requirements.txt -redis==5.2.1

It’s important that these steps happen in order. For example you’ll want the environment variables defined before you install your dependencies.

... continue reading