diff options
Diffstat (limited to 'skills/vercel-python/references')
5 files changed, 71 insertions, 39 deletions
diff --git a/skills/vercel-python/references/dependencies-and-versions.md b/skills/vercel-python/references/dependencies-and-versions.md index fbe5626..3274198 100644 --- a/skills/vercel-python/references/dependencies-and-versions.md +++ b/skills/vercel-python/references/dependencies-and-versions.md @@ -28,7 +28,9 @@ When using `pyproject.toml`, lockfiles are selected in this order: ## Python Versions -Vercel Python deployments currently support Python 3.12, 3.13, and 3.14 for new projects. Python 3.12 is the default. +Vercel Python deployments currently support Python 3.12, 3.13, and 3.14 for new projects. Python 3.12 is the default. See [Vercel Python documentation](https://vercel.com/docs/functions/runtimes/python) for the current list of supported versions. + +Vercel uses major.minor only; patch numbers in `.python-version` or `requires-python` are ignored. Version selection sources: @@ -61,6 +63,8 @@ Both patterns are valid. Do not request unsupported future versions such as `3.1 Vercel uses `uv` for Python dependency installation. Build-time installs can download managed Python versions automatically. Runtime dependency installation avoids Python downloads and expects the needed runtime to be available. +The builder supports **uv workspaces**. When the project is a workspace member, the builder resolves `uv.lock` from the workspace root automatically. Do not claim that uv workspaces or monorepo layouts are unsupported. + If dependency sync fails: 1. Reproduce locally with `uv sync` or `uv pip install -r requirements.txt`. @@ -76,19 +80,23 @@ When custom commands are required, document why and keep them minimal. ## Bundle Size -Vercel Python functions support up to 500 MB of total bundle size. +Vercel Python functions support up to [500 MB](https://vercel.com/docs/functions/limitations#bundle-size-limits) of total bundle size. When a project exceeds the standard bundle limit and a `uv.lock` is present, the builder can automatically externalize public PyPI packages. Externalized packages are installed at cold start from the lockfile rather than bundled into the function. This is the primary mechanism for deploying large Python dependency sets. It requires: - `pyproject.toml` with a `uv.lock` lockfile. - No custom install or build commands (these disable the optimization). -Common fixes for oversized bundles: +Strategies for reducing function size: + +- **Use `uv.lock` with `pyproject.toml`** so the builder can externalize large public packages. This is the most effective fix for heavy dependency sets. +- **Separate production from dev dependencies.** Use optional dependency groups or `[dependency-groups]` in `pyproject.toml` to keep test, lint, and build tools out of the production install. Vercel installs only main dependencies by default. +- **Audit heavy packages.** Check whether packages like numpy, pandas, scipy, or spacy are actually needed at runtime. If they are only used in data pipelines or scripts, remove them from the deployed function's dependencies. +- **Consider lighter alternatives.** For example, `polars` is significantly smaller than `pandas` for data processing. `httpx` or `urllib3` can replace heavier HTTP libraries. +- **Remove committed artifacts.** Do not commit `.venv`, `venv`, `__pycache__`, model weights, or generated files. These inflate the bundle. +- **Use `excludeFiles` in `vercel.json`** only for files that are safe to omit from the function bundle. +- **Avoid custom install/build commands** when the issue is dependency bundle size -- these disable the externalization optimization. -- Prefer `uv.lock` with `pyproject.toml` so the builder can externalize large public packages. -- Remove unused heavy packages. -- Avoid committing `.venv`, `venv`, caches, model weights, and generated artifacts. -- Use `excludeFiles` in `vercel.json` only for files safe to omit from the function bundle. -- Avoid custom install/build commands when the issue is dependency bundle size. +The externalization mechanism handles public PyPI packages. Private packages (git, local path, or non-PyPI registries) are always bundled directly. Do not assume Vercel deploys every local file. Static `public/**` assets are served separately, and many development/cache directories are excluded. diff --git a/skills/vercel-python/references/frameworks.md b/skills/vercel-python/references/frameworks.md index 5da3705..a53fb9a 100644 --- a/skills/vercel-python/references/frameworks.md +++ b/skills/vercel-python/references/frameworks.md @@ -4,7 +4,7 @@ Use this reference for FastAPI, Flask, Django, ASGI/WSGI app shape, static files ## Zero Configuration -Correctly structured Python projects deploy with zero configuration. No `vercel.json` is needed when the entrypoint and callable follow Vercel's conventions. Only add `vercel.json` when explicit overrides are required. +Correctly structured Python projects deploy with zero configuration. No `vercel.json` is needed when the entrypoint and callable follow Vercel's conventions. Do not create a `vercel.json` unless the project genuinely needs an override — unnecessary config is a common source of deployment failures. ## FastAPI @@ -23,11 +23,10 @@ def read_root(): FastAPI is ASGI. Declare both `fastapi` and an ASGI server such as `uvicorn` in the dependency manifest. WSGI frameworks like Flask do not need `uvicorn`. -Vercel searches `app/`, `src/`, and `api/` directories in addition to the project root. An entrypoint at `app/main.py` with a top-level `app` callable works without any extra configuration. +See `runtime-and-entrypoints.md` for entrypoint discovery rules and conventional file names. Typical fixes: -- Put the app in `main.py`, `app.py`, `app/main.py`, or configure `[tool.vercel].entrypoint`. - Export `app` at top level. - Do not rely on local dev commands such as `uvicorn main:app` as the deploy entrypoint. @@ -93,10 +92,41 @@ Django static collection can run during build when static settings are compatibl - Default Django static storage. - `ManifestStaticFilesStorage`. - WhiteNoise `CompressedManifestStaticFilesStorage`. -- Some `django-storages` configurations. +- `django-storages` configurations. `WHITENOISE_USE_FINDERS=True` can work without `STATIC_ROOT`, but prefer an explicit static setup for production. +## Background Workers + +Vercel supports background task processing via the `vercel-workers` package. Worker services run alongside the web service and consume messages from Vercel Queues. + +The `vercel-workers` package provides: + +- `send()` and `@subscribe` primitives for publishing and consuming queue messages. +- Adapters for **Celery**, **Dramatiq**, and **Django tasks**. + +Worker services are configured in `vercel.json` using `experimentalServices`: + +```json +{ + "experimentalServices": { + "web": { + "framework": "fastapi", + "entrypoint": "main.py", + "routePrefix": "/" + }, + "worker": { + "type": "worker", + "entrypoint": "worker.py", + "topic": "default", + "consumer": "default" + } + } +} +``` + +When a Python app requires background processing (task queues, scheduled jobs, event-driven workers), check whether `vercel-workers` can handle the workload before concluding that the app is incompatible with Vercel. + ## Databases Vercel Marketplace provides managed database integrations that automatically configure connection environment variables: diff --git a/skills/vercel-python/references/runtime-and-entrypoints.md b/skills/vercel-python/references/runtime-and-entrypoints.md index 018a3ce..46b562d 100644 --- a/skills/vercel-python/references/runtime-and-entrypoints.md +++ b/skills/vercel-python/references/runtime-and-entrypoints.md @@ -4,33 +4,21 @@ Use this reference when Vercel cannot find a Python app, the callable is wrong, ## Entrypoint Discovery -Vercel's Python builder looks for conventional entrypoint files named: +Entrypoint resolution follows this priority: -- `app.py` -- `index.py` -- `server.py` -- `main.py` -- `wsgi.py` -- `asgi.py` +1. **`[tool.vercel].entrypoint`** in `pyproject.toml` — explicit path, highest priority. +2. **Framework-specific discovery:** + - **Django:** The builder reads `manage.py` to find `DJANGO_SETTINGS_MODULE`, then looks in the settings module for top-level symbols. + - **Everything else:** Conventional files named `app.py`, `index.py`, `server.py`, `main.py`, `wsgi.py`, or `asgi.py`. Search locations are the project root and shallow app directories such as `src`, `app`, and `api`. +3. **`[project.scripts].app`** in `pyproject.toml` — legacy fallback. -The common search locations are the project root and shallow app directories such as `src`, `app`, and `api`. Prefer conventional names when possible. - -For nonstandard layouts, use `pyproject.toml`: +Prefer `[tool.vercel].entrypoint` for new work: ```toml [tool.vercel] entrypoint = "api/main.py" ``` -Legacy projects may use: - -```toml -[project.scripts] -app = "api/main.py" -``` - -Prefer `[tool.vercel].entrypoint` for new work. - ## Callable Symbols For generic Python, FastAPI, and Flask apps, the entrypoint should expose one top-level callable: @@ -68,12 +56,14 @@ The runtime runs ASGI apps through a vendored Uvicorn layer for lifespan support ## Django Discovery -Django detection starts from `manage.py`, usually at the project root or one directory below. The builder looks at Django settings and prefers `ASGI_APPLICATION` over `WSGI_APPLICATION`. +Django detection starts from `manage.py`, usually at the project root or one directory below. The builder reads `manage.py` to find the module used to set `DJANGO_SETTINGS_MODULE`, then looks in that module for top-level symbols. It prefers `ASGI_APPLICATION` over `WSGI_APPLICATION`. + +If the settings module depends on environment variables or other configuration, these must be set in the Vercel project so the build environment can resolve them. Common blockers: - `manage.py` is nested too deeply. -- `DJANGO_SETTINGS_MODULE` cannot import because dependencies or environment variables are missing. +- `DJANGO_SETTINGS_MODULE` cannot import because dependencies or environment variables are missing. Set required env vars in the Vercel project settings. - Settings only define `WSGI_APPLICATION` when the app expects ASGI behavior. ## Working Directory diff --git a/skills/vercel-python/references/sdk-runtime-apis.md b/skills/vercel-python/references/sdk-runtime-apis.md index 3333eb9..d3670db 100644 --- a/skills/vercel-python/references/sdk-runtime-apis.md +++ b/skills/vercel-python/references/sdk-runtime-apis.md @@ -2,7 +2,7 @@ The official Python SDK for Vercel is the `vercel` package on PyPI. Do not use unofficial third-party packages for Vercel platform APIs. -The SDK requires Python 3.10+ and provides both synchronous and asynchronous APIs. It is under active development; refer to the [vercel package on PyPI](https://pypi.org/project/vercel/) for current API documentation and usage examples. +The SDK requires Python 3.10+ and provides both synchronous and asynchronous APIs. It is under active development and its API surface may change significantly between releases — concrete code examples are intentionally omitted here to avoid going stale. Refer to the [SDK README](https://github.com/vercel/vercel-py) for the latest code examples and the [vercel package on PyPI](https://pypi.org/project/vercel/) for release history. ## Capabilities @@ -20,8 +20,8 @@ The SDK provides Python clients for the following Vercel platform features: ## Middleware Pattern -Python web frameworks (FastAPI, Flask, Django) can call the SDK's `set_headers()` function at the start of each request to store Vercel-provided headers in a context variable. This enables OIDC token resolution and request helper functions to access Vercel headers without passing the request object explicitly. See the SDK README for the current middleware integration pattern. +Python web frameworks (FastAPI, Flask, Django) can call the SDK's `set_headers()` function at the start of each request to store Vercel-provided headers in a context variable. This enables OIDC token resolution and request helper functions to access Vercel headers without passing the request object explicitly. See the [SDK README](https://github.com/vercel/vercel-py) for the current middleware integration pattern. ## Import Guidance -Always use the `vercel` package for Vercel platform APIs. If code imports from an unofficial package, replace it with the official SDK. Refer to the SDK README for current import paths and examples. +Always use the `vercel` package for Vercel platform APIs. If code imports from an unofficial package, replace it with the official SDK. Refer to the [SDK README](https://github.com/vercel/vercel-py) for current import paths and examples. diff --git a/skills/vercel-python/references/troubleshooting.md b/skills/vercel-python/references/troubleshooting.md index 44d2d00..1c843ad 100644 --- a/skills/vercel-python/references/troubleshooting.md +++ b/skills/vercel-python/references/troubleshooting.md @@ -17,8 +17,12 @@ Use this reference when Vercel build output, runtime logs, or the inspector repo `DJANGO_ENTRYPOINT_NOT_FOUND` -- Move or expose `manage.py` at the project root or one directory below. -- Ensure the project includes importable Django settings. +- Confirm `manage.py` is at the project root or one directory below. +- Verify the settings module defines `ASGI_APPLICATION` or `WSGI_APPLICATION`: + ```bash + uv run manage.py diffsettings | grep -E 'WSGI_APPLICATION|ASGI_APPLICATION' + ``` +- Ensure required environment variables are set in the Vercel project so the settings module can import. `PYTHON_HANDLER_NOT_FOUND` @@ -37,7 +41,7 @@ Use this reference when Vercel build output, runtime logs, or the inspector repo - Check `[tool.vercel]` keys and Vercel function config. - Prefer simple `[tool.vercel].entrypoint` for entrypoint overrides. -`VERCEL_JSON_PARSE_ERROR` +`INVALID_VERCEL_JSON` - Fix invalid JSON in `vercel.json`. - Remove comments; JSON does not allow them. |
