Client¶
The main entry point for interacting with the Bloomy API.
Client
¶
Client(api_key: str | None = None, base_url: str = 'https://app.bloomgrowth.com/api/v1', timeout: float = 30.0)
The Client class is the main entry point for interacting with the Bloomy API.
It provides methods for managing Bloom Growth features.
Example
Initialize a new Client instance.
Parameters:
-
api_key(str | None, default:None) –The API key to use. If not provided, will attempt to load from environment variable (BG_API_KEY) or configuration file.
-
base_url(str, default:'https://app.bloomgrowth.com/api/v1') –The base URL for the API. Defaults to the production API URL.
-
timeout(float, default:30.0) –The timeout in seconds for HTTP requests. Defaults to 30.0.
Raises:
-
ConfigurationError–If no API key is provided or found in configuration.
Methods:
-
__enter__–Context manager entry.
-
__exit__–Context manager exit - close the HTTP client.
-
close–Close the HTTP client connection.
Source code in src/bloomy/client.py
Basic Usage¶
from bloomy import Client, ConfigurationError
# Initialize with API key
client = Client(api_key="your-api-key")
# Custom base URL (for testing/staging)
client = Client(
api_key="your-api-key",
base_url="https://staging.example.com/api/v1"
)
# Custom timeout (in seconds)
client = Client(api_key="your-api-key", timeout=60.0)
# Handle missing API key
try:
client = Client()
except ConfigurationError as e:
print(f"Configuration error: {e}")
Parameters¶
- api_key (str, optional): Your Bloom Growth API key. If not provided, will attempt to load from
BG_API_KEYenvironment variable or~/.bloomy/config.yaml - base_url (str, optional): Custom API endpoint. Defaults to
"https://app.bloomgrowth.com/api/v1" - timeout (float, optional): Request timeout in seconds. Defaults to
30.0
Exceptions¶
- ConfigurationError: Raised when no API key can be found from any source
Context Manager¶
The Client supports context manager protocol for automatic resource cleanup: