{"id":5741,"library":"vercel-runtime","title":"Vercel Python Runtime (Internal/Base Package)","description":"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.","status":"active","version":"0.12.0","language":"en","source_language":"en","source_url":"https://vercel.com/docs/functions/runtimes/python","tags":["vercel","serverless","python-runtime","fastapi","flask","django"],"install":[{"cmd":"pip install vercel-runtime","lang":"bash","label":"Install package (usually handled by Vercel's build process)"}],"dependencies":[{"reason":"Required for execution; specifically >=3.12 is required for this package, though Vercel supports other Python versions depending on configuration.","package":"python","optional":false}],"imports":[{"note":"Developers typically import frameworks like FastAPI, Flask, or Django, not `vercel-runtime` directly, when writing Vercel Python Functions. Vercel automatically detects and runs ASGI/WSGI apps.","symbol":"FastAPI","correct":"from fastapi import FastAPI"}],"quickstart":{"code":"from fastapi import FastAPI\nfrom os import environ\n\napp = FastAPI()\n\n@app.get(\"/\")\ndef read_root():\n    return {\"message\": f\"Hello from Vercel Python! The secret is: {environ.get('MY_SUPER_SECRET', 'NOT_SET')}\"}\n\n# To deploy this on Vercel:\n# 1. Save as `api/index.py` (or `app.py`, `main.py`, etc.)\n# 2. Add `fastapi` to `requirements.txt`\n# 3. Add `uvicorn` to `requirements.txt` (for local dev, not strictly needed for Vercel deployment)\n# 4. Deploy with `vercel` CLI","lang":"python","description":"This quickstart demonstrates how to create a simple FastAPI application, which is a common way to build Python Serverless Functions for Vercel. Vercel automatically detects the `app` object and serves it. The `vercel-runtime` package itself is not directly imported into typical user-facing function code."},"warnings":[{"fix":"Ensure your Python functions only rely on standard Python libraries and packages compatible with the Vercel Python runtime. Consult Vercel's official documentation for supported APIs and behaviors across different runtimes.","message":"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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Optimize function performance, offload long-running tasks to external services (e.g., queues, background workers), and consider increasing `maxDuration` in `vercel.json` for specific functions if your plan allows. Ensure any database connections are managed efficiently to avoid startup delays.","message":"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.","severity":"breaking","affected_versions":"All versions"},{"fix":"Thoroughly test environment variables, configuration, and external service connections. Implement robust error handling and consider integrating with external logging services for comprehensive log capture.","message":"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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Carefully manage your `requirements.txt` or `pyproject.toml` to include only necessary runtime dependencies. Use a `.vercelignore` file or `excludeFiles` in `vercel.json` to prevent unnecessary files from being bundled with your function.","message":"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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always define your target Python version in your project's configuration files (e.g., `pyproject.toml` with `requires-python` or a `.python-version` file) to ensure consistent environments. Consult Vercel's documentation for current supported versions and any compatibility requirements.","message":"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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}