Skip to content
GitHub

Secrets (lexigram-secrets)

Secret vaults with rotation, tenant isolation, and audit logging for the Lexigram Framework. Supports HashiCorp Vault, AWS Secrets Manager, GCP Secret Manager, Azure Key Vault, and in-memory backends with automatic key rotation, version tracking, and tenant-scoped secret stores.


lexigram-secrets provides a RotatableSecretStoreProtocol-based secret management system with versioned rotation, tenant isolation, audit logging, and pluggable backends. All services are wired via SecretsProvider, which registers the secret store and rotation decorator with the DI container.

Full documentation: docs.lexigram.dev

Terminal window
uv add lexigram-secrets
# Optional extras
uv add "lexigram-secrets[vault]" # HashiCorp Vault backend
uv add "lexigram-secrets[aws]" # AWS Secrets Manager backend
uv add "lexigram-secrets[gcp]" # GCP Secret Manager backend
uv add "lexigram-secrets[azure]" # Azure Key Vault backend
from lexigram import Application
from lexigram.secrets import SecretsModule
from lexigram.secrets.types import RotatableSecretStoreProtocol
async def main() -> None:
async with Application.boot(modules=[SecretsModule.configure()]) as app:
store = await app.container.resolve(RotatableSecretStoreProtocol)
# ... work with the secret store ...
if __name__ == "__main__":
import asyncio
asyncio.run(main())
FieldDefaultEnv varDescription
name"secrets"LEX_SECRETS__NAMEConfiguration name
enabledtrueLEX_SECRETS__ENABLEDEnable the secrets subsystem
backend_typememoryLEX_SECRETS__BACKEND_TYPEBackend store type (memory, vault, aws, gcp, azure)
backend_options{}Keyword arguments forwarded to the backend constructor
max_age_seconds7776000LEX_SECRETS__MAX_AGE_SECONDSMax age before automatic rotation
warning_before_seconds86400LEX_SECRETS__WARNING_BEFORE_SECONDSSeconds before expiry to emit warnings
tenant_idnullLEX_SECRETS__TENANT_IDOptional tenant namespace
audit_actor_id"secrets-system"LEX_SECRETS__AUDIT_ACTOR_IDActor identifier for audit logs
MethodDescription
SecretsModule.configure(config)Configure with explicit SecretsConfig
SecretsModule.stub()Minimal config for testing (memory backend)
  • Versioned secrets — Every set and rotate creates a new version; full history retained
  • Automatic rotationRotationDecorator (get_rotated, get_current_version, check_warnings) serves a fresh secret when the current version is past max_age_seconds
  • Tenant isolationTenantScopedSecretStore prefixes keys per tenant for multi-tenant apps
  • Audit loggingSecretAuditDecorator logs all store operations through AuditLoggerProtocol
  • Pluggable backendsHashicorpVaultStore (KV v2) and in-memory (FakeRotatableSecretStore)
  • Bulk operationsget_bulk for fetching multiple secrets at once
  • Version introspectionlist_versions and get_version for audit and rollback workflows
from lexigram.testing.fakes import FakeRotatableSecretStore
from lexigram.testing.compliance import StoreConformanceSuite
class TestMyStore(StoreConformanceSuite):
@pytest.fixture
def make_store(self):
return FakeRotatableSecretStore
FileWhat it contains
src/lexigram/secrets/module.pySecretsModule class with factory methods
src/lexigram/secrets/di/provider.pySecretsProvider — wires secret store into DI container
src/lexigram/secrets/config.pySecretsConfig and backend selection
src/lexigram/secrets/types.pyRotatableSecretStoreProtocol, VersionedSecret, SecretVersion
src/lexigram/secrets/rotation/RotationDecorator and RotationSchedule for automatic key rotation
src/lexigram/secrets/tenancy/TenantScopedSecretStore for multi-tenant key isolation
src/lexigram/secrets/audit/SecretAuditDecorator for operation audit logging
src/lexigram/secrets/backends/Backend implementations (Vault, etc.)