Vercel Python Runtime (Internal/Base Package)
This `vercel-runtime` Python package appears to be an internal or foundational component used by Vercel's platform to manage the execution environment for Python Serverless Functions. It is not typically a library that developers directly import or interact with in their application code when building Vercel functions. Instead, developers focus on creating standard ASGI (Asynchronous Server Gateway Interface) or WSGI (Web Server Gateway Interface) applications using frameworks like FastAPI, Flask, or Django, which Vercel then deploys and runs within its Python runtime environment. The current version is `0.12.0`, and Vercel maintains a rapid release cycle across its platform.
Warnings
- gotcha Vercel's Edge Runtime (often used for Node.js or other runtimes) has significant limitations compared to full Node.js or Python environments (e.g., no `fs` module, specific crypto methods). While the Python runtime provides a more complete Python environment, be aware of the underlying differences if you mix runtimes or expect Node.js-specific behaviors.
- breaking Vercel functions, including Python, have execution duration limits. Default timeouts can be as low as 10 seconds for some contexts and up to 300 seconds (or more for specific plans/configurations) for Node.js functions, and up to 300 seconds for Edge Functions, though they must start responding within 25 seconds. If a function exceeds this, it results in a 504 error.
- gotcha Debugging Vercel functions can be challenging due to log latency and silent failures. Functions can crash during initialization (e.g., missing environment variables, DB connection failure) before any application `print()` or `logging` statements are executed, resulting in a 500 error with no visible logs.
- gotcha Python functions have a maximum uncompressed bundle size of 500 MB. Including unnecessary files (e.g., tests, static assets, large data files) can cause deployments to fail due to hitting this limit.
- gotcha Specifying the Python version requires explicit configuration. Vercel defaults to Python 3.12, but you can specify other supported versions (e.g., 3.13, 3.14) in `pyproject.toml`, `.python-version`, or `Pipfile.lock`. Older Python versions (like 3.9) might require specific Node.js runtime configurations (e.g., Node.js 16 or 18) for legacy images.
Install
-
pip install vercel-runtime
Imports
- FastAPI
from fastapi import FastAPI
Quickstart
from fastapi import FastAPI
from os import environ
app = FastAPI()
@app.get("/")
def read_root():
return {"message": f"Hello from Vercel Python! The secret is: {environ.get('MY_SUPER_SECRET', 'NOT_SET')}"}
# To deploy this on Vercel:
# 1. Save as `api/index.py` (or `app.py`, `main.py`, etc.)
# 2. Add `fastapi` to `requirements.txt`
# 3. Add `uvicorn` to `requirements.txt` (for local dev, not strictly needed for Vercel deployment)
# 4. Deploy with `vercel` CLI