Skip to content
Skills Library
Programming · Building & coding

add-function

/add-function

Guide for adding new functions to the library. Use this when implementing new API wrappers or utility functions.

Licence
MIT
Last repository change
19.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
10
Deprecation

No signals detected. Repository changed on 19.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Guide for adding new functions to the library. Use this when implementing new API wrappers or utility functions.

Original author description

Guide for adding new functions to the library. Use this when implementing new API wrappers or utility functions.

How it works

  1. When to Use This Skill
  2. Function Categories
  3. Step 0: Find the API Documentation
  4. Step 1: Choose the Right Location
  5. Step 2: Create the Function
  6. Step 3: Export the Function
  7. Common Patterns
  8. Step 4: Add Tests
  9. Step 5: Document the Function
  10. Checklist Before Committing
Original SKILL.md headings · 375 lines, 1,035 words
SKILL.md preview
---
name: add-function
description: Guide for adding new functions to the library. Use this when implementing new API wrappers or utility functions.
---

# Adding 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:

```bash
# 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](../rest-api-patterns/SKILL.md) skill for more details.

---

## Step 1: Choose the Right Location

### Top-Level Function

For general-purpose functions exported from `sempy_labs`:

```python
# src/sempy_labs/_my_feature.py
```

### Submodule Function

For functions belonging to a specific domain:

```python
# 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

```python
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

```python
@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`:

```python
# 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`:

```python
from ._my_feature import my_new_function

__all__ = [
    ...,
    "my_new_function",
]
```

---

## Common Patterns

### Functions That Modify Resources

```python
@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

```python
@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

```python
@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:

```python
# 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:

1. ✅ Short description (one line)
2. ✅ Extended description (if needed)
3. ✅ API reference link (for wrapper functions)
4. ✅ Service Principal note (if supported)
5. ✅ All parameters documented with types
6. ✅ Return value documented
7. ✅ Exceptions documented (if applicable)

---

## Checklist Before Committing

- [ ] Function follows naming conventions (`list_`, `get_`, `create_`, etc.)
- [ ] `@log` decorator 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](../../src/sempy_labs/_workspaces.py) for well-implemented examples:

- `list_workspace_users` — List function returning DataFrame
- `update_workspace_user` — Update function with parameters
- `delete_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/](https://learn.microsoft.com/rest/api/fabric/core/) |
| Fabric Admin API | [https://learn.microsoft.com/rest/api/fabric/admin/](https://learn.microsoft.com/rest/api/fabric/admin/) |
| Power BI REST API | [https://learn.microsoft.com/rest/api/power-bi/](https://learn.microsoft.com/rest/api/power-bi/) |
| Azure Management API | [https://learn.microsoft.com/rest/api/resources/](https://learn.microsoft.com/rest/api/resources/) |

Versions

RepositoryScoreLicence
This page · microsoft/semantic-link-labs100MIT
microbus-io/fabric100Apache-2.0

Database snapshot: 13.11.2026 · package version 601647020006 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 95rest-api-patterns
    Guide for implementing REST API wrapper functions. Use this when adding new API wrappers or troubleshooting API calls.
  • 100add-command
    Guide for adding new CLI commands or subcommands to todoist-cli. Use when implementing new SDK endpoints, adding subcommands to existing command groups, or extending CLI functionality.
  • 95types-check
    Validate function inputs in R using a standalone file of check_* functions. Use when writing exported R functions that need input validation, reviewing existing validation code, or when creating new input validation helpers.
  • 100tidy-deprecate-function
    Guide for deprecating R functions/arguments. Use when a user asks to deprecate a function or parameter, including adding lifecycle warnings, updating documentation, adding NEWS entries, and updating tests.
  • 100add-python-function
    TRIGGER when user asks to add a Python-backed function endpoint to an existing Python-backed microservice.
  • 100zhihu-pp-ai-slop-cleaner
    Use for Zhihu++ maintenance work that scans Kotlin main sources for low-call functions, structurally similar function bodies, dead code, pure forwarding wrappers, pointless abstractions, repeated helpers, and cross-platform duplicate glue before refactoring or PR cleanup.…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.