How to Deploy a Python Function to the Cloud with Modal
Modal is a serverless platform for Python that runs your functions in the cloud on demand. You write normal Python, decorate a function, and Modal handles containers, scaling and GPUs. There is no Dockerfile and no cluster to manage. The free tier includes $30 of monthly compute credit, which is enough to test real workloads.
It is aimed at data and ML developers who want a function to run somewhere fast without DevOps overhead. If you have ever waited on a Kubernetes setup just to run a batch job, Modal is the shorter path.
What is Modal?
Modal is a serverless compute platform for Python. You define an app, attach an image with your dependencies, and deploy. Modal builds the container, runs your function on demand, and scales to zero between calls so you do not pay for idle time.
How do you install and run your first function?
pip install modal- Run
modal setupto authenticate in the browser. - Write a file that imports
modaland defines an app plus one function. - Run it locally with
modal run app.py— it executes in the cloud. - Deploy it persistently with
modal deploy app.py.
The first run pulls and builds an image, so it takes longer than later calls.
How do you add dependencies and a GPU?
Point the image at packages and the runtime picks it up:
modal.Image.debian_slim().pip_install("torch")for libraries.@app.function(gpu="A100")to request a GPU type.- Use
gpu="any"to take whatever is available at a lower cost.
GPUs bill per second of use, so a 30-second job on an A100 costs cents.
How do you expose it as a web endpoint?
Add a decorator that turns the function into an HTTP route, then deploy. Modal gives you a URL that scales from zero. This works for an API, a webhook handler, or a simple inference endpoint. You can also schedule functions to run on a cron.
What should you watch out for?
Cold starts happen when a deployed function has been idle, and a GPU cold start can add several seconds. Long-running state does not survive between calls unless you use Modal’s storage primitives like volumes and dicts. And the pricing model rewards bursty work — a function running 24/7 may be cheaper on a plain VM.
Key Takeaways
- Modal runs Python functions serverlessly with no Dockerfile or Kubernetes.
- Install with
pip install modal, authenticate withmodal setup. - Request GPUs with one decorator argument; billed per second.
- Functions can be HTTP endpoints or scheduled jobs.
- Free tier gives about $30/month compute; best for bursty workloads.
Last updated October 2026. Details at Modal.
