All jobs

Pin the Python Dependencies of a Streamlit App

Yes. An agent compiles your loose requirements.txt into exact pins, runs every page through AppTest against them and opens a PR that your CI installs as-is.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads what the app installs today and what installs it. In a Streamlit repository like streamlit/llm-examples, requirements.txt has eight lines and three kinds of looseness: lower bounds only (streamlit>=1.28, openai>=1.2, anthropic>=0.3.0, trubrics>=1.4.3), no bound at all (duckduckgo-search, streamlit-feedback), and two exact pins (langchain==0.0.350, langchain-community==0.0.3). requirements-dev.txt pins black==23.3.0, mypy==1.4.1 and pre-commit==3.3.3 but leaves watchdog and pytest open. Three places install from the first file: .github/workflows/app-testing.yml through streamlit/streamlit-app-action@v0.0.3, whose action.yml runs pip install -r requirements.txt when the file exists; .devcontainer/devcontainer.json, whose postCreateCommand is pip3 install --user -r requirements.txt on a python:3.11-bullseye image; and Streamlit Community Cloud, where the README says the demo is deployed.

The agent keeps requirements.txt as the file everything installs and makes it the lock. It moves the human-written ranges into a new requirements.in, then compiles it with uv pip compile requirements.in -o requirements.txt --python-version 3.11, the interpreter the workflow's actions/setup-python@v5 step and the devcontainer image both use, so the resolution matches the machines that will install it. The output pins every direct and transitive package with == and a # via comment naming what pulled it in. The dev file gets the same treatment, requirements-dev.in compiled with -c requirements.txt as a constraint so the two files can never disagree about a shared package.

A lock is only as good as what runs against it. The repository's app_test.py covers two pages with streamlit.testing.v1.AppTest: it patches openai.resources.chat.Completions.create to drive Chatbot.py, and langchain.llms.OpenAI.__call__ to drive pages/3_Langchain_Quickstart.py. The agent adds a parametrised smoke test that runs AppTest.from_file(...) over every file in pages/ and asserts not at.exception, which works without any API key because each page stops at its st.info prompt when the key field is empty. That catches the failure mode pinning is most likely to expose: pages/2_Chat_with_search.py imports initialize_agent, StreamlitCallbackHandler, ChatOpenAI and DuckDuckGoSearchRun from langchain, and pages/1_File_Q&A.py uses anthropic.HUMAN_PROMPT and anthropic.Client(...).completions.create, import paths that exist in some versions and not others.

In the sandbox the agent installs the compiled file into a fresh Python 3.11 environment, runs pytest app_test.py -v and ruff check . as the workflow does, and reads the resolver's output for the two existing pins: langchain==0.0.350 and langchain-community==0.0.3 stay exactly where they are, and whatever versions of openai and anthropic satisfy them become the pins. Nothing is upgraded on the first run; the pull request records the state that works today, and the weekly run described below is what moves it.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Pin the Python dependencies of this Streamlit app and open a pull request. Read requirements.txt, requirements-dev.txt, app_test.py, .github/workflows/app-testing.yml, .devcontainer/devcontainer.json and every file in pages/ first. Move the current ranges into requirements.in and requirements-dev.in, then compile them with uv pip compile for Python 3.11, the version the workflow and the devcontainer use, writing requirements.txt and requirements-dev.txt with exact versions and via comments, with the dev file constrained by requirements.txt. Keep the existing exact pins for langchain and langchain-community unchanged and do not upgrade anything on this run. Add a parametrised AppTest smoke test to app_test.py that runs every page in pages/ with no API key and asserts no exception. Install the compiled requirements into a fresh Python 3.11 environment, run pytest app_test.py -v and ruff check ., and paste both outputs in the pull request. Do not change the workflow or the devcontainer; both install requirements.txt and must keep working unchanged.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request with two new .in files holding the ranges that used to live in the .txt files, a rewritten requirements.txt and requirements-dev.txt in which every package has an exact version and a # via line, and a few lines added to app_test.py. The description shows the pytest -v run from the sandbox with each page listed, the ruff check result, and the resolver's note on which packages were previously unbounded.

.github/workflows/app-testing.yml runs on every pull request to main, so the same tests run again on GitHub against the same pinned file, with pmeier/pytest-results-action publishing the results as the workflow already does. The devcontainer and Community Cloud deployment pick up the pinned file the next time they build, with no configuration change.

A reviewer checks that the .in files say what the team means (a package that was unbounded on purpose may deserve an explicit floor), that the Python version used to compile matches the one in the workflow and the devcontainer, and that no pin moved on this first pass. Then they merge, and from here on a version change is a diff in a pull request rather than a surprise at install time.

Run it on every Monday morning

A scheduled job on your server sends POST /o/{org}/sessions each week with this request, the repository in resources, and a prompt that adds one instruction: recompile with --upgrade so the pins move to the newest versions the .in ranges allow, run the same tests, and leave out any bump that breaks a page, naming the error. Send a request_id that is a UUID v5 of the repository and the week so a retried job returns the run already started instead of opening a second pull request.

Give the API key a webhook_url and Rush POSTs run.completed when the turn ends, with the session_url to read the pull request link from, so the weekly diff lands in the channel where the app is maintained.

The use case this job follows, with its automation and trigger: Upgrade dependencies weekly.

Why run it on Rush?

Pinning looks like a mechanical edit, but the only way to know a lock is right is to install it on the interpreter your CI uses and run the app, and that is slow and messy on a laptop that already has a different streamlit in its environment. In a Rush sandbox the agent builds a fresh Python 3.11 environment, installs exactly the compiled file and drives every page through AppTest, and each command and its output is kept with the run.

The same request works unchanged every week: recompile, test, report. Because the agent reads the resolver output and the test output rather than guessing, the pull request says which packages moved and which page objected, and a reviewer reads a diff instead of debugging a deployment.

Frequently asked questions

Why uv pip compile and not pip freeze?

pip freeze records whatever happens to be installed, including packages nobody asked for, and loses the distinction between what you want and what you got. Compiling from requirements.in keeps your ranges in one file and the resolved pins in another, with # via comments that explain every transitive package.

Does the CI workflow need to change?

No. streamlit/streamlit-app-action@v0.0.3 installs requirements.txt when the file exists, and the pinned file is still named requirements.txt. The devcontainer's postCreateCommand and Community Cloud read the same file.

Will anything be upgraded?

Not on the first run. The agent compiles the ranges you already have, so langchain==0.0.350 and langchain-community==0.0.3 stay put and the open-ended packages get the version that satisfies today's resolution. Upgrades are the weekly job's work, one pull request at a time with the tests run again.

How does the smoke test run without API keys?

Every page in pages/ asks for a key in the sidebar and stops with st.info when it is empty, so AppTest.from_file(page).run() exercises the imports and the first render without calling any provider. app_test.py already uses this pattern for Chatbot.py, with the OpenAI client patched for the second step.

Should the pins include hashes?

They can. uv pip compile --generate-hashes writes a hash per file and pip install -r then refuses anything that does not match. The agent leaves hashes out unless the prompt asks, because every installer of the file, including Community Cloud, must then support them.

More Streamlit jobs

More jobs like this: Upgrade dependencies weekly

Keep reading