FastAPI UV vs Requirements File

FastAPI Docker: UV vs Requirements for speed

Same FastAPI sample twice in Docker: classic pip + requirements vs uv

The repository ships one FastAPI app (with user-management-style routes and SQLite) built as two images: Dockerfile.requirementsfile installs dependencies with pip from requirements.txt, while Dockerfile.uv uses uv for resolution and installs. Docker Compose runs both side by side so you can compare build behavior and dependency workflows on your machine.

When it is useful

You are choosing a Python packaging path for containerized services, you need a concrete diff for a team discussion, or you are learning how uv layers into Docker without betting a production app on slides alone.

What you can do

  • Build and start both variants with the documented compose command and environment template.
  • Hit the same API surface on each service port the README assigns for local comparison.
  • Extend main.py, routers, or models once, then rebuild both images to see how each Dockerfile behaves.

Limits

  • Measured build time and image size depend on your CPU, cache, and dependency set; treat numbers as local experiments, not universal promises.
  • The sample SQLite backend is for demos; production databases and secrets management are separate decisions.
  • Picking uv vs pip also depends on org policy, supply-chain tooling, and CI; this repo illustrates mechanics, not procurement approval.

Frequently asked questions

What is being compared?

The same FastAPI app (user-management-style routes and SQLite) is built as two Docker images: Dockerfile.requirementsfile installs with pip from requirements.txt, and Dockerfile.uv uses uv for resolution and installs.

How do I run both side by side?

Copy .env.sample to .env, then docker-compose up --build. The requirements.txt variant listens on localhost:8081 and the uv variant on localhost:8082 so you can hit the same API surface on each.

What else ships in the sample?

CORS middleware, Docker health checks for both services, and a shared main.py/routers/models layout you can extend once and rebuild both images.

Are build-time numbers universal?

No. Measured build time and image size depend on your CPU, cache, and dependency set. Treat them as local experiments. SQLite here is for demos, not a production database choice.

Continue exploring