Configuration

All configuration options for the Redenv Python SDK.

The Redenv and RedenvSync constructors accept a configuration dictionary. Here's a complete example:

config/redenv.py
from redenv import Redenv  # or RedenvSync

redenv = Redenv({
    # Required
    "project": "my-app",
    "token_id": "stk_yYt2HXRprwYgpvwv",
    "token": "redenv_sk_8f3a9b2c...",
    "upstash": {
        "url": "https://your-redis.upstash.io",
        "token": "AXxxxxxxxxxxxxxxx",
    },

    # Optional
    "environment": "production",
    "cache": {"ttl": 300, "swr": 86400},
    "env": {"override": True},
    "log": "low",
})

All Options#

OptionTypeRequiredDefaultDescription
projectstrYesYour Redenv project name
token_idstrYesService Token public ID (stk_...)
tokenstrYesService Token secret key (redenv_sk_...)
upstash.urlstrYesUpstash Redis REST URL
upstash.tokenstrYesUpstash Redis REST Token
environmentstrNo"development"Environment to fetch secrets from
cache.ttlintNo300Seconds before data is stale
cache.swrintNo86400Seconds stale data can be served while refreshing
env.overrideboolNoTrueOverwrite existing os.environ variables
log"none" | "low" | "high"No"low"Logging verbosity

Warning

Never hardcode credentials. Load them from environment variables. These "bootstrap" secrets are the only ones you manage outside Redenv.

Option Details#

environment#

ValueDescription
"development"Default. Local development
"staging"Pre-production testing
"production"Live production secrets
Any custom stringYour own environment names
import os
redenv = Redenv({
    # ...
    "environment": os.getenv("ENVIRONMENT", "development"),
})

cache#

Uses stale-while-revalidate strategy. Preset configurations:

Use CaseTTLSWRExample
Default30086400General purpose
High-frequency updates1060Feature flags, A/B tests
Stable secrets360086400API keys, database URLs
Serverless30300AWS Lambda (ephemeral instances)
Development530See changes quickly

Info

For a deep dive into how caching works, scale impact, and architecture, see Caching Strategy.

env.override#

When False, existing os.environ variables are preserved. Useful for local .env overrides during development.

redenv = Redenv({
    # ...
    "env": {"override": False},
})

log#

ValueDescription
"none"No logs
"low"Errors and important info only
"high"Verbose logging (cache hits/misses, refreshes)

Example output with "high":

[REDENV] Cache HIT (fresh): redenv:my-app:production
[REDENV] Cache HIT (stale): redenv:my-app:production - triggering background refresh
[REDENV] Cache MISS: redenv:my-app:staging - fetching from Redis

Best Practice: Singleton Pattern#

Create a single Redenv instance and import it elsewhere. This ensures cache is shared across your app:

config/redenv.py
import os
from redenv import Redenv

redenv = Redenv({
    "project": os.environ["REDENV_PROJECT"],
    "token_id": os.environ["REDENV_TOKEN_ID"],
    "token": os.environ["REDENV_TOKEN_KEY"],
    "upstash": {
        "url": os.environ["UPSTASH_REDIS_URL"],
        "token": os.environ["UPSTASH_REDIS_TOKEN"],
    },
    "environment": os.getenv("ENVIRONMENT", "development"),
})
config/redenv.py
import os
from redenv import RedenvSync

redenv = RedenvSync({
    "project": os.environ["REDENV_PROJECT"],
    "token_id": os.environ["REDENV_TOKEN_ID"],
    "token": os.environ["REDENV_TOKEN_KEY"],
    "upstash": {
        "url": os.environ["UPSTASH_REDIS_URL"],
        "token": os.environ["UPSTASH_REDIS_TOKEN"],
    },
    "environment": os.getenv("ENVIRONMENT", "development"),
})
anywhere else
from config.redenv import redenv

secrets = redenv.load()  # or await redenv.load() for async