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 personalvault

Quick Start

Environment Variables

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

Synchronous (Django, Flask)

from personalvault import init, pv

# Initialize once at startup
init()

# Retrieve keys instantly from cache
openai_key = pv("OPENAI_API_KEY")
db_password = pv("DB_PASS")

Asynchronous (FastAPI, AIOHTTP)

from personalvault 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 personalvault 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 personalvault 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 personalvault 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.0.tar.gz (5.6 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.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ripv_py-1.0.0.tar.gz
  • Upload date:
  • Size: 5.6 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.0.tar.gz
Algorithm Hash digest
SHA256 7c79c959495978bbfef663e594cd789e5c1e7f4339f0f09c199de198da1d3c86
MD5 1ab12c0a4793cddf29ee795316288d14
BLAKE2b-256 f45bdd0afa64418003668513c14454a7c3c8ce81498d573b741a2d2432b6409d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ripv_py-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca9742bcb981977fbf404969ff7612b7a448f387560c028ea892d582c855cc59
MD5 67afb9729ef7b55d0010ab2b8c173e0f
BLAKE2b-256 ec5c5c80f14ec16e0a69dd1c433c811daf1a68e5e9b198b80d6a1b44f3b5de4e

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