Skip to main content

Python client for SecureVault - secure secrets management

Project description

SecureVault Python Client

Python wrapper for the SecureVault CLI tool.

Installation

pip install securevault

Or install from source:

cd wrappers/python
pip install -e .

Prerequisites

  • SecureVault CLI must be installed and available in your PATH
  • Python 3.7 or higher

Quick Start

from securevault import VaultClient

# Initialize client
vault = VaultClient()

# Set a secret
vault.set('api_key', 'my-secret-key')

# Get a secret
api_key = vault.get('api_key')
print(f"API Key: {api_key}")

# List all secrets
secrets = vault.list()
print(f"Secrets: {secrets}")

# Check if secret exists
if vault.exists('api_key'):
    print("API key is configured")

# Delete a secret
vault.delete('api_key')

Usage Examples

Context Manager

from securevault import VaultClient

with VaultClient() as vault:
    vault.set('temp_key', 'temp_value')
    value = vault.get('temp_key')
    print(value)

Load Secrets into Environment

from securevault import VaultClient
import os

vault = VaultClient()

# Load all secrets as environment variables
vault.load_env()

# Access from environment
api_key = os.getenv('API_KEY')

# Load with prefix
vault.load_env(prefix='APP_')
# Now accessible as APP_API_KEY, APP_DB_PASSWORD, etc.

Get All Secrets

from securevault import VaultClient

vault = VaultClient()

# Get all secrets as dictionary
secrets = vault.get_all()
for name, value in secrets.items():
    print(f"{name}: {value}")

Export/Import

from securevault import VaultClient

vault = VaultClient()

# Export to JSON
vault.export_to_file('secrets.json')

# Import from JSON
vault.import_from_file('secrets.json')

Async Support

import asyncio
from securevault import AsyncVaultClient

async def main():
    vault = AsyncVaultClient()
    
    # All methods are async
    await vault.set('api_key', 'secret123')
    api_key = await vault.get('api_key')
    print(api_key)
    
    secrets = await vault.list()
    print(secrets)

asyncio.run(main())

Custom CLI Path

from securevault import VaultClient

# Specify custom path to CLI
vault = VaultClient(cli_path='/custom/path/to/securevault')

API Reference

VaultClient

Methods

  • get(name: str) -> str - Get a secret value
  • set(name: str, value: str, description: Optional[str] = None) - Set a secret
  • delete(name: str) - Delete a secret
  • list() -> List[str] - List all secret names
  • exists(name: str) -> bool - Check if a secret exists
  • get_all() -> Dict[str, str] - Get all secrets as dictionary
  • load_env(prefix: str = '') - Load secrets into environment variables
  • export_to_file(filepath: str) - Export secrets to JSON file
  • import_from_file(filepath: str) - Import secrets from JSON file

AsyncVaultClient

Async version with the same methods, but all are async/await.

Error Handling

from securevault import VaultClient, VaultError, SecretNotFoundError

vault = VaultClient()

try:
    value = vault.get('nonexistent')
except SecretNotFoundError:
    print("Secret not found")
except VaultError as e:
    print(f"Vault error: {e}")

Development

Running Tests

pip install -e ".[dev]"
pytest

Running Async Tests

pytest -v tests/test_async.py

License

MIT

Author

JahDev

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

securevault-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

securevault-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file securevault-0.1.0.tar.gz.

File metadata

  • Download URL: securevault-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for securevault-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e94145ee8ed5b813bdfe61c0595c4503955df8064244bf47086c83e23d7aaed9
MD5 2de34e1f7f5658a0986d44f336babb15
BLAKE2b-256 f50a98b2bc110d19e1ddb9a3eb783f7faea03c41d47de3b88dac36d4753af649

See more details on using hashes here.

File details

Details for the file securevault-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: securevault-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for securevault-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 424ac8c74ef586380ecf07ffca580d786181a8a5d70721312491644dcbc78208
MD5 6799a624d7f495a563aa08e32c93507f
BLAKE2b-256 941a60da6a8ee2899f7922076ad1f27cece60cca86d464e47b196f2a84bf9f37

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