製品をチェック

Azure Active Directory Connector の30日間無償トライアルをダウンロード

 30日間の無償トライアルへ

製品の詳細

Azure Active Directory アイコン Azure Active Directory Python Connector 相談したい

Azure Active Directory へのデータ連携用のPython Connecotr ライブラリ。 pandas、SQLAlchemy、Dash、petl などの主要なPython ツールにAzure Active Directory をシームレスに統合。

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

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

加藤龍彦
デジタルマーケティング

最終更新日:2023-09-23
azureactivedirectory ロゴ

CData

python ロゴ画像
Python ロゴ

こんにちは!ウェブ担当の加藤です。マーケ関連のデータ分析や整備もやっています。

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

CData Python Connectors の特徴

CData Python Connectors は、以下のような特徴を持った製品です。

  1. Azure Active Directory をはじめとする、CRM、MA、会計ツールなど多様なカテゴリの270種類以上のSaaS / オンプレデータソースに対応
  2. Dash をはじめとする多様なデータ分析・BI ツールにAzure Active Directory データを連携
  3. ノーコードでの手軽な接続設定

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

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

pip install pandas
pip install dash
pip install dash-daq

Python でAzure Active Directory データを可視化

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

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

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

接続文字列を使ってデータへの接続を確立します。connect 関数を使ってCData Azure Active Directory Connector からAzure Active Directory データ との接続を確立します。

cnxn = mod.connect("OAuthClientId=MyApplicationId;OAuthClientSecret=MySecretKey;CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH;OAuthSettingsLocation=/PATH/TO/OAuthSettings.txt")")

Azure Active Directory はOAuth 認証を使用します。OAuth で認証するには、OAuthClientIdOAuthClientSecret、およびCallbackURL 接続プロパティを取得するアプリを作成する必要があります。認証手順は、ヘルプドキュメントのOAuth セクションを参照してください。

Azure Active Directory にクエリを実行

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

df = pd.read_sql("""SELECT id, availabilityStatus FROM Domains WHERE isVerified = 'TRUE'""", cnxn)

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

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

app_name = 'dash-azureadedataplot'

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

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

Layout 設定

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

trace = go.Bar(x=df.id, y=df.availabilityStatus, name='id')

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 Active Directory Domains Data', barmode='stack')
		})
], className="container")

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

接続、アプリ、レイアウトを定義したら、アプリを実行してみましょう。以下のコードで実行できます。

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

最後に、Python でウェブアプリを起動してブラウザでAzure Active Directory データ を見てみましょう。

python azuread-dash.py
Dash のウェブアプリでAzure Active Directory データ を表示

ちゃんとデータが表示できてますね!

おわりに

Azure Active Directory Python Connector の30日の無償トライアル をぜひダウンロードして、Azure Active Directory データ への接続をPython アプリやスクリプトから簡単に作成してみてください。



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

cnxn = mod.connect("OAuthClientId=MyApplicationId;OAuthClientSecret=MySecretKey;CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH;OAuthSettingsLocation=/PATH/TO/OAuthSettings.txt")

df = pd.read_sql("SELECT id, availabilityStatus FROM Domains WHERE isVerified = 'TRUE'", cnxn)
app_name = 'dash-azureaddataplot'

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.id, y=df.availabilityStatus, name='id')

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 Active Directory Domains Data', barmode='stack')
		})
], className="container")

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

関連コンテンツ

トライアル・お問い合わせ

30日間無償トライアルで、CData のリアルタイムデータ連携をフルにお試しいただけます。記事や製品についてのご質問があればお気軽にお問い合わせください。