add-function
作成者: microsoft
ライブラリに新しい関数を追加するためのガイドです。新しいAPIラッパーやユーティリティ関数を実装する際に使用します。
npx skills add https://github.com/microsoft/semantic-link-labs --skill add-functionAdding New Functions
This skill covers the workflow for adding new functions to the Semantic Link Labs library.
When to Use This Skill
Use this skill when you need to:
- Add a new API wrapper function
- Create a new utility function
- Extend existing functionality with new features
- Add functions to submodules (admin, report, lakehouse, etc.)
Function Categories
| Category | Location | Purpose |
|---|---|---|
| Top-level functions | src/sempy_labs/_*.py | Main library exports |
| Admin functions | src/sempy_labs/admin/ | Admin API operations |
| Report functions | src/sempy_labs/report/ | Report operations |
| Lakehouse functions | src/sempy_labs/lakehouse/ | Lakehouse operations |
| Direct Lake functions | src/sempy_labs/directlake/ | Direct Lake model operations |
| TOM methods | src/sempy_labs/tom/_model.py | TOMWrapper class methods |
Step 0: Find the API Documentation
Before implementing an API wrapper, find the relevant API documentation:
# Use the API search tool
cd .claude/skills/rest-api-patterns/scripts
python search_public_api_doc.py "your search query"
# Examples:
python search_public_api_doc.py "workspace users" --source fabric
python search_public_api_doc.py "dataset refresh" --source powerbi
See the REST API Patterns skill for more details.
Step 1: Choose the Right Location
Top-Level Function
For general-purpose functions exported from sempy_labs:
# src/sempy_labs/_my_feature.py
Submodule Function
For functions belonging to a specific domain:
# src/sempy_labs/admin/_my_admin_function.py
# src/sempy_labs/lakehouse/_my_lakehouse_function.py
# src/sempy_labs/report/_my_report_function.py
Step 2: Create the Function
Required Imports
import pandas as pd
from typing import Optional, List
from uuid import UUID
# Logging decorator from sempy
from sempy._utils._log import log
# Helper functions
from sempy_labs._helper_functions import (
resolve_workspace_name_and_id,
resolve_workspace_id,
_base_api,
_create_dataframe,
)
# Icons for user messages
import sempy_labs._icons as icons
Function Template
@log
def my_new_function(
item: str | UUID,
workspace: Optional[str | UUID] = None,
option: str = "default",
) -> pd.DataFrame:
"""
Short description of what the function does.
Extended description with more details about the function's behavior,
use cases, and any important notes.
This is a wrapper function for the following API: `API Name <https://learn.microsoft.com/rest/api/...>`_.
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
Parameters
----------
item : str | uuid.UUID
The name or ID of the item.
workspace : str | uuid.UUID, default=None
The Fabric workspace name or ID.
Defaults to None which resolves to the workspace of the attached lakehouse
or if no lakehouse attached, resolves to the workspace of the notebook.
option : str, default="default"
An option that controls function behavior.
Returns
-------
pandas.DataFrame
A pandas dataframe showing the results.
Columns include: 'Column1', 'Column2', 'Column3'.
Raises
------
ValueError
If the item does not exist.
FabricHTTPException
If the API request fails.
"""
# Resolve workspace
(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
# Define result DataFrame structure
columns = {
"Column1": "string",
"Column2": "string",
"Column3": "int",
}
df = _create_dataframe(columns=columns)
# Make API call
responses = _base_api(
request=f"/v1/workspaces/{workspace_id}/items",
uses_pagination=True,
client="fabric_sp",
)
# Process responses
rows = []
for r in responses:
for item in r.get("value", []):
rows.append({
"Column1": item.get("id"),
"Column2": item.get("name"),
"Column3": item.get("count", 0),
})
if rows:
df = pd.DataFrame(rows)
return df
Step 3: Export the Function
From Module File
Add to the module's __init__.py:
# src/sempy_labs/admin/__init__.py (example for admin submodule)
from ._my_admin_function import my_new_function
__all__ = [
...,
"my_new_function",
]
From Main Package
For top-level functions, add to src/sempy_labs/__init__.py:
from ._my_feature import my_new_function
__all__ = [
...,
"my_new_function",
]
Common Patterns
Functions That Modify Resources
@log
def create_item(
name: str,
workspace: Optional[str | UUID] = None,
) -> None:
"""
Creates a new item.
...
"""
(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
payload = {
"displayName": name,
}
_base_api(
request=f"/v1/workspaces/{workspace_id}/items",
method="post",
payload=payload,
status_codes=[201, 202],
client="fabric_sp",
)
print(
f"{icons.green_dot} The '{name}' item has been successfully created "
f"in the '{workspace_name}' workspace."
)
Functions That Delete Resources
@log
def delete_item(
item: str | UUID,
workspace: Optional[str | UUID] = None,
) -> None:
"""
Deletes an item.
...
"""
(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
item_id = resolve_item_id(item=item, type="ItemType", workspace=workspace_id)
_base_api(
request=f"/v1/workspaces/{workspace_id}/items/{item_id}",
method="delete",
client="fabric_sp",
)
print(
f"{icons.green_dot} The item has been successfully deleted "
f"from the '{workspace_name}' workspace."
)
Functions With Long-Running Operations
@log
def long_running_operation(
item: str | UUID,
workspace: Optional[str | UUID] = None,
) -> dict:
"""
Performs a long-running operation.
...
"""
workspace_id = resolve_workspace_id(workspace)
item_id = resolve_item_id(item=item, type="ItemType", workspace=workspace_id)
# lro_return_json handles polling for completion
result = _base_api(
request=f"/v1/workspaces/{workspace_id}/items/{item_id}/operation",
method="post",
lro_return_json=True,
client="fabric_sp",
)
return result
Step 4: Add Tests
Create tests for the new function:
# tests/test_my_feature.py
import pytest
import pandas as pd
def test_my_new_function_returns_dataframe():
"""Test that my_new_function returns a DataFrame."""
from sempy_labs import my_new_function
# This might require mocking for unit tests
result = my_new_function()
assert isinstance(result, pd.DataFrame)
def test_my_new_function_with_workspace():
"""Test my_new_function with specific workspace."""
from sempy_labs import my_new_function
result = my_new_function(workspace="Test Workspace")
assert isinstance(result, pd.DataFrame)
Step 5: Document the Function
Ensure the docstring follows numpydoc style:
- ✅ Short description (one line)
- ✅ Extended description (if needed)
- ✅ API reference link (for wrapper functions)
- ✅ Service Principal note (if supported)
- ✅ All parameters documented with types
- ✅ Return value documented
- ✅ Exceptions documented (if applicable)
Checklist Before Committing
- Function follows naming conventions (
list_,get_,create_, etc.) -
@logdecorator is applied - Complete docstring with numpydoc style
- Type hints for all parameters and return value
- Uses standard helper functions (
_base_api,resolve_*, etc.) - Function exported in
__init__.py - Tests written for the new function
- Code formatted with black
- No linting errors
- Documentation builds without warnings
Example: Complete New Function
See _workspaces.py for well-implemented examples:
list_workspace_users— List function returning DataFrameupdate_workspace_user— Update function with parametersdelete_user_from_workspace— Delete function with confirmation message
API Documentation Resources
When wrapping REST APIs, reference the official documentation:
| API | Documentation |
|---|---|
| Fabric Core API | https://learn.microsoft.com/rest/api/fabric/core/ |
| Fabric Admin API | https://learn.microsoft.com/rest/api/fabric/admin/ |
| Power BI REST API | https://learn.microsoft.com/rest/api/power-bi/ |
| Azure Management API | https://learn.microsoft.com/rest/api/resources/ |
microsoftのその他のスキル
oss-growth
microsoft
OSS成長ハッカーのペルソナ
official
microsoft-foundry
microsoft
Foundryエージェントのエンドツーエンドでのデプロイ、評価、管理:Dockerビルド、ACRプッシュ、ホスト型/プロンプトエージェント作成、コンテナ起動、バッチ評価、継続的評価、プロンプト最適化ワークフロー、agent.yaml、トレースからのデータセットキュレーション。用途:エージェントをFoundryにデプロイ、ホスト型エージェント、エージェント作成、エージェント呼び出し、エージェント評価、バッチ評価実行、継続的評価、継続的モニタリング、継続的評価ステータス、プロンプト最適化、プロンプト改善、プロンプトオプティマイザー、エージェント指示最適化、エージェント改善...
officialdevelopmentdevops
azure-ai
microsoft
Azure AI向けに使用:Search、Speech、OpenAI、Document Intelligence。検索、ベクター/ハイブリッド検索、音声認識、音声合成、文字起こし、OCRを支援。使用時:AI Search、クエリ検索、ベクター検索、ハイブリッド検索、セマンティック検索、音声認識、音声合成、文字起こし、OCR、テキスト読み上げ。
officialdevelopmentapi
azure-deploy
microsoft
既存の.azure/deployment-plan.mdとインフラストラクチャファイルを持つ、すでに準備済みのアプリケーションに対してAzureデプロイを実行します。ユーザーが新しいアプリケーションの作成を依頼した場合はこのスキルを使用せず、代わりにazure-prepareを使用してください。このスキルは、azd up、azd deploy、terraform apply、az deploymentコマンドを組み込みのエラーリカバリ機能付きで実行します。azure-prepareからの.azure/deployment-plan.mdと、azure-validateからの検証済みステータスが必要です。使用タイミング:「azd upを実行」、「azd deployを実行」、「デプロイを実行」...
officialdevopsaws
azure-storage
microsoft
Azure Storage Servicesには、Blob Storage、File Shares、Queue Storage、Table Storage、Data Lakeが含まれます。ストレージアクセス層(ホット、クール、コールド、アーカイブ)について、各層の使用タイミングや比較に関する質問に回答します。オブジェクトストレージ、SMBファイル共有、非同期メッセージング、NoSQLキーバリュー、ビッグデータ分析を提供します。ライフサイクル管理を含みます。使用用途:ブロブストレージ、ファイル共有、キューストレージ、テーブルストレージ、データレイク、ファイルアップロード、ブロブダウンロード、ストレージアカウント、アクセス層、...
officialdevelopmentdatabase
azure-diagnostics
microsoft
Azure上でAppLens、Azure Monitor、リソースヘルス、安全なトリアージを使用して、Azureの本番環境の問題をデバッグします。使用時:本番環境の問題のデバッグ、App Serviceのトラブルシューティング、App Serviceの高CPU、App Serviceのデプロイ障害、コンテナアプリのトラブルシューティング、Functionsのトラブルシューティング、AKSのトラブルシューティング、kubectlが接続できない、kube-system/CoreDNSの障害、PodがPending状態、CrashLoop、ノードがReadyにならない、アップグレード障害、ログの分析、KQL、インサイト、イメージプル障害、コールドスタート問題、ヘルスプローブ障害、...
officialdevopsdevelopment
azure-prepare
microsoft
Azureアプリのデプロイ準備(インフラBicep/Terraform、azure.yaml、Dockerfiles)。新規作成/モダナイズ、または作成+デプロイに使用。クロスクラウド移行には非対応(azure-cloud-migrateを使用)。使用禁止:copilot-sdkアプリ(azure-hosted-copilot-sdkを使用)。対象:「アプリ作成」「Webアプリ構築」「API作成」「サーバーレスHTTP API作成」「フロントエンド作成」「バックエンド作成」「サービス構築」「アプリケーションのモダナイズ」「アプリケーション更新」「認証追加」「キャッシュ追加」「Azureへのホスティング」「作成および...」
officialdevelopmentdevops
azure-validate
microsoft
Azureへの準備が整っているかを確認するためのデプロイ前検証。構成、インフラストラクチャ(BicepまたはTerraform)、RBACロールの割り当て、マネージドIDの権限、前提条件について詳細なチェックを実行します。使用場面:アプリの検証、デプロイ準備状況の確認、事前チェックの実行、構成の確認、デプロイ可能かの確認、azure.yamlの検証、Bicepの検証、デプロイ前のテスト、デプロイエラーのトラブルシューティング、Azure Functionsの検証、関数アプリの検証、サーバーレスの検証...
officialdevopstesting