Python SDK for Vercel
Project description
vercel-sdk
Python SDK for Vercel.
Installation
pip install vercel-sdk
Requirements
- Python 3.9+
Usage
Headers and request context
from vercel.headers import geolocation, ip_address
# In a framework handler, pass request.headers
city_info = geolocation(request)
client_ip = ip_address(request.headers)
Runtime Cache
The SDK talks to Vercel’s Runtime Cache when the following env vars are present; otherwise it falls back to an in-memory cache.
RUNTIME_CACHE_ENDPOINT: base URL of the runtime cache API (e.g. https://cache.vercel.com/...)RUNTIME_CACHE_HEADERS: JSON object of headers to send (e.g. '{"authorization": "Bearer "}')- Optional:
SUSPENSE_CACHE_DEBUG=trueto log fallback behavior
import asyncio
from vercel.cache import get_cache
async def main():
cache = get_cache(namespace="demo")
await cache.delete("greeting")
await cache.set("greeting", {"hello": "world"}, {"ttl": 60, "tags": ["demo"]})
value = await cache.get("greeting") # dict or None
await cache.expire_tag("demo") # invalidate by tag
asyncio.run(main())
OIDC (Vercel project tokens)
If the VERCEL_OIDC_TOKEN header is not present, the SDK will try to refresh a token using the local Vercel CLI session and your project configuration.
import asyncio
from vercel.oidc import get_vercel_oidc_token, decode_oidc_payload
async def main():
token = await get_vercel_oidc_token()
payload = decode_oidc_payload(token)
sub = payload.get("sub")
asyncio.run(main())
Notes:
- Requires a valid Vercel CLI login on the machine running the code for refresh.
- Project info is resolved from
.vercel/project.json.
Examples
See examples/ for runnable scripts:
runtime_cache_basic.py: set/get with fallback to in-memorycache_tags.py: tag-based invalidationbuild_cache_env.py: shows behavior when cache env vars are setfastapi_oidc_plus_cache/: small FastAPI demo wiring headers/oidc
Development
- Lint/typecheck/tests:
uv pip install -e .[dev]
uv run ruff format --check && uv run ruff check . && uv run mypy src && uv run pytest -v
- CI runs lint, typecheck, examples as smoke tests, and builds wheels.
- Publishing: push a tag (
vX.Y.Z) that matchesproject.versionto publish via PyPI Trusted Publishing.
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vercel_sdk-0.0.5.tar.gz.
File metadata
- Download URL: vercel_sdk-0.0.5.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c4b24cfbdc0ea0d27e6387c56fff520ce701df291370649f051764db1adb968
|
|
| MD5 |
64b1e528e681fa13c140576f6fa7dd86
|
|
| BLAKE2b-256 |
9a661823b0b38a00706cccc87a71b75a5798cb8a0b1c0fceb68b459f2a882249
|
Provenance
The following attestation bundles were made for vercel_sdk-0.0.5.tar.gz:
Publisher:
publish.yml on vercel/vercel-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vercel_sdk-0.0.5.tar.gz -
Subject digest:
3c4b24cfbdc0ea0d27e6387c56fff520ce701df291370649f051764db1adb968 - Sigstore transparency entry: 591240069
- Sigstore integration time:
-
Permalink:
vercel/vercel-py@540467fd80d40c005ec25cf4896717cfa41251de -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/vercel
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@540467fd80d40c005ec25cf4896717cfa41251de -
Trigger Event:
push
-
Statement type:
File details
Details for the file vercel_sdk-0.0.5-py3-none-any.whl.
File metadata
- Download URL: vercel_sdk-0.0.5-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5efb7ad0eaad591212e183eddbca10b5633fc58bb0bc039d5659fcdf7743bd1
|
|
| MD5 |
5f85542ae637413d4a18f886281582ab
|
|
| BLAKE2b-256 |
e3f5f8c1d67ba101c1aaa4ac5ca30416c733a305de9a151349138d4e279c093d
|
Provenance
The following attestation bundles were made for vercel_sdk-0.0.5-py3-none-any.whl:
Publisher:
publish.yml on vercel/vercel-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vercel_sdk-0.0.5-py3-none-any.whl -
Subject digest:
b5efb7ad0eaad591212e183eddbca10b5633fc58bb0bc039d5659fcdf7743bd1 - Sigstore transparency entry: 591240078
- Sigstore integration time:
-
Permalink:
vercel/vercel-py@540467fd80d40c005ec25cf4896717cfa41251de -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/vercel
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@540467fd80d40c005ec25cf4896717cfa41251de -
Trigger Event:
push
-
Statement type: