Skip to main content

A zero-knowledge, end-to-end encrypted secret management SDK for Python.

Project description

Redenv Python SDK

The official, zero-knowledge Python client for Redenv. Securely fetch, cache, and manage your environment variables at runtime.

PyPI - Version PyPI - License PyPI - Python Version

Features

  • 🔒 Zero-Knowledge: End-to-End Encryption. Secrets are decrypted locally using your Project Encryption Key (PEK).
  • ⚡ High Performance: In-memory LRUCache with Stale-While-Revalidate strategy for zero-latency reads.
  • 🔄 Universal: Native Async (asyncio) and Synchronous clients included.
  • 🛠️ Developer Experience:
    • Smart Casting: secrets.get("PORT", cast=int)
    • Scoping: secrets.scope("STRIPE_") for namespaced configs.
    • Validation: secrets.require("API_KEY") fail-fast checks.
    • Time Travel: Fetch historical versions of secrets.
  • 🛡️ Secure by Default: Secrets are masked (********) in logs to prevent accidental leaks.

Installation

pip install redenv

Quick Start

Async Client (FastAPI / Modern Apps)

import asyncio
import os
from redenv import Redenv

async def main():
    client = Redenv({
        "project": os.getenv("REDENV_PROJECT"),
        "token_id": os.getenv("REDENV_TOKEN_ID"),
        "token": os.getenv("REDENV_TOKEN_KEY"),
        "upstash": {
            "url": os.getenv("UPSTASH_REDIS_URL"),
            "token": os.getenv("UPSTASH_REDIS_TOKEN")
        }
    })

    # 1. Load Secrets (Populates os.environ by default)
    secrets = await client.load()
    
    # 2. Access Secrets
    print(f"Database URL: {secrets['DATABASE_URL']}")
    
    # 3. Smart Casting
    port = secrets.get("PORT", cast=int)
    debug = secrets.get("DEBUG", cast=bool)

if __name__ == "__main__":
    asyncio.run(main())

Synchronous Client (Flask / Scripts / Legacy)

Perfect for scripts or frameworks where async/await is not available at the top level.

from redenv import RedenvSync

client = RedenvSync({ ... }) # Same config as above

# Blocks until secrets are fetched
secrets = client.load()

print(secrets["API_KEY"])

Advanced Usage

1. Scoping & Validation

Organize large configurations and ensure critical keys exist.

secrets = await client.load()

# Fail if these keys are missing
secrets.require("STRIPE_KEY", "STRIPE_WEBHOOK")

# Create a subset of keys (e.g., keys starting with "STRIPE_")
# The prefix is automatically stripped.
stripe_config = secrets.scope("STRIPE_")

print(stripe_config["KEY"])     # Maps to STRIPE_KEY
print(stripe_config["WEBHOOK"]) # Maps to STRIPE_WEBHOOK

2. Time Travel (Version History)

Redenv stores a history of every secret change. You can access older versions for rollbacks or auditing.

# Get the absolute version 5
v5 = await client.get_version("API_KEY", 5)

# Get the previous version (1 version older than latest)
# Mode="index": 0=Latest, 1=Previous, -1=Oldest
prev = await client.get_version("API_KEY", 1, mode="index")

# Get the oldest version ever created
first = await client.get_version("API_KEY", -1)

3. Writing Secrets

You can update secrets programmatically. This automatically encrypts the value, increments the version, and updates the history.

await client.set("FEATURE_FLAG", "true")

4. Configuration Options

Option Type Description Default
project str Your Project ID Required
token_id str Service Token Public ID Required
token str Service Token Secret Key Required
upstash dict { url: ..., token: ... } Required
environment str Target environment (dev, prod) development
log str Log level (none, low, high) low
cache dict { ttl: 300, swr: 86400 } (seconds) 5min / 24h
env.override bool Overwrite existing os.environ keys True
client = Redenv({
    # ...
    "env": {
        "override": False # Protects local env vars from being overwritten
    }
})

Security

  • Masking: If you accidentally print the secrets object, values are hidden: Secrets({'API_KEY': '********'}).
  • Zero-Knowledge: The server (Upstash) never sees the plaintext. Decryption happens only in your application's memory.

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

redenv-0.2.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

redenv-0.2.0-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file redenv-0.2.0.tar.gz.

File metadata

  • Download URL: redenv-0.2.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for redenv-0.2.0.tar.gz
Algorithm Hash digest
SHA256 14be97dcabb8ffd2ab2cfa19cae7bca46adaeef8bcd608690a83a54f5cfd8478
MD5 5370c3424fa4d02b766561b3d3936636
BLAKE2b-256 f0a1e8e5c73ece7525f29bcce50d6188c05ef25089e6df064363802c917092fe

See more details on using hashes here.

File details

Details for the file redenv-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: redenv-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for redenv-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c3a4efe433280def81adc6261ef8dd020a1b5067ecddc4162903d4ddc1e75341
MD5 a6d3656dccc3bdb796c4f93a1ab97042
BLAKE2b-256 3a27bc668cd5f2ae45c53cda1533db8d288792e15a2ecb240c6c50a65cd0d98b

See more details on using hashes here.

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