Skip to main content

Dbx to Pbi Wrapper

Project description

DbxPbiApiWrapper

Overview

DbxPbiApiWrapper is a Python-based wrapper designed to simplify interactions with the Power BI API. It provides a set of classes and methods for handling common tasks such as dataset management, refresh operations, and user access management. This library is optimized for integration with Databricks, making it ideal for seamless data analytics workflows.

Features

  • Azure AD Token Management: Automated handling of Azure Active Directory (AAD) token validation.
  • Dataset Operations: Retrieve, list, and manage datasets within specified Power BI workspaces.
  • Refresh Functionality: Easily trigger and monitor dataset refreshes, with built-in checks for ongoing operations.
  • User Access Management: Fetch detailed user access information for specific datasets.
  • Refresh History: Retrieve the history of dataset refresh operations.

Prerequisites

  • Python 3.8 or higher
  • Microsoft Power BI Service account with the following API permissions:
    • Dataset.Read.All
    • Dataset.Write.All
    • Group.Read.All
  • Azure AD App registration configured with the necessary permissions.

Installation

To install the package, clone the repository and use:

pip install DbxPbiApiWrapper

Usage

Initialization

Initialize the DbxPbiDatasetWrapper class with your Azure AD tenant details and credentials.

from DbxPbiWrapper import DbxPbiDatasetWrapper

# Define your credentials
tenant = "your-tenant-id"
account_key = "your-account-key"
account_secret = "your-account-secret"

# Initialize the wrapper
pbi_wrapper = DbxPbiDatasetWrapper(tenant, account_key, account_secret)

Example 1: Refresh a Power BI Dataset

Trigger a refresh for a specific dataset in a workspace:

workspace_name = "SalesWorkspace"
dataset_name = "SalesDataset"
try:
    *Trigger dataset refresh*    pbi_wrapper.refreshPbiDataset(workspace_name, dataset_name)
    print("Dataset refresh initiated successfully.")
except Exception as e:
    print(f"Failed to refresh dataset: {str(e)}")

Example 2: List All Datasets in a Workspace

Retrieve all datasets in a specified workspace:

workspace_name = "MarketingWorkspace"
# Fetch and display datasets
datasets = pbi_wrapper.getAllDatasetsInWorkspace(workspace_name)
if datasets:
    for dataset in datasets:
        print(f"Dataset Name: {dataset['name']}, Dataset ID: {dataset['id']}")
else:
    print("No datasets found in the workspace.")

Example 3: Get Users with Access to a Dataset

Fetch a list of users who have access to a specific dataset:

workspace_name = "FinanceWorkspace"
dataset_name = "RevenueDataset"

# Retrieve user access details
users = pbi_wrapper.getUsersInDataset(workspace_name, dataset_name)
if users:
    for user in users:
        print(f"User: {user['displayName']}, Role: {user['datasetUserAccessRight']}")
else:
    print("No users found with access to this dataset.")

Class Descriptions

DbxPbiDatasetWrapper

Main interface for interacting with Power BI services:

  • refreshPbiDataset(workspaceName, datasetName): Initiates a dataset refresh.
  • getAllDatasetsInWorkspace(workspaceName): Lists all datasets in a workspace.
  • getAllWorkspaces(): Retrieves a list of all available workspaces.
  • getUsersInDataset(workspaceName, datasetName): Fetches users with access to a dataset.
  • getDatasetRefreshHistory(workspaceName, datasetName): Returns the refresh history of a dataset.

Error Handling

The library includes basic error handling for common issues like:

  • Invalid Azure AD credentials
  • Insufficient API permissions
  • Ongoing dataset refresh preventing new refresh requests
  • It is recommended to implement proper exception handling when integrating this library into your projects.

Contribution

We welcome contributions! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch (feature/your-feature-name).
  3. Submit a pull request for review.

Contact

For support or questions, please contact the author at info@j2datagroup.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbxpbiapiwrapper-0.0.8.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

DbxPbiApiWrapper-0.0.8-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file dbxpbiapiwrapper-0.0.8.tar.gz.

File metadata

  • Download URL: dbxpbiapiwrapper-0.0.8.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for dbxpbiapiwrapper-0.0.8.tar.gz
Algorithm Hash digest
SHA256 d9121b86f23e09312ae391e8dc135938ca7a73a4a6831a060519d607d006afe2
MD5 d82253d04252e7c79dbc0c492826908f
BLAKE2b-256 36f63802525217182a7f6cdc38e20005c9bbd743207d71c6372c6927daffd4ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbxpbiapiwrapper-0.0.8.tar.gz:

Publisher: pypublish.yml on J2DataGroup/DbxPbiWrapper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file DbxPbiApiWrapper-0.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for DbxPbiApiWrapper-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 5986567e54f7b779a7786573f0eac764ca50366f8dff1479bd02655c92d860e2
MD5 80c57fae928e22ee4186bec6f883c4c4
BLAKE2b-256 a70cef68c438a4b78c01edaa9a705f5827cd39fe12ca0d43e44cfc27db8f6837

See more details on using hashes here.

Provenance

The following attestation bundles were made for DbxPbiApiWrapper-0.0.8-py3-none-any.whl:

Publisher: pypublish.yml on J2DataGroup/DbxPbiWrapper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page