A lightweight Python client for interacting with the Power BI REST API. The library provides simple, object-oriented helpers to authenticate, list workspaces, fetch datasets and inspect data models.
Create a virtual environment and install the dependencies:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtAuthentication details are read from environment variables. Create a .env
file or export the following variables in your environment:
POWERBI_TENANT_ID=<your-tenant-id>
POWERBI_CLIENT_ID=<your-client-id>
POWERBI_CLIENT_SECRET=<your-client-secret>
The client authenticates using an Azure AD service principal via the
msal library.
Run the example script to list workspaces and datasets:
python examples/example_usage.pyYou can specify a workspace to list datasets from using the --workspace-id
flag. You can also print tables for a specific dataset using --dataset-id
and display dashboards with --show-dashboards:
python examples/example_usage.py --workspace-id YOUR_WORKSPACE_ID \
--dataset-id YOUR_DATASET_ID --show-dashboardsThis will output a table of your Power BI workspaces and datasets using
pandas DataFrames.
All get_raw methods accept a fetch_all flag. When set to True, the
client automatically handles $top/$skip pagination and returns all
records.
The codebase is structured to be easily extended for additional Power BI endpoints. Each entity class contains two core methods:
get_raw- fetch raw JSON data from the API.to_dataframe- return the data as apandasDataFrame for analysis.
Additional helpers and endpoints can be implemented following the same pattern.
Use powerbi_api_client.utils.save_json to write any Python object to a
JSON file. The helper creates a json_data directory by default and accepts a
custom file name:
from powerbi_api_client.utils import save_json
data = {"hello": "world"}
save_json(data, "example.json")