How to Use uvx for Temporary Python Shells and Exploratory Coding
Problem
I want to test how a Flask API behaves. I could create a new virtual environment, install Flask, test my hypothesis, then figure out what to do with that environment. Or I could run it in a disposable shell that vanishes when I’m done.
Here’s the second approach - it’s faster, cleaner, and exactly what uvx was designed for.
The Short Answer
Use uvx --from python for throwaway shells, and uvx --with <packages> ipython for interactive sessions with dependencies.
# Run a throwaway Python shell with Flaskuvx --from flask python
# Run IPython with additional packagesuvx --with pandas --with requests ipython
# Run a Flask app interactivelyuvx --from flask python -c "from flask import Flask; app = Flask(__name__)"What is uvx for Shells?
uvx (alias for uv tool run) can execute Python with any package as the main entry point. It creates a temporary, isolated environment that cleans up after itself.
The process works like this:
- Resolves the specified package
- Creates an ephemeral environment
- Runs the Python interpreter or tool
- Cleans up when done - no persistent installation
This is useful for:
- Quick API testing
- Framework exploration
- One-off script execution with dependencies
- Interactive debugging sessions
uvx —from for Package-as-Main
The --from flag lets you run a package’s default executable. This is powerful for shells:
# Run Flask's Python interpreteruvx --from flask python
# Now you're in a shell with Flask available>>> from flask import Flask, request>>> app = Flask(__name__)>>> @app.route('/test')... def test(): return 'OK'...Armin Ronacher (mitsuhiko), the creator of Flask, shared this workflow on Reddit:
“One thing I sometimes do is to just run a python shell. Eg: if I want to figure out how an API behaves I can just run it in a throwaway virtualenv: $ uvx —from flask python”
This is the quickest way to explore any Python package interactively.
Version Pinning with —from
You can pin specific versions:
# Run specific Flask versionuvx --from 'flask<3.0' python
# Run with version constraintsuvx --from 'flask>2.0,<3.0' pythonuvx —with for Adding Dependencies
The --with flag adds additional packages to the ephemeral environment:
# IPython with data science packagesuvx --with pandas --with requests ipython
# Multiple packages at onceuvx --with pandas --with requests --with numpy ipython
# With version constraintsuvx --with 'requests>2.28,<3.0' ipythonFrom a Reddit discussion:
“uvx —with pandas —with requests ipython” for ad-hoc iPython sessions
Another developer added:
“Adhoc iPython sessions with some libs is something I tend to do A LOT”
Combining —from and —with
You can combine both flags for the best of both worlds:
# Flask as main, plus additional packagesuvx --from flask --with sqlalchemy --with pydantic python
# Great for testing ORM models with Flask routesuvx --from flask --with 'sqlalchemy>2.0' pythonPractical Use Cases
Use Case 1: API Exploration
# Quick HTTP testinguvx --from flask python>>> import requests>>> response = requests.get('https://api.example.com/data')>>> print(response.json())Use Case 2: Framework Testing
# Test Django setupuvx --from django python -c "import django; print(django.VERSION)"
# Test FastAPIuvx --from fastapi python>>> from fastapi import FastAPI>>> app = FastAPI()Use Case 3: Package Exploration
# Explore any package without installinguvx --from pandas python>>> import pandas as pd>>> df = pd.DataFrame({'a': [1,2,3]})>>> df.describe()Use Case 4: Data Science Scratchpad
# Ad-hoc analysis environmentuvx --with pandas --with numpy --with matplotlib ipythonuvx vs Traditional Approaches
| Approach | Setup Time | Cleanup | Best For |
|---|---|---|---|
| uvx | Seconds | Automatic | One-off tasks |
| pipx | Seconds | Manual | Persistent tools |
| venv | ~30 seconds | Manual | Long-lived projects |
| uv venv | ~5 seconds | Manual | Project work |
The key advantage of uvx: zero commitment. Create, use, forget. No cleanup needed.
Advanced Patterns
Running Scripts with Dependencies
# Run a script with temporary dependenciesuvx --with rich --with httpx python script.py
# Equivalent to creating a temp venv with those packagesUsing uv run Instead
For project-based work:
# For project-based workuv run --with pandas --with requests script.py
# --no-project ignores project dependenciesuv run --no-project --with pandas script.pySpecific Python Version
# Run with specific Python versionuvx --python 3.11 --from flask python
# PyPy for specific needsuvx --python pypy3.9 --from numpy pythonWhy This Works
The old workflow was: create venv, install stuff, do work, delete venv. That’s four steps with manual cleanup.
uvx handles all of this automatically:
--fromspecifies the “main” package - the one that provides the context--withadds supporting packages without making them the focus- The environment is truly temporary - it vanishes when the session ends
- No accumulated junk in your system
This is why the Flask creator uses it for API exploration. It’s not about laziness - it’s about removing friction from the thought-to-execution pipeline.
Summary
In this post, I showed how to use uvx for temporary Python shells and exploratory coding. The key commands are:
uvx --from <package> python- Run Python with a package availableuvx --with <pkg> ipython- Interactive session with dependenciesuvx --from <pkg1> --with <pkg2> python- Combine approaches
The key point is: no more “let me create a quick venv” - just run and go. When the creator of Flask uses this workflow for API testing, you know it’s production-grade thinking.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
- 👨💻 uv Documentation
- 👨💻 Flask Documentation
- 👨💻 IPython Documentation
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments