Skip to main content

VercelPy

A Python wrapper for Vercel's storage services, providing a clean, Pythonic interface to Vercel Blob Storage and Edge Config.

PyPI version License: MIT

Installation

# Install with pip
pip3 install vercelpy

Features

  • Blob Storage: Upload, download, list, copy, and delete files with Vercel's Blob Storage
  • Edge Config: Store and retrieve configuration values with Vercel's Edge Config

Blob Storage

Vercel Blob is a global object storage service designed for serving content directly at the edge. VercelPy provides a simple interface for working with Vercel Blob.

Setup

Set your Blob Storage credentials via environment variables:

# In your .env file
BLOB_READ_WRITE_TOKEN=your_read_write_token

Usage Examples

Importing the Module

import vercelpy.blob_store as blob_store
# or with an alias
import vercelpy.blob_store as vb_store

List all files in the Blob Storage

# List all blobs with default limit (1000)
blobs = blob_store.list()

# With a limit
blobs = blob_store.list({
    'limit': '5',
})

# With pagination using cursor
blobs = blob_store.list({
    'limit': '4',
    'cursor': cursor,
})

# The response contains:
# blobs: List of blob objects with size, uploadedAt, pathname, url, downloadUrl
# cursor: Pagination cursor (if available)
# hasMore: Boolean indicating if more blobs are available
# folders: List of folder names (if available)

Upload File / Blob to the Storage

# Upload a file with random suffix
with open('file.txt', 'rb') as f:
    response = blob_store.put('test.txt', f.read())
    print(response)

# Upload without random suffix
with open('file.txt', 'rb') as f:
    response = blob_store.put('test.txt', f.read(), {
        "addRandomSuffix": "false",
    })
    print(response)

# The response contains:
# pathname: Path to the blob
# contentType: Content type of the blob
# contentDisposition: Content disposition of the blob
# url: URL of the blob
# downloadUrl: URL to download the blob

Downloading Files

# Download a file on the server
blob_store.download_file('blob_url', 'path/to/directory/', {'token': 'my_token'})

# If no directory is specified, it will download to the program's base directory

Checking Blob Metadata

# Get blob metadata
metadata = blob_store.head('blob_url')
print(metadata)

# The response contains:
# size: Size of the blob in bytes
# uploadedAt: Date when the blob was uploaded
# pathname: Path to the blob
# contentType: Content type of the blob
# contentDisposition: Content disposition of the blob
# url: URL of the blob
# downloadUrl: URL to download the blob
# cacheControl: Cache control header

Copying Blobs

# Copy a blob to a new location (without random suffix by default)
response = blob_store.copy("https://example.blob.vercel-storage.com/test.txt", "new-folder/test.txt")
print(response)

# To add random suffix when copying
response = blob_store.copy("https://example.blob.vercel-storage.com/test.txt", "new-folder/test.txt", {
    "addRandomSuffix": "true"
})

# The response contains pathname, contentType, contentDisposition, url, and downloadUrl

Deleting Blobs

# Delete a single blob
blob_store.delete('blob_url')

# Delete multiple blobs
blob_store.delete([
    'blob_url_1',
    'blob_url_2'
])

# The delete method doesn't return anything

Edge Config

Vercel Edge Config allows you to store and retrieve configuration values at the edge. VercelPy provides a convenient interface for working with Edge Config.

Setup

Set your Edge Config credentials via environment variables:

# In your .env file
EDGE_CONFIG=your_edge_config_connection_string

The connection string can be in either of these formats:

  • edge-config:id=your_id&token=your_token
  • https://edge-config.vercel.com/your_id?token=your_token

Usage Examples

Creating a Client

import vercelpy.edge_config as edge

# Create a client with environment variables
# This happens automatically when using module functions

# Create a client with a connection string
connection_string = "edge-config:id=your_id&token=your_token"
client = edge.create_client(connection_string)

# With options
client = edge.create_client(connection_string, {"consistentRead": True})

Getting a Value

import vercelpy.edge_config as edge

# Get a value with the default client (using EDGE_CONFIG env var)
value = edge.get("api_key")
print(f"API Key: {value}")

# Get with options for consistent reads
value = edge.get("feature_flags", {"consistentRead": True})

# Using a specific client
client = edge.create_client("your_connection_string")
value = client.get("database_url")

Checking if a Key Exists

import vercelpy.edge_config as edge

# Check if a key exists
if edge.has("feature_flag_new_ui"):
    print("Feature flag is set")

# With a specific client
client = edge.create_client("your_connection_string")
if client.has("rate_limit"):
    print("Rate limit is configured")

Getting Multiple Values

import vercelpy.edge_config as edge

# Get all values
all_config = edge.get_all()
print(f"All config: {all_config}")

# Get specific keys
settings = edge.get_all(["api_url", "timeout", "retry_count"])
print(f"API URL: {settings['api_url']}")
print(f"Timeout: {settings['timeout']}")

# With options
settings = edge.get_all(["api_key", "secret"], {"consistentRead": True})

Getting Configuration Digest

import vercelpy.edge_config as edge

# Get the configuration digest (for caching purposes)
digest_info = edge.digest()
print(f"Digest: {digest_info['digest']}")
print(f"Items Count: {digest_info['itemsCount']}")

Error Handling

import vercelpy.edge_config as edge
from vercelpy.edge_config.errors import EdgeConfigError, UnexpectedNetworkError

try:
    value = edge.get("api_key")
except Exception as e:
    if str(e) == EdgeConfigError.UNAUTHORIZED:
        print("Authentication failed")
    elif str(e) == EdgeConfigError.EDGE_CONFIG_NOT_FOUND:
        print("Edge Config not found")
    else:
        print(f"Unexpected error: {e}")

Common Issues

  1. Since Vercel Blob Storage is still in beta, requests may sometimes result in unexpected Connection Errors. The implementation uses a retry mechanism with exponential backoff to mitigate this issue.

Environment Variables

  • BLOB_READ_WRITE_TOKEN: Your Vercel Blob read-write token
  • EDGE_CONFIG: Your Edge Config connection string

License

MIT - See the LICENSE file for details.

Author

Surya Sekhar Datta hello@surya.dev

Links

Metadata

Release files for vercelpy 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vercelpy 0.2.1
File Size Uploaded Provenance Actions
vercelpy-0.2.1.tar.gz 6.3 kB Without provenance Details for vercelpy-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vercelpy 0.2.1
File Interpreter ABI Platform Actions
vercelpy-0.2.1-py3-none-any.whl Python 3 none any Details for vercelpy-0.2.1-py3-none-any.whl

Total release size: 14.6 kB

Release files / vercelpy-0.2.1.tar.gz

Download URL vercelpy-0.2.1.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
45ab13c65190b1545b3b75856fbaea09f85fec26e1e15265085c25a94fe53ac1
BLAKE2b-256 checksum
How to use checksums
9abf02cbce21218f7166578310b4bee03dcbd12eb333465734870153d86ca751
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.13.3 Darwin/24.5.0

Release files / vercelpy-0.2.1-py3-none-any.whl

Download URL vercelpy-0.2.1-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5fdfe156daebab81351b3e2ba2e22ec16d4b6455474b7026ac630dbc99b8dcfd
BLAKE2b-256 checksum
How to use checksums
395ef4bc488028b2b661076309d825165b3007910098bb7ca7d805bde83bbdf5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.13.3 Darwin/24.5.0

Security for vercelpy 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page