Configuration¶
The Bloomy SDK provides flexible configuration options to suit different use cases and deployment scenarios.
Configuration Methods¶
1. Direct API Key¶
The simplest method - pass your API key directly to the client:
Best for: Scripts, notebooks, and testing
2. Environment Variable¶
Set the BG_API_KEY
environment variable:
Then initialize the client without parameters:
Best for: Production applications, CI/CD pipelines
3. Configuration File¶
The SDK can store credentials in a local configuration file:
from bloomy import Configuration
# Initial setup - fetches and saves API key
config = Configuration()
config.configure_api_key(
username="your-email@example.com",
password="your-password",
store_key=True
)
# Future usage - automatically loads saved API key
from bloomy import Client
client = Client()
The configuration is stored in ~/.bloomy/config.yaml
:
Best for: Development environments, personal use
Configuration Priority¶
When initializing a client, the SDK checks for credentials in this order:
- Direct
api_key
parameter BG_API_KEY
environment variable- Configuration file (
~/.bloomy/config.yaml
)
The first valid API key found is used.
Managing Configuration¶
View Current Configuration¶
from bloomy import Configuration
config = Configuration()
print(f"Has API key: {config.api_key is not None}")
Update Configuration¶
# Update with new credentials
config.configure_api_key(
username="new-email@example.com",
password="new-password",
store_key=True
)
# Or set API key directly and store it
config = Configuration(api_key="new-api-key")
config._store_api_key() # Store to config file
Clear Configuration¶
Security Best Practices¶
- Never commit API keys to version control
- Use environment variables in production
- Restrict file permissions on config files:
- Rotate API keys regularly
- Use separate keys for development and production
Troubleshooting¶
Missing API Key Error¶
If you see BloomyError: No API key provided
, check:
- Spelling of environment variable (
BG_API_KEY
) - Configuration file exists at
~/.bloomy/config.yaml
- API key is properly formatted
Authentication Failed¶
If authentication fails:
- Verify API key is correct and active
- Check if your account has API access enabled
- Ensure your API key is valid
Configuration File Issues¶
To reset configuration:
Then reconfigure using the Configuration class.