• Projects
  • Service
  • About
  • branding.bz
  • Podcast
  • Tips
  • FAQ
  • Recruit
  • Download
  • Contact
  • branding.bz(ブランド構築SaaS)
  • DESIGN NOW(デザインメディア)
  • X
  • LinkedIn
  • Spotify
  • Facebook

213-0011 神奈川県川崎市高津区久本3-6-7-303

© 2026 ID INC. All rights reserved

claude-skills/スキル
SKILLOfficialdatabase

databricks-apps-python

プラグイン
databricks
ソース
GitHub で見る ↗
説明

Databricks アプリケーション(Databricks が提供するアプリ構築プラットフォーム)用の Python バックエンド(サーバー側の処理)— FastAPI(デフォルト)、Flask、Dash、Streamlit、Gradio、Reflex に対応しています。 **新しい Databricks アプリケーションのデフォルトは `databricks-apps`(AppKit — Node/TypeScript/React)です。まずはこちらを優先してください。** このスキルは、以下の場合にのみ使用してください: - ユーザーが Python バックエンドを明確に指定している - 既存の Python アプリを拡張する必要がある - チーム全体が Python のみを使用している カバー範囲: - OAuth 認証(ユーザーの本人確認) - アプリケーションリソース - SQL ウェアハウス(データベース)および Lakebase(データ管理基盤)への接続 - 基盤モデル(大規模言語モデル)、ベクトル検索(テキスト検索機能)、モデル提供 API(`databricks-python-sdk` 経由) - CLI またはDAB(Databricks Asset Bundles — リソース定義セット)を使ったデプロイ(公開・配置)

原文を表示

Python backend for Databricks Apps — FastAPI (default), Flask, Dash, Streamlit, Gradio, Reflex. **Default for a new Databricks App is `databricks-apps` (AppKit — Node/TypeScript/React) — reach for it first.** Use this skill only when the user asks for a Python backend, extends an existing Python app, or the team is Python-only. Covers OAuth auth, app resources, SQL warehouse and Lakebase connectivity, foundation-model / Vector Search / model-serving APIs (via `databricks-python-sdk`), and deployment via CLI or DABs.

ユースケース
  • Python バックエンドを明確に指定するとき
  • 既存の Python アプリを拡張するとき
  • チーム全体が Python のみを使用する場合
本文(日本語訳)

Databricks Applications — Python バックエンド

まず、このスキルが適切であることを確認してください。 新しい Databricks Apps のデフォルトは databricks-apps です(AppKit — Node.js + TypeScript + React SDK)。ユーザーが明示的に Python バックエンドを要望しているか、既存の Python アプリを拡張しているか、チームが Python のみの場合を除き、まずそのスキルを読み込んでください。以下は Python バックエンド向けの代替案です。

Python アプリの重要なルール(必ず守る)

  • 必ず フレームワークの選択を確認するか、以下の Python フレームワーク選択 を使用する
  • 必ず 認証に SDK の Config() を使用する(トークンをコード内に書き込まない)
  • 必ず リソースに app.yaml の valueFrom を使用する(リソース ID をコード内に書き込まない)
  • 必ず Dash アプリのレイアウトとスタイルに dash-bootstrap-components を使用する
  • 必ず Streamlit のデータベース接続に @st.cache_resource を使用する
  • 必ず Flask は Gunicorn で、FastAPI は uvicorn でデプロイする(開発用サーバーは使用しない)

Python アプリの必須ステップ

このチェックリストをコピーして、各項目を確認してください:

- [ ] フレームワークが選択済み
- [ ] 認証戦略が決定済み:アプリ認証、ユーザー認証、または両方
- [ ] アプリが使用するリソースを特定済み(SQL ウェアハウス、Lakebase、モデル配信エンドポイント など)
- [ ] バックエンドデータ戦略が決定済み(SQL ウェアハウス、Lakebase、または SDK)
- [ ] デプロイ方法を決定済み:CLI または DABs

Python フレームワーク選択

フレームワーク 最適な用途 app.yaml コマンド
FastAPI(デフォルト) あらゆる Python バックエンドのデフォルト — 非同期 API、自動生成される API 仕様書(OpenAPI)、JSON を返すアプリ ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
Flask カスタム REST API、軽量なアプリ、Webhook ["gunicorn", "app:app", "-w", "4", "-b", "0.0.0.0:8000"]
Dash 本番ダッシュボード、BI ツール、複雑なインタラクション ["python", "app.py"]
Streamlit 迅速なプロトタイピング、データサイエンスアプリ、UI が一連の Python ウィジェットである内部ツール ["streamlit", "run", "app.py"]
Gradio 機械学習のデモ、モデルインターフェース、チャット UI ["python", "app.py"]
Reflex JavaScript 不要のフルスタック Python アプリ ["reflex", "run", "--env", "prod"]

デフォルトは FastAPI です。 ユーザーが Streamlit 風のウィジェットプロトタイピング(Streamlit)、大型ダッシュボードグリッド(Dash)、Gradio 風の機械学習デモを明示的に要望していない限り、FastAPI を選んでください。FastAPI は JS/HTML フロントエンドまたは JSON を消費するクライアントと自然に組み合わせられます。これは Node.js 側の databricks-apps と同じ構成です。


クイックリファレンス

概念 詳細
ランタイム Python 3.11、Ubuntu 22.04、2 vCPU、6 GB RAM
プリインストール済み Dash 2.18.1、Streamlit 1.38.0、Gradio 4.44.0、Flask 3.0.3、FastAPI 0.115.0
認証(アプリ) サービスプリンシパル(サービス用アカウント)経由で Config() から自動注入される DATABRICKS_CLIENT_ID/DATABRICKS_CLIENT_SECRET
認証(ユーザー) x-forwarded-access-token ヘッダー — references/1-authorization.md を参照
リソース app.yaml の valueFrom — references/2-app-resources.md を参照
SDK / Foundation Models / Vector Search / Model Serving databricks-python-sdk スキルを使用 — WorkspaceClient と OpenAI 互換の基盤モデルパターンは Databricks App 内でも同じに機能します
ドキュメント https://docs.databricks.com/dev-tools/databricks-apps/

詳細ガイド

認証: アプリまたはユーザー認証を構成する場合は references/1-authorization.md を使用してください — サービスプリンシパル認証、ユーザー代理トークン、OAuth スコープ、フレームワーク別のコード例をカバーしています。(キーワード:OAuth、サービスプリンシパル、ユーザー認証、代理認証、アクセストークン、スコープ)

アプリリソース: アプリを Databricks リソースに接続する場合は references/2-app-resources.md を使用してください — SQL ウェアハウス、Lakebase、モデル配信、シークレット、ボリューム、および valueFrom パターンをカバーしています。(キーワード:リソース、valueFrom、SQL ウェアハウス、モデル配信、シークレット、ボリューム、接続)

フレームワーク: フレームワーク別の Databricks 固有パターンについては references/3-frameworks.md を参照してください — FastAPI(デフォルト)、Flask、Dash、Streamlit、Gradio、Reflex — 認証統合とデプロイコマンド付き。(キーワード:FastAPI、Flask、Dash、Streamlit、Gradio、Reflex、フレームワーク選択)

デプロイ: アプリをデプロイする場合は references/4-deployment.md を使用してください — Databricks CLI、Asset Bundles(DABs)、app.yaml 構成、デプロイ後の検証をカバーしています。(キーワード:デプロイ、CLI、DABs、アセットバンドル、app.yaml、ログ)

Lakebase: Lakebase(PostgreSQL)をアプリのデータレイヤーとして使用する場合は references/5-lakebase.md を使用してください — 自動注入される環境変数、psycopg2/asyncpg パターン、Lakebase と SQL ウェアハウスの選択方法をカバーしています。(キーワード:Lakebase、PostgreSQL、psycopg2、asyncpg、トランザクション、PGHOST)

CLI コマンド: CLI 経由でアプリのライフサイクルを管理する場合は references/6-cli-approach.md を使用してください — アプリの作成、デプロイ、監視、削除をカバーしています。(キーワード:CLI、アプリ作成、アプリデプロイ、アプリログ)

Foundation Models / SDK / Vector Search / Model Serving: OpenAI 互換の基盤モデルクライアント、WorkspaceClient 呼び出し、Vector Search、モデル配信の呼び出しについては、databricks-python-sdk スキルを使用してください — 同じパターンは Databricks App 内でも機能します。このスキルの examples/ フォルダ(fm-minimal-chat.py、fm-parallel-calls.py、fm-structured-outputs.py、llm_config.py)は、App 側の配線のみを示しています。


ワークフロー

  1. タスクの種類を判定します:

    ゼロからの新規アプリ? → databricks-apps を最初に読み込んでください(AppKit / Node)。ユーザーが明示的に Python バックエンドを要望している場合のみ、このスキルに留まってください。

    Python バックエンド確定済み? → Python フレームワーク選択 — デフォルトは FastAPI です。

    認証をセットアップしている? → references/1-authorization.md を読んでください。

    データ・リソースに接続している? → references/2-app-resources.md を読んでください。

    Lakebase(PostgreSQL)を使用している? → references/5-lakebase.md を読んでください。

    Databricks にデプロイしている? → references/4-deployment.md を読んでください。

    CLI でアプリのライフサイクルを管理している? → references/6-cli-approach.md を読んでください。

    基盤モデル / LLM API、Vector Search、またはモデル配信エンドポイントを呼び出している? → databricks-python-sdk スキルを読み込んでください。このスキルの examples/ フォルダは、SDK パターンの上のアプリ側の配線のみを示しています。

  2. 該当するガイドの指示に従ってください。


コアアーキテクチャ

すべての Python Databricks アプリは次のパターンに従います:

app-directory/
├── app.py                 # メインアプリケーション(またはフレームワーク固有の名前)
├── models.py              # Pydantic データモデル
├── backend.py             # データアクセスレイヤー
├── requirements.txt       # 追加の Python 依存パッケージ
├── app.yaml               # Databricks Apps 構成
└── README.md

バックエンド切り替えパターン

import os
from databricks.sdk.core import Config

USE_MOCK = os.getenv("USE_MOCK_BACKEND", "true").lower() == "true"

if USE_MOCK:
    from backend_mock import MockBackend as Backend
else:
    from backend_real import RealBackend as Backend

backend = Backend()

SQL ウェアハウス接続(すべてのフレームワークで共通)

from databricks.sdk.core import Config
from databricks import sql

cfg = Config()  # 環境変数から認証情報を自動検出
conn = sql.connect(
    server_hostname=cfg.host,
    http_path=f"/sql/1.0/warehouses/{os.getenv('DATABRICKS_WAREHOUSE_ID')}",
    credentials_provider=lambda: cfg.authenticate,
)

Pydantic モデル

from pydantic import BaseModel, Field
from datetime import datetime
from enum import Enum

class Status(str, Enum):
    ACTIVE = "active"
    PENDING = "pending"

class EntityOut(BaseModel):
    id: str
    name: str
    status: Status
    created_at: datetime

class EntityIn(BaseModel):
    name: str = Field(..., min_length=1)
    status: Status = Status.PENDING

よくある問題

問題 対策
接続が枯渇している @st.cache_resource(Streamlit)を使用するか、接続プーリング(複数接続の再利用)を使用する
認証トークンが見つからない x-forwarded-access-token ヘッダーを確認 — デプロイ時のみ利用可能(ローカルでは利用不可)
アプリが起動しない app.yaml コマンドがフレームワークと一致しているか確認;databricks apps logs <name> でログを確認
リソースにアクセスできない UI 経由でリソースを追加;サービスプリンシパルがアクセス権を持っているか確認;app.yaml で valueFrom を使用
デプロイ時のインポートエラー requirements.txt に不足しているパッケージを追加(プリインストール済みパッケージは記載不要)
Lakebase アプリがデプロイ時にクラッシュ psycopg2/asyncpg はプリインストールされていません — 必ず requirements.txt に追加してください
ポート競合 アプリは DATABRICKS_APP_PORT 環境変数にバインドする必要があります(デフォルト 8000)。8080 は使用しないでください。Streamlit は自動構成;その他は環境変数をコードで読み込むか、app.yaml コマンドで 8000 を使用
Streamlit:set_page_config エラー st.set_page_config() は Streamlit コマンドの最初に実行する必要があります
Dash:スタイルが適用されていない `dash-bootstrap
原文(English)を表示

Databricks Applications — Python backends

First, confirm this skill is the right one. The default for new Databricks Apps is databricks-apps (AppKit — Node.js + TypeScript + React SDK). Load that skill first unless the user explicitly asks for a Python backend, is extending an existing Python app, or the team is Python-only. Everything below is the Python-backend alternative.

Critical Rules for Python apps (always follow)

  • MUST confirm framework choice or use Python Framework Selection below
  • MUST use SDK Config() for authentication (never hardcode tokens)
  • MUST use app.yaml valueFrom for resources (never hardcode resource IDs)
  • MUST use dash-bootstrap-components for Dash app layout and styling
  • MUST use @st.cache_resource for Streamlit database connections
  • MUST deploy Flask with Gunicorn, FastAPI with uvicorn (not dev servers)

Required Steps for Python apps

Copy this checklist and verify each item:

- [ ] Framework selected
- [ ] Auth strategy decided: app auth, user auth, or both
- [ ] App resources identified (SQL warehouse, Lakebase, serving endpoint, etc.)
- [ ] Backend data strategy decided (SQL warehouse, Lakebase, or SDK)
- [ ] Deployment method: CLI or DABs

Python Framework Selection

Framework Best For app.yaml Command
FastAPI (default) Any Python backend by default — async APIs, auto-generated OpenAPI docs, JSON-serving apps ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
Flask Custom REST APIs, lightweight apps, webhooks ["gunicorn", "app:app", "-w", "4", "-b", "0.0.0.0:8000"]
Dash Production dashboards, BI tools, complex interactivity ["python", "app.py"]
Streamlit Rapid prototyping, data science apps, internal tools where the UI is a series of Python widgets ["streamlit", "run", "app.py"]
Gradio ML demos, model interfaces, chat UIs ["python", "app.py"]
Reflex Full-stack Python apps without JavaScript ["reflex", "run", "--env", "prod"]

Default: FastAPI. Reach for FastAPI unless the user explicitly asks for Streamlit-style widget prototyping (Streamlit), a heavy dashboard grid (Dash), or a Gradio-style ML demo. FastAPI pairs naturally with a JS/HTML frontend or a JSON-consuming caller — the same posture databricks-apps uses on the Node side.


Quick Reference

Concept Details
Runtime Python 3.11, Ubuntu 22.04, 2 vCPU, 6 GB RAM
Pre-installed Dash 2.18.1, Streamlit 1.38.0, Gradio 4.44.0, Flask 3.0.3, FastAPI 0.115.0
Auth (app) Service principal via Config() — auto-injected DATABRICKS_CLIENT_ID/DATABRICKS_CLIENT_SECRET
Auth (user) x-forwarded-access-token header — see references/1-authorization.md
Resources valueFrom in app.yaml — see references/2-app-resources.md
SDK / Foundation Models / Vector Search / Model Serving Use the databricks-python-sdk skill — same WorkspaceClient and OpenAI-compatible foundation-model patterns work inside a Databricks App
Docs https://docs.databricks.com/dev-tools/databricks-apps/

Detailed Guides

Authorization: Use references/1-authorization.md when configuring app or user authorization — covers service principal auth, on-behalf-of user tokens, OAuth scopes, and per-framework code examples. (Keywords: OAuth, service principal, user auth, on-behalf-of, access token, scopes)

App resources: Use references/2-app-resources.md when connecting your app to Databricks resources — covers SQL warehouses, Lakebase, model serving, secrets, volumes, and the valueFrom pattern. (Keywords: resources, valueFrom, SQL warehouse, model serving, secrets, volumes, connections)

Frameworks: See references/3-frameworks.md for Databricks-specific patterns per framework — FastAPI (default), Flask, Dash, Streamlit, Gradio, Reflex — with auth integration and deployment commands. (Keywords: FastAPI, Flask, Dash, Streamlit, Gradio, Reflex, framework selection)

Deployment: Use references/4-deployment.md when deploying your app — covers Databricks CLI, Asset Bundles (DABs), app.yaml configuration, and post-deployment verification. (Keywords: deploy, CLI, DABs, asset bundles, app.yaml, logs)

Lakebase: Use references/5-lakebase.md when using Lakebase (PostgreSQL) as your app's data layer — covers auto-injected env vars, psycopg2/asyncpg patterns, and when to choose Lakebase vs SQL warehouse. (Keywords: Lakebase, PostgreSQL, psycopg2, asyncpg, transactional, PGHOST)

CLI commands: Use references/6-cli-approach.md for managing app lifecycle via CLI — covers creating, deploying, monitoring, and deleting apps. (Keywords: CLI, create app, deploy app, app logs)

Foundation Models / SDK / Vector Search / Model Serving: Use the databricks-python-sdk skill for the OpenAI-compatible foundation-model client, WorkspaceClient calls, Vector Search, and model-serving invocation — the same patterns apply inside a Databricks App. The examples in this skill's examples/ folder (fm-minimal-chat.py, fm-parallel-calls.py, fm-structured-outputs.py, llm_config.py) show the App-side wiring only.


Workflow

  1. Determine the task type:

    New app from scratch? → Load databricks-apps first (AppKit / Node). Only stay in this skill if the user explicitly asks for a Python backend. Python-backend confirmed? → Python Framework Selection — default to FastAPI. Setting up authorization? → Read references/1-authorization.md Connecting to data/resources? → Read references/2-app-resources.md Using Lakebase (PostgreSQL)? → Read references/5-lakebase.md Deploying to Databricks? → Read references/4-deployment.md Using CLI for app lifecycle? → Read references/6-cli-approach.md Calling foundation model / LLM APIs, Vector Search, or model-serving endpoints? → Load the databricks-python-sdk skill. This skill's examples/ folder shows only the App-side wiring on top of those SDK patterns.

  2. Follow the instructions in the relevant guide.


Core Architecture

All Python Databricks apps follow this pattern:

app-directory/
├── app.py                 # Main application (or framework-specific name)
├── models.py              # Pydantic data models
├── backend.py             # Data access layer
├── requirements.txt       # Additional Python dependencies
├── app.yaml               # Databricks Apps configuration
└── README.md

Backend Toggle Pattern

import os
from databricks.sdk.core import Config

USE_MOCK = os.getenv("USE_MOCK_BACKEND", "true").lower() == "true"

if USE_MOCK:
    from backend_mock import MockBackend as Backend
else:
    from backend_real import RealBackend as Backend

backend = Backend()

SQL Warehouse Connection (shared across all frameworks)

from databricks.sdk.core import Config
from databricks import sql

cfg = Config()  # Auto-detects credentials from environment
conn = sql.connect(
    server_hostname=cfg.host,
    http_path=f"/sql/1.0/warehouses/{os.getenv('DATABRICKS_WAREHOUSE_ID')}",
    credentials_provider=lambda: cfg.authenticate,
)

Pydantic Models

from pydantic import BaseModel, Field
from datetime import datetime
from enum import Enum

class Status(str, Enum):
    ACTIVE = "active"
    PENDING = "pending"

class EntityOut(BaseModel):
    id: str
    name: str
    status: Status
    created_at: datetime

class EntityIn(BaseModel):
    name: str = Field(..., min_length=1)
    status: Status = Status.PENDING

Common Issues

Issue Solution
Connection exhausted Use @st.cache_resource (Streamlit) or connection pooling
Auth token not found Check x-forwarded-access-token header — only available when deployed, not locally
App won't start Check app.yaml command matches framework; check databricks apps logs <name>
Resource not accessible Add resource via UI, verify SP has permissions, use valueFrom in app.yaml
Import error on deploy Add missing packages to requirements.txt (pre-installed packages don't need listing)
Lakebase app crashes on start psycopg2/asyncpg are NOT pre-installed — MUST add to requirements.txt
Port conflict Apps must bind to DATABRICKS_APP_PORT env var (defaults to 8000). Never use 8080. Streamlit is auto-configured; for others, read the env var in code or use 8000 in app.yaml command
Streamlit: set_page_config error st.set_page_config() must be the first Streamlit command
Dash: unstyled layout Add dash-bootstrap-components; use dbc.themes.BOOTSTRAP
Slow queries Use Lakebase for transactional/low-latency; SQL warehouse for analytical queries

Platform Constraints

Constraint Details
Runtime Python 3.11, Ubuntu 22.04 LTS
Compute 2 vCPUs, 6 GB memory (default)
Pre-installed frameworks Dash, Streamlit, Gradio, Flask, FastAPI, Shiny
Custom packages Add to requirements.txt in app root
Network Apps can reach Databricks APIs; external access depends on workspace config
User auth GA, on by default — no admin enablement required; declare user_api_scopes to add scopes

Official Documentation

  • Databricks Apps Overview — main docs hub
  • Authorization — app auth and user auth
  • Resources — SQL warehouse, Lakebase, serving, secrets
  • app.yaml Reference — command and env config
  • System Environment — pre-installed packages, runtime details

Related Skills

  • databricks-apps — the default for new Databricks Apps (AppKit / Node / TypeScript + React); load it first unless a Python backend is explicitly required
  • databricks-python-sdk — WorkspaceClient, OpenAI-compatible foundation-model client, Vector Search, model-serving invocation; the same patterns work inside a Databricks App
  • databricks-lakebase — persistent PostgreSQL state (autoscaling managed PG with branching)
  • databricks-model-serving — endpoint lifecycle for ML models an App calls
  • databricks-dabs — deploying apps via DABs

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。