Upstash Python SDK
Unified Python SDK for Upstash cloud services including Redis, Vector, QStash, and Workflow. Provides serverless-friendly clients optimized for edge and serverless environments with HTTP-based connections. Replaces the older individual packages (upstash-redis, upstash-vector, upstash-qstash).
Warnings
- gotcha Upstash Redis uses HTTP REST calls, not the Redis wire protocol. Standard redis-py commands that rely on persistent TCP connections (SUBSCRIBE, BLPOP, WATCH) are not supported.
- gotcha Redis.from_env() reads UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN from environment. These must be the REST endpoint, not the standard Redis port 6379 URL.
- breaking The unified 'upstash' package changed internal module structure. Imports like 'from upstash.redis import Redis' do not work. Use 'from upstash_redis import Redis'.
- gotcha Redis.get() returns None for missing keys, not raising a KeyError. Pipeline results are returned as a list, not individual values.
- gotcha Each Redis command makes an individual HTTP request. Use pipelines to batch multiple commands and reduce latency.
- deprecated The separate upstash-redis, upstash-vector, and upstash-qstash packages are being consolidated into the unified upstash package. Individual packages still work but may not receive updates.
Install
-
pip install upstash -
pip install upstash-redis -
pip install upstash-vector -
pip install upstash-qstash
Imports
- Redis
from upstash_redis import Redis
- Index
from upstash_vector import Index
- QStash
from upstash_qstash import QStash
Quickstart
import os
from upstash_redis import Redis
redis = Redis(
url=os.environ.get('UPSTASH_REDIS_REST_URL', ''),
token=os.environ.get('UPSTASH_REDIS_REST_TOKEN', '')
)
redis.set('greeting', 'Hello from Upstash!')
value = redis.get('greeting')
print(value)