diff options
Diffstat (limited to 'skills/vercel-python')
| -rw-r--r-- | skills/vercel-python/SKILL.md | 53 | ||||
| -rw-r--r-- | skills/vercel-python/references/dependencies-and-versions.md | 24 | ||||
| -rw-r--r-- | skills/vercel-python/references/frameworks.md | 38 | ||||
| -rw-r--r-- | skills/vercel-python/references/runtime-and-entrypoints.md | 32 | ||||
| -rw-r--r-- | skills/vercel-python/references/sdk-runtime-apis.md | 6 | ||||
| -rw-r--r-- | skills/vercel-python/references/troubleshooting.md | 10 |
6 files changed, 102 insertions, 61 deletions
diff --git a/skills/vercel-python/SKILL.md b/skills/vercel-python/SKILL.md index 6351dd8..fc1d73e 100644 --- a/skills/vercel-python/SKILL.md +++ b/skills/vercel-python/SKILL.md @@ -1,6 +1,6 @@ --- name: vercel-python -description: Diagnose, fix, and prepare Python projects for Vercel deployments. Use for FastAPI, Flask, Django, ASGI/WSGI, Python entrypoints, pyproject.toml, requirements.txt, uv, .python-version, bundle size, Python runtime errors, or Vercel's Python SDK/runtime APIs. +description: Diagnose, fix, and prepare Python projects for Vercel deployments. Use for FastAPI, Flask, Django, ASGI/WSGI, Python entrypoints, pyproject.toml, requirements.txt, uv, .python-version, bundle size, Python runtime errors, or Vercel's Python SDK/runtime APIs. Use this skill whenever the user mentions Python and Vercel in the same context, even if they don't explicitly ask for deployment help. metadata: author: vercel version: "1.0.0" @@ -10,36 +10,32 @@ metadata: Use this skill when a Vercel deployment involves Python, including FastAPI, Flask, Django, generic ASGI/WSGI apps, Python runtime diagnostics, dependency resolution, Python version selection, bundle size issues, or the `vercel` Python SDK. -This skill handles Python-specific diagnosis and remediation. For the actual deployment flow, use a deployment skill if one is available. For CLI auth, environment variables, domains, or logs, use the Vercel CLI or a CLI-focused skill if available. +This skill diagnoses and fixes Python-specific deployment issues. It does not handle the deployment itself. ## How It Works 1. **Inspect the project structure** before changing any files. Check the following: - **Entrypoint:** Look for these files in the project root, then in `src/`, `app/`, and `api/` subdirectories: - - `app.py`, `index.py`, `server.py`, `main.py`, `wsgi.py`, `asgi.py` + **Entrypoint:** Identify the app entrypoint and confirm it exposes a supported top-level callable (`app`, `application`, or `handler`). The entrypoint priority is: `[tool.vercel].entrypoint` in `pyproject.toml`, then framework-specific discovery (Django uses the settings module; others use conventional files like `app.py`, `main.py`, etc.), then `[project.scripts].app` (legacy). For Django projects, if `manage.py` exists at the root or one directory below, check that the settings module defines `ASGI_APPLICATION` or `WSGI_APPLICATION`. See `references/runtime-and-entrypoints.md` for full details. - If found, read the file and check for a top-level `app`, `application`, or `handler` symbol (variable assignment, function, or class). If none of these symbols exist, the deployment will fail at build time. + **Dependencies:** Identify the dependency manifest. Vercel discovers manifests from the entrypoint directory upward to the project root. The highest-priority manifest wins: `pyproject.toml` > `Pipfile.lock` / `Pipfile` > `requirements.txt` (and variants like `requirements.frozen.txt`, `requirements.in`, `requirements/prod.txt`). Check for a lockfile: `uv.lock` or `pylock.toml` (used with `pyproject.toml` projects). See `references/dependencies-and-versions.md` for the full priority list. - If the project uses a nonstandard entrypoint path, check `pyproject.toml` for `[tool.vercel].entrypoint`. + **Bundle size:** Vercel Python functions support up to [500 MB](https://vercel.com/docs/functions/limitations#bundle-size-limits). Do not use 250 MB as the limit. When a `uv.lock` is present, the builder can automatically externalize large public PyPI packages and install them at cold start, allowing even larger dependency sets. See `references/dependencies-and-versions.md` for size reduction strategies. - **Dependencies:** Identify the dependency manifest. Vercel uses this priority: - 1. `pyproject.toml` - 2. `Pipfile.lock` / `Pipfile` - 3. `requirements.txt` (and variants: `requirements.frozen.txt`, `requirements.in`) + **Python version:** Check `.python-version` (takes priority) and `project.requires-python` in `pyproject.toml`. Vercel supports Python 3.12, 3.13, and 3.14 for new projects. Only flag a version as blocking if it excludes all supported versions (e.g., `==3.11.*`, `<3.12`, `>=3.15`). A range like `>=3.11` is fine because it includes 3.12+. - Check for a lockfile: `uv.lock` or `pylock.toml` (used with `pyproject.toml` projects). + **Database:** If the project requires a database (PostgreSQL, MySQL, etc.), note that Vercel Marketplace provides managed database integrations (Neon Postgres, Supabase, AWS RDS) that automatically set connection environment variables. Do not assume the app cannot connect to a database on Vercel. See `references/frameworks.md` for details. - **Python version:** Check `.python-version` (takes priority, skip comment lines starting with `#`) and `project.requires-python` in `pyproject.toml`. Vercel supports Python 3.12, 3.13, and 3.14 for new projects. Only flag a version as blocking if it excludes all supported versions (e.g., `==3.11.*`, `<3.12`, `>=3.15`). A range like `>=3.11` is fine because it includes 3.12+. + **Vercel config:** If `vercel.json` exists, check for custom `buildCommand` or `installCommand` (these can limit dependency optimization). - **Django:** If `manage.py` exists at the root or one directory below, look for a settings file containing `ASGI_APPLICATION` or `WSGI_APPLICATION`. + **Monorepo:** If the Python app is in a subdirectory of a monorepo, confirm `rootDirectory` is set correctly in the Vercel project settings. The builder resolves `uv.lock` from the workspace root automatically for uv workspace projects. - **Vercel config:** If `vercel.json` exists, check for custom `buildCommand` or `installCommand` (these can limit dependency optimization). + **Background workers:** If the project uses task queues, background jobs, or event-driven workers (Celery, Dramatiq, Django tasks, or similar), check `references/frameworks.md` for Vercel's worker service support via the `vercel-workers` package. Do not assume background processing is incompatible with Vercel. 2. **Identify blockers and risks** from what you found: - - **Blocking:** No entrypoint file, no callable symbol, Python version outside supported range, malformed config files, Django without `manage.py`. + - **Blocking:** No entrypoint file and no configurable path, no callable symbol, Python version that excludes all supported versions, malformed config files, Django without `manage.py`. - **Risk:** No dependency manifest, custom build/install commands, Django without ASGI/WSGI settings. - - **Info:** Which manifest, lockfile, and Python version source were detected. + - **Info:** Which manifest, lockfile, and Python version source were detected. Nonstandard entrypoint path (fixable with `[tool.vercel].entrypoint`). 3. Read only the reference file that matches the problem: - Entry points and runtime behavior: `references/runtime-and-entrypoints.md` @@ -50,16 +46,31 @@ This skill handles Python-specific diagnosis and remediation. For the actual dep 4. Make the smallest safe project change that addresses the root cause, or give the user exact remediation when credentials, missing env vars, or account state block progress. -5. When the Python project is ready, proceed with deployment. If a deployment skill is available, use it. Deploy as preview unless the user explicitly asks for production. +5. **Verify.** Re-check the project against the same checklist from step 1. Confirm that no blocking findings remain and all risks have been documented or addressed. + +## Exit Criteria + +This skill's job is done when the Python project has no blocking deployment issues. It does not handle deployment, auth, environment variables, domains, or logs. + +## Common Misconceptions + +Do not accept these conclusions without checking the reference docs first: + +| Claim | Reality | +|---|---| +| "The bundle is too large for Vercel" | The limit is 500 MB, not 250 MB. With `uv.lock`, the builder externalizes public packages beyond that. | +| "This app requires a database, so it can't deploy to Vercel" | Vercel Marketplace provides Neon Postgres, Supabase, and AWS RDS integrations. | +| "Background processing is impossible on Vercel" | Vercel supports worker services via `vercel-workers` with Celery, Dramatiq, and Django task adapters. | +| "Vercel doesn't support uv workspaces or monorepos" | It does. The builder resolves `uv.lock` from the workspace root. | +| "This entrypoint path isn't supported" | Any path works with `[tool.vercel].entrypoint` in `pyproject.toml`. | +| "Python version X.Y isn't compatible" | Only blocking if the range excludes all of 3.12, 3.13, and 3.14. Ranges like `>=3.11` are fine. | ## Present Results to User Lead with the concrete blocker or readiness status: ```text -I inspected the Python project. Vercel should use `app/main.py` as the entrypoint with `app` as the ASGI callable. - -The deployment blocker is `requires-python = ">=3.15"` in `pyproject.toml`; Vercel currently supports Python 3.12, 3.13, and 3.14 for new Python deployments. I can change this to a supported range and then deploy a preview. +I inspected the Python project. Vercel should use `app/main.py` as the entrypoint with `app` as the ASGI callable. No blocking issues found. ``` When several findings exist, group them by deployment impact: @@ -75,5 +86,3 @@ When several findings exist, group them by deployment impact: - FastAPI, Flask, Django, static assets, or `collectstatic` issues: inspect `references/frameworks.md`. - Vercel diagnostic codes such as `PYTHON_ENTRYPOINT_NOT_FOUND`, `PYTHON_HANDLER_NOT_FOUND`, `DJANGO_SETTINGS_FAILED`, `PYTHON_REQUIREMENTS_PARSE_ERROR`, `PYTHON_DEPENDENCY_SYNC_FAILED`, or `LAMBDA_SIZE_EXCEEDED`: inspect `references/troubleshooting.md`. - Runtime helper APIs such as Blob storage, OIDC, caching, geolocation, or cron scheduling: inspect `references/sdk-runtime-apis.md`. - -This skill is for preparing and fixing Python apps. Once the project is ready, hand off deployment, auth, environment variables, domains, and logs to the appropriate tools or skills. 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. |
