Skip to main content

Python SDK for PersonalVault - secure API key retrieval

Project description

PersonalVault Python SDK

Secure API key retrieval for Python backend applications.

Installation

pip install ripv-py

Quick Start

Environment Variables

export PV_API_KEY="pvault_bk_..."       # Required - your backend key
export PV_API_URL="https://pv.sprkt.xyz"  # Optional - defaults to https://pv.sprkt.xyz
export PV_CACHE_TTL="3600"              # Optional - cache TTL in seconds (default: 3600)

Synchronous (Django, Flask)

import pv

# Initialize once at startup
pv.init()

# Call the module directly to retrieve keys
openai_key = pv("OPENAI_API_KEY")
db_password = pv("DB_PASS")

Or with named imports:

from pv import init, pv

init()
openai_key = pv("OPENAI_API_KEY")

Asynchronous (FastAPI, AIOHTTP)

from pv import pv_async

# Auto-initializes on first call, then serves from cache
openai_key = await pv_async("OPENAI_API_KEY")
db_password = await pv_async("DB_PASS")

API Reference

init() -> None

Synchronously fetch and cache all allowed keys. Blocks until complete.

pv(key_name: str) -> str

Synchronous cache lookup. Raises PVNotInitializedError if init() hasn't been called or cache has expired.

pv_async(key_name: str) -> str

Async key retrieval. Automatically initializes/refreshes the cache when needed.

Exceptions

Exception When
PVAuthError PV_API_KEY missing, invalid, or expired
PVDeniedError Server rejected request (IP allowlist, etc.)
PVKeyNotFoundError Key not in vault or not allowed for this backend key
PVNotInitializedError pv() called before init() or cache expired

Framework Examples

FastAPI

from contextlib import asynccontextmanager
from fastapi import FastAPI
from pv import pv_async, pv

@asynccontextmanager
async def lifespan(app: FastAPI):
    await pv_async("DB_URL")  # warm the cache
    yield

app = FastAPI(lifespan=lifespan)

@app.get("/")
async def root():
    return {"db": pv("DB_URL")}

Flask

from flask import Flask
from pv import init, pv

app = Flask(__name__)
init()  # fetch keys at import time

@app.route("/")
def index():
    return {"db": pv("DB_URL")}

Django (settings.py)

from pv import init, pv

init()

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "PASSWORD": pv("DB_PASS"),
    }
}

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

ripv_py-1.0.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

ripv_py-1.0.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file ripv_py-1.0.1.tar.gz.

File metadata

  • Download URL: ripv_py-1.0.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for ripv_py-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b19ebcb9ca027558e7b23fb7c6acc653ab6b0724be669f16627059805265454f
MD5 86e637e4d1ef66b532ffc9373ac610d6
BLAKE2b-256 913d89f9cb1d55ed20339a27a08f4eb42c173ba5d046d07c56c49ae86e26a179

See more details on using hashes here.

File details

Details for the file ripv_py-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: ripv_py-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for ripv_py-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 83ccf313d979965164a0726a5fdafa04124c01efb090fe83dd0b8e7c89eb1864
MD5 cf6e3c37854f752b38b73b4d9f559fa8
BLAKE2b-256 37af1758544a1e4e445c77f461b2240f9bdf03fd6a9babda8fc2b0f3c982d993

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