Skip to main content

Python SDK for Vercel

Project description

vercel-sdk

Python SDK for Vercel.

Installation

pip install vercel-sdk

Requirements

  • Python 3.10+

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=true to log fallback behavior
from vercel.cache import get_cache

def main():
    cache = get_cache(namespace="demo")

    cache.delete("greeting")
    cache.set("greeting", {"hello": "world"}, {"ttl": 60, "tags": ["demo"]})
    value = cache.get("greeting")  # dict or None
    cache.expire_tag("demo")        # invalidate by tag

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.

from vercel.oidc import get_vercel_oidc_token, decode_oidc_payload

def main():
    token = get_vercel_oidc_token()
    payload = decode_oidc_payload(token)
    sub = payload.get("sub")

main()

Notes:

  • Requires a valid Vercel CLI login on the machine running the code for refresh.
  • Project info is resolved from .vercel/project.json.

Blob Storage

The SDK includes a Blob client for uploading, listing, downloading, copying, and deleting objects in Vercel Blob.

  • Required: set BLOB_READ_WRITE_TOKEN or pass token when constructing a client

Async usage:

import asyncio
from vercel.blob import AsyncBlobClient

async def main():
    client = AsyncBlobClient()  # uses BLOB_READ_WRITE_TOKEN from env

    # Upload bytes
    uploaded = await client.put(
        "examples/assets/hello.txt",
        b"hello from python",
        access="public",
        content_type="text/plain",
    )

    # Inspect metadata, list, download bytes, then delete
    meta = await client.head(uploaded.url)
    listing = await client.list_objects(prefix="examples/assets/")
    content = await client.get(uploaded.url)
    await client.delete([b.url for b in listing.blobs])

asyncio.run(main())

Synchronous usage:

from vercel.blob import BlobClient

client = BlobClient()  # or BlobClient(token="...")

# Create a folder entry, upload a local file, list, then download
client.create_folder("examples/assets", overwrite=True)
uploaded = client.upload_file(
    "./README.md",
    "examples/assets/readme-copy.txt",
    access="public",
    content_type="text/plain",
)
listing = client.list_objects(prefix="examples/assets/")
client.download_file(uploaded.url, "/tmp/readme-copy.txt", overwrite=True)

Examples

See examples/ for runnable scripts:

  • runtime_cache_basic.py: set/get with fallback to in-memory
  • cache_tags.py: tag-based invalidation
  • build_cache_env.py: shows behavior when cache env vars are set
  • blob_storage.py: end-to-end blob operations (sync and async)
  • fastapi_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 matches project.version to 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

vercel_sdk-0.0.6.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vercel_sdk-0.0.6-py3-none-any.whl (35.3 kB view details)

Uploaded Python 3

File details

Details for the file vercel_sdk-0.0.6.tar.gz.

File metadata

  • Download URL: vercel_sdk-0.0.6.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vercel_sdk-0.0.6.tar.gz
Algorithm Hash digest
SHA256 e50b4cae1f81a3319e8723dd610baf599e8dfdb8ec77259d9cafc5eecad6194a
MD5 5a038def1038450fa31773541458879d
BLAKE2b-256 865d0c034a26b476034b19a70f9f69bdcffb698aad5c1e1d0b2577bc11b6d8f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for vercel_sdk-0.0.6.tar.gz:

Publisher: publish.yml on vercel/vercel-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vercel_sdk-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: vercel_sdk-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 35.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vercel_sdk-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2d8e02388a9a5eb1b4b98d0f7a5f3e9b6b4703be8469c96e72eea9a05bb89859
MD5 45bd7a321f2b69b5692cef7949d51c93
BLAKE2b-256 cf3adb5d2cd4ccd07e2402b4d364892ebb8b9f111ea6bcb5b85cbf2d4aa376f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for vercel_sdk-0.0.6-py3-none-any.whl:

Publisher: publish.yml on vercel/vercel-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page