Python uv: No More Manual Virtual Environments

HasHas
3 min read
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

But now, a new tool called uv makes this entire process seamless.

That changes with uv, a new ultra-fast Python package manager and runtime by Astral (creators of Ruff).

With uv, managing Python dependencies feels more like using npm in Node.js:

  • No manual virtual environment setup.

  • Simple commands to install and run.

  • Automatic isolation per project.

Why uv Feels Like npm

Why uv Feels Like npm

Let’s compare side by side:

TaskOld Python Way (pip + venv)With uvNode.js (npm)
Create projectmkdir app && cd app && python -m venv .venvuv init appmkdir app && cd app && npm init -y
Add dependencypip install requestsuv add requestsnpm install axios
Track dependenciesrequirements.txt (manual update)pyproject.toml (auto updated)package.json (auto updated)
Run scriptsource .venv/bin/activate && python script.pyuv run python script.pynode script.js
Lock versionspip-tools or manualBuilt-in lockfilepackage-lock.json
Global tool installpip install --user tooluv tool install toolnpm install -g tool

Example: Installing and Running a Project

npm init -y
npm install express
node server.js
uv init my-app
uv add fastapi uvicorn
uv run uvicorn app:app --reload

Notice how both flows look almost identical. No venv step in Python anymore.

Why This Matters

Why This Matters

  • Beginner friendly: New Python devs don’t need to learn about virtual environments right away.

  • Faster installs: uv is significantly faster than pip.

  • Consistency: Automatic lock files ensure reproducible builds.

  • Unified experience: Just like JavaScript developers rely on npm, Python developers can now rely on uv.

Conclusion

Python has long lagged behind JavaScript in developer experience when it comes to dependency management. With uv, Python is finally catching up — giving us an npm-like workflow that’s simple, fast, and reliable.

If you’re tired of typing python -m venv .venv && source .venv/bin/activate, it’s time to try uv.

Let’s create a FastAPI project step by step… with UV + Python

1. Initialize a New Project

uv init testApi
cd testApi

it will Create

run this

uv run main.py

its creates everything automatically

2. Add Dependencies

uv add fastapi uvicorn

same npm i packagename

it will add dependency in pyproject.toml — same as package.json

3. Add a Basic FastAPI App

from fastapi import FastAPI
import uvicorn
def main():
    print("Hello from ocr!")
    uvicorn.run(app, host="0.0.0.0", port=7000)


app = FastAPI()

@app.get("/")
async def root():
    return {"message":"i am python FastAPI"}


if __name__ == "__main__":
    main()

4. Run the App

Boom….

5. Summary

  • uv = automatic environment + package manager (like npm)

  • FastAPI project is ready in minutes

  • No manual venv, no pip hassles

  • Run scripts with uv run

🚀 Exploring FastAPI with uv — no virtual environments, no hassle, just Python done right! Stay tuned, more insights coming soon.

0
Subscribe to my newsletter

Read articles from Has directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Has
Has