Secrets Manager Installation
Before you begin
You'll need:
- A ByteHide account and project token
- Python 3.7 or higher installed
- pip package manager
Installation
Install the ByteHide Secrets SDK using pip:
Bash
pip install bytehide-secretspip install bytehide-secretsInitialize the SDK
Once installed, you need to initialize the SDK with your project token.
Using Environment Variables (Recommended)
Set up environment variables and the SDK will auto-initialize:
Python
from bytehide_secrets import SecretsManager
# Environment variables:
# BYTEHIDE_SECRETS_TOKEN=f8118003-c24d-4f6f-9057-1a0d0b89ef55
# BYTEHIDE_SECRETS_ENVIRONMENT=production
# The SDK will read from environment variables automatically
api_key = SecretsManager.get("API_KEY")
print(f"API Key: {api_key}")from bytehide_secrets import SecretsManager
# Environment variables:
# BYTEHIDE_SECRETS_TOKEN=f8118003-c24d-4f6f-9057-1a0d0b89ef55
# BYTEHIDE_SECRETS_ENVIRONMENT=production
# The SDK will read from environment variables automatically
api_key = SecretsManager.get("API_KEY")
print(f"API Key: {api_key}")Direct Initialization
For testing or development scenarios, you can initialize directly with a token:
Python
from bytehide_secrets import SecretsManager
# Not recommended for production - use environment variables instead
SecretsManager.unsecure_initialize("f8118003-c24d-4f6f-9057-1a0d0b89ef55", "production")from bytehide_secrets import SecretsManager
# Not recommended for production - use environment variables instead
SecretsManager.unsecure_initialize("f8118003-c24d-4f6f-9057-1a0d0b89ef55", "production")Security Notice
Never hardcode your token in source code. For production environments, always use environment variables or a secure vault.
Environment Variables Setup
Development Environment
Bash
# Linux/macOS
export BYTEHIDE_SECRETS_TOKEN=your-token-here
export BYTEHIDE_SECRETS_ENVIRONMENT=development
# Windows (Command Prompt)
set BYTEHIDE_SECRETS_TOKEN=your-token-here
set BYTEHIDE_SECRETS_ENVIRONMENT=development
# Windows (PowerShell)
$env:BYTEHIDE_SECRETS_TOKEN = "your-token-here"
$env:BYTEHIDE_SECRETS_ENVIRONMENT = "development"# Linux/macOS
export BYTEHIDE_SECRETS_TOKEN=your-token-here
export BYTEHIDE_SECRETS_ENVIRONMENT=development
# Windows (Command Prompt)
set BYTEHIDE_SECRETS_TOKEN=your-token-here
set BYTEHIDE_SECRETS_ENVIRONMENT=development
# Windows (PowerShell)
$env:BYTEHIDE_SECRETS_TOKEN = "your-token-here"
$env:BYTEHIDE_SECRETS_ENVIRONMENT = "development"Using a .env File
Create a .env file in your project root:
CODE
BYTEHIDE_SECRETS_TOKEN=your-token-here
BYTEHIDE_SECRETS_ENVIRONMENT=productionBYTEHIDE_SECRETS_TOKEN=your-token-here
BYTEHIDE_SECRETS_ENVIRONMENT=productionThen use python-dotenv to load it:
Python
from dotenv import load_dotenv
load_dotenv()from dotenv import load_dotenv
load_dotenv()Production Environment
In production, set these variables through your hosting platform:
- AWS Lambda/EC2: Environment Variables
- Google Cloud Functions: Environment configuration
- Heroku: Config vars
- Docker: Environment flags
- Kubernetes: ConfigMaps or Secrets
Verify Installation
After initializing the SDK, you can verify it's working by accessing a test secret:
Python
from bytehide_secrets import SecretsManager
try:
# Attempt to get a secret
secret = SecretsManager.get("test")
print("Secret retrieved successfully!")
except Exception as ex:
print(f"Error: {ex}")from bytehide_secrets import SecretsManager
try:
# Attempt to get a secret
secret = SecretsManager.get("test")
print("Secret retrieved successfully!")
except Exception as ex:
print(f"Error: {ex}")