AsyncClient¶
AsyncClient
¶
AsyncClient(api_key: str | None = None, base_url: str = 'https://app.bloomgrowth.com/api/v1', timeout: float = 30.0, graphql_url: str | None = None)
Asynchronous client for interacting with the Bloomy API.
This client provides async access to all Bloomy API operations including users, meetings, todos, goals, headlines, issues, and scorecards.
client.v1 groups the REST API operations; the top-level attributes are
aliases of client.v1.*, kept for backward compatibility. client.v2
groups the GraphQL API operations (user, meeting, issue, ...).
Parameters:
-
api_key(str | None, default:None) –The API key for authentication. If not provided, it will be loaded from environment variables or configuration files.
-
base_url(str, default:'https://app.bloomgrowth.com/api/v1') –The base URL for the API. Defaults to the production API URL.
Example
Using the async client with context manager:
import asyncio
from bloomy import AsyncClient
async def main():
async with AsyncClient(api_key="your-api-key") as client:
user = await client.user.details()
print(user.name)
asyncio.run(main())
Without context manager:
Initialize the async Bloomy client.
Parameters:
-
api_key(str | None, default:None) –The API key for authentication.
-
base_url(str, default:'https://app.bloomgrowth.com/api/v1') –The base URL for the API.
-
timeout(float, default:30.0) –The timeout in seconds for HTTP requests. Defaults to 30.0.
-
graphql_url(str | None, default:None) –The absolute URL of the v2 GraphQL endpoint. Defaults to the scheme and host of
base_urlplus/graphql/.
Raises:
-
ConfigurationError–If no API key is provided or found in configuration.
Methods:
-
__aenter__–Enter the async context manager.
-
__aexit__–Exit the async context manager.
-
close–Close the HTTP client.
Source code in src/bloomy/async_client.py
Methods:¶
__aenter__
async
¶
Enter the async context manager.
Returns:
-
Self–The async client instance.
__aexit__
async
¶
__aexit__(exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None) -> None
Exit the async context manager.
Source code in src/bloomy/async_client.py
Basic Usage¶
import asyncio
from bloomy import AsyncClient, ConfigurationError
async def main():
# Initialize with API key
async with AsyncClient(api_key="your-api-key") as client:
users = await client.user.list()
# Custom base URL (for testing/staging)
async with AsyncClient(
api_key="your-api-key",
base_url="https://staging.example.com/api/v1"
) as client:
users = await client.user.list()
# Custom timeout (in seconds)
async with AsyncClient(api_key="your-api-key", timeout=60.0) as client:
users = await client.user.list()
# Handle missing API key
try:
client = AsyncClient()
except ConfigurationError as e:
print(f"Configuration error: {e}")
asyncio.run(main())
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 AsyncClient supports async context manager protocol for automatic resource cleanup: