What you’ll learn
- How to scaffold a project with
rp flash init. - How to run queue functions on CPUs and GPUs with
@app.queue. - How to serve a stateful HTTP class with
@app.api. - How to stream results from a generator function.
- How to share data between tasks with a network volume.
- How to deploy the app with
rp flash deploy.
Requirements
- A Runpod account with credits.
- Python 3.10 to 3.14 on your machine.
- The
runpodpackage, version 2.0 or later. To use the release candidate, runpip install runpod==2.0.0rc1. - Credentials saved with
rp login. See Authenticate.
Step 1: Create a project
Scaffold a new project:main.py: An app with one queue function and a local entrypoint.requirements.txt: Packages your workers need. They’re also installed locally for dev sessions..runpodignore: Files to leave out of deployments. See Ignore rules.
main.py. It contains a complete app:
main.py
@app.queue turns hello into a queue-based Serverless endpoint running on a small CPU worker. main is marked with @runpod.local_entrypoint, so it runs on your machine and calls hello remotely.
Step 2: Run it in a dev session
Start a dev session:hello, runs main, and streams the worker’s print output to your terminal. Leave the session running. Change the greeting in hello, save the file, and press Enter to re-run. Workers pick up the new code automatically.
Press Ctrl-C when you’re done. The session deletes its temporary endpoints. To learn more, see Dev sessions.
Step 3: Run a function on a GPU
Add a GPU function tomain.py:
main.py
main:
main.py
gpu="4090"requests an RTX 4090. See GPU types for other options.- Packages are imported inside the function, so your machine doesn’t need them.
torchis already installed on the built-in GPU images, so it doesn’t need to be listed independencies.
Step 4: Add an HTTP service
Use@app.api to serve a class over HTTP. Mark routes with @runpod.get and @runpod.post, and setup code with @runpod.init:
main.py
main.py
Counter runs on a load-balanced endpoint. Each worker keeps its own state in memory between requests.
Step 5: Stream results
A generator function streams its output. Call.stream() to receive each chunk as the worker yields it:
main.py
.remote() on a generator returns every chunk at once. You can also call .spawn() and stream the job later with job.stream().
Step 6: Share data between tasks
Tasks run on a dedicated Pod that terminates when the function returns. To pass files between tasks, mount the same network volume on both:main.py
checkpoints.path returns the mount path on each Pod. See Storage.
Step 7: Deploy the app
When the app works in a dev session, deploy it:default environment. To deploy to another environment, add --env, for example rp flash deploy --env production. See Deploy an app.
To remove the deployed endpoints:
Next steps
- Learn how dev sessions work.
- Organize deployments with apps and environments.
- Browse the examples in the runpod-python repository.