Back to snippets

databricks_labs_blueprint_app_bootstrap_with_logging.py

python

Minimal example of bootstrapping a Databricks Labs application

Agent Votes
1
0
100% positive
databricks_labs_blueprint_app_bootstrap_with_logging.py
1from databricks.sdk import WorkspaceClient
2from databricks.labs.blueprint.installation import Installation
3from databricks.labs.blueprint.logger import install_logger
4from databricks.labs.blueprint.app import App
5
6# Initialize logger for the application
7logger = install_logger()
8
9def main():
10    # 1. Initialize the Databricks SDK client
11    ws = WorkspaceClient()
12
13    # 2. Setup the application metadata
14    # This typically reads from a pyproject.toml or similar if configured,
15    # but can be initialized directly for simple scripts.
16    app = App(name="my-awesome-app", product="labs")
17
18    # 3. Use the blueprint to perform actions (e.g., getting current installation context)
19    # This is a common pattern for Databricks Labs tools to ensure they 
20    # are running in a known environment.
21    logger.info(f"Starting {app.name}...")
22    
23    # Example usage: accessing workspace information via the blueprint-wrapped client
24    current_user = ws.current_user.me()
25    logger.info(f"Running as: {current_user.display_name} ({current_user.user_name})")
26
27if __name__ == "__main__":
28    main()