製品をチェック

無償トライアル:

無償トライアルへ

製品の情報と無償トライアルへ:

Azure Analysis Services Python Connector

Azure Analysis Services データ連携用のPython ライブラリ。Azure Analysis Services データをpandas、SQLAlchemy、Dash、petl などの人気のPython ツールにシームレスに統合。

データ連携でお困りですか?

お問い合わせ

Python のDash ライブラリを使って、Azure Analysis Services データ に連携するウェブアプリケーションを開発


CData Python Connector for AAS を使って、Azure Analysis Services にデータ連携するPython ウェブアプリケーションを開発できます。pandas とDash を使って作成してみます。


azureanalysisservices ロゴ画像
python ロゴ画像

Python

Python ロゴ画像

Pythonエコシステムには、多くのモジュールがあり、システム構築を素早く効率的に行うことができます。CData Python Connector for AAS を使うことで、pandas モジュールとDash フレームワークでAzure Analysis Services にデータ連携するアプリケーションを効率的に開発することができます。本記事では、pandas、Dash とCData Connector を使って、Azure Analysis Services に連携して、Azure Analysis Services data をビジュアライズするシンプルなウエブアプリを作ります。

CData Python Connector は、ビルトインされた効率的なデータプロセスにより、リアルタイムAzure Analysis Services data データにPython からアクセスし、高いパフォーマンスと接続性を発揮します。Azure Analysis Services に複雑なクエリを投げる際に、ドライバーはフィルタリング、集計などがサポートされている場合、SQL 処理を直接Azure Analysis Services 側に行わせ、サポートされていないSQL 処理については、組み込まれたSQL エンジンによりクライアント側で処理を行います(特にJOIN やSQL 関数など)。

Azure Analysis Services への接続

Azure Analysis Services data への連携は、RDB ソースへのアクセスと同感覚で行うことができます。必要な接続プロパティを使って接続文字列を作成します。本記事では、接続文字列をcreate_engine 関数のパラメータとして送ります。

To connect to Azure Analysis Services, set the Url property to a valid server, for instance, asazure://southcentralus.asazure.windows.net/server, in addition to authenticating. Optionally, set Database to distinguish which Azure database on the server to connect to.

Azure Analysis Services uses the OAuth authentication standard. OAuth requires the authenticating user to interact with Azure Analysis Services using the browser. You can connect without setting any connection properties for your user credentials. See the Help documentation for more information.

以下の手順に従い、必要なモジュールをインストールし、Python オブジェクト経由でAzure Analysis Services にアクセスします。

必要なモジュールのインストール

pip で必要なモジュールおよびフレームワークをインストールします:

pip install pandas
pip install dash
pip install dash-daq

Python でAzure Analysis Services データ をビジュアライズ

必要なモジュールとフレームワークがインストールされたら、ウェブアプリを開発していきます。コードのスニペットは以下の通りです。フルコードは記事の末尾に付いています。

まず、CData Connector を含むモジュールをインポートします:

import os
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import cdata.aas as mod
import plotly.graph_objs as go

接続文字列を使ってデータへの接続を確立します。connect 関数を使ってCData Azure Analysis Services Connector にAzure Analysis Services data との接続を確立します。

cnxn = mod.connect("URL=asazure://REGION.asazure.windows.net/server;InitiateOAuth=GETANDREFRESH;OAuthSettingsLocation=/PATH/TO/OAuthSettings.txt")")

Azure Analysis Services にクエリを実行

read_sql 関数を使って、padas からSQL 文を発行し、DataFrame に結果を格納します。

df = pd.read_sql("""SELECT Country, Education FROM Customer WHERE Country = 'Australia'""", cnxn)

ウェブアプリケーションの設定

DataFrame に格納されたクエリ結果を使って、ウェブアプリにname、stylesheet、title を設定していきます。

app_name = 'dash-aasedataplot'

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.title = 'CData + Dash'

Layout 設定

次に、Azure Analysis Services data をベースにした棒グラフを作詞し、アプリのレイアウトを設定します。

trace = go.Bar(x=df.Country, y=df.Education, name='Country')

app.layout = html.Div(children=[html.H1("CData Extention + Dash", style={'textAlign': 'center'}),
	dcc.Graph(
		id='example-graph',
		figure={
			'data': [trace],
			'layout':
			go.Layout(alt='Azure Analysis Services Customer Data', barmode='stack')
		})
], className="container")

アプリをセットアップして、実行n

接続、アプリ、レイアウトを定義したら、アプリを実行してみましょう。Python コードの最後はこのようです。

if __name__ == '__main__':
    app.run_server(debug=True)

では、Python でウェブアプリを稼働させて、ブラウザでAzure Analysis Services data を見てみましょう。

python aas-dash.py
Azure Analysis Services data in a Dash web app (Salesforce is shown).

製品の無償トライアル情報

Azure Analysis Services Python Connector の30日の無償トライアル をぜひダウンロードして、Azure Analysis Services data への接続をPython アプリやスクリプトから簡単に作成しましょう。



import os
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import cdata.aas as mod
import plotly.graph_objs as go

cnxn = mod.connect("URL=asazure://REGION.asazure.windows.net/server;InitiateOAuth=GETANDREFRESH;OAuthSettingsLocation=/PATH/TO/OAuthSettings.txt")

df = pd.read_sql("SELECT Country, Education FROM Customer WHERE Country = 'Australia'", cnxn)
app_name = 'dash-aasdataplot'

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.title = 'CData + Dash'
trace = go.Bar(x=df.Country, y=df.Education, name='Country')

app.layout = html.Div(children=[html.H1("CData Extention + Dash", style={'textAlign': 'center'}),
	dcc.Graph(
		id='example-graph',
		figure={
			'data': [trace],
			'layout':
			go.Layout(alt='Azure Analysis Services Customer Data', barmode='stack')
		})
], className="container")

if __name__ == '__main__':
    app.run_server(debug=True)