{"id":48866358,"url":"https://github.com/andrewvillazon/pbipy","last_synced_at":"2026-04-15T18:35:56.273Z","repository":{"id":65369345,"uuid":"569618585","full_name":"andrewvillazon/pbipy","owner":"andrewvillazon","description":"A Python Library for interacting with the Power BI Rest API","archived":false,"fork":false,"pushed_at":"2025-08-10T18:43:22.000Z","size":443,"stargazers_count":99,"open_issues_count":6,"forks_count":31,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-12-07T04:20:57.916Z","etag":null,"topics":["powerbi","python","python3","rest-api"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrewvillazon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-11-23T08:37:08.000Z","updated_at":"2025-11-26T11:46:10.000Z","dependencies_parsed_at":"2023-11-13T22:27:15.174Z","dependency_job_id":"f0ef3cac-6304-4bd1-9d77-2651bdb8c274","html_url":"https://github.com/andrewvillazon/pbipy","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/andrewvillazon/pbipy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewvillazon%2Fpbipy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewvillazon%2Fpbipy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewvillazon%2Fpbipy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewvillazon%2Fpbipy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrewvillazon","download_url":"https://codeload.github.com/andrewvillazon/pbipy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewvillazon%2Fpbipy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31855335,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"ssl_error","status_checked_at":"2026-04-15T15:24:39.138Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["powerbi","python","python3","rest-api"],"created_at":"2026-04-15T18:35:55.591Z","updated_at":"2026-04-15T18:35:56.263Z","avatar_url":"https://github.com/andrewvillazon.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pbipy\n\n![PyPI](https://img.shields.io/pypi/v/pbipy) ![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/andrewvillazon/pbipy) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pbipy) ![GitHub](https://img.shields.io/github/license/andrewvillazon/pbipy) ![Static Badge](https://img.shields.io/badge/Python-blue?logo=python\u0026logoColor=yellow) ![Static Badge](https://img.shields.io/badge/power-bi-yellow?logoColor=yellow\u0026labelColor=yellow\u0026color=black)\n\n\n`pbipy` is a Python Library for interacting with the Power BI Rest API. It aims to simplyify working with the Power BI Rest API and support programatic administration of Power BI in Python.\n\n`pbipy` supports operations for Apps, Dataflows, Datasets, Gateways, Imports, Reports, and Workspaces (Groups), allowing users to perform actions on their PowerBI instance using Python.\n\n## Installation\n\n```console\npip install pbipy\n```\n\nOr to install the latest development code:\n\n```console\npip install git+https://github.com/andrewvillazon/pbipy\n```\n\n## Getting Started: Authentication\n\nTo use `pbipy` you'll first need to acquire a `bearer_token`.\n\n*How do I get a `bearer_token`?*\n\nTo acquire a `bearer_token` you'll need to authenticate against your [Registered Azure Power BI App](https://learn.microsoft.com/en-us/power-bi/developer/embedded/register-app?tabs=customers). Registering is the first step in turning on the Power BI Rest API, so from here on it's assumed your Power BI Rest API is up and running.\n\nTo authenticate against the Registered App, Microsoft provides the `MSAL` and `azure-identity` python libraries. These libraries support different ways of acquiring a `bearer_token` and which to use will depend on how your cloud/tenant is configured.\n\nBecause there are multiple ways to acquire the token, `pbipy` leaves it up to the user do this in the way that suits, rather than directly handling authentication (of course, this might change in future).\n\nThis `README` doesn't cover authentication in detail, however, these are some helpful resources that look at acquiring a `bearer_token` in the context of Power BI:\n\n* [Power BI REST API with Python and MSAL. Part II.](https://www.datalineo.com/post/power-bi-rest-api-with-python-and-msal-part-ii)\n* [Power BI REST API with Python Part III, azure-identity](https://www.datalineo.com/post/power-bi-rest-api-with-python-part-iii-azure-identity)\n* [Monitoring Power BI using REST APIs from Python](https://data-goblins.com/power-bi/power-bi-api-python)\n\nThe example below uses the `msal` library to to get a bearer_token.\n\n```python\nimport msal\n\n\n#  msal auth setup\ndef acquire_bearer_token(username, password, azure_tenant_id, client_id, scopes):\n    app = msal.PublicClientApplication(client_id, authority=azure_tenant_id)\n    result = app.acquire_token_by_username_password(username, password, scopes)\n    return result[\"access_token\"]\n\n\nbearer_token = acquire_bearer_token(\n    username=\"your-username\",\n    password=\"your-password\",\n    azure_tenant_id=\"https://login.microsoftonline.com/your-azure-tenant-id\",\n    client_id=\"your-pbi-client-id\",\n    scopes=[\"https://analysis.windows.net/powerbi/api/.default\"],\n)\n```\n\nThe code that follows assumes you've authenticated and acquired your `bearer_token`.\n\n## Usage\n\nStart by creating the `PowerBI()` client. Interactions with the Power BI Rest API go through this object. \n\n```python\nfrom pbipy import PowerBI\n\npbi = PowerBI(bearer_token)\n```\n\nTo interact with the API, simply call the relevant method from the client.\n\n```python\n# Grab the datasets from a workspace\n\npbi.datasets(group=\"f089354e-8366-4e18-aea3-4cb4a3a50b48\")\n```\n\n`pbipy` converts API responses into regular Python objects, with snake case included! 🐍🐍\n\n```python\nsales = pbi.dataset(\"cfafbeb1-8037-4d0c-896e-a46fb27ff229\")\n\nprint(type(sales))\nprint(hasattr(sales, \"configured_by\"))\n\n# \u003cclass 'pbipy.Dataset'\u003e\n# True\n```\n\nMost methods take in an object id...\n\n```python\ndataset = pbi.dataset(\n    id=\"cfafbeb1-8037-4d0c-896e-a46fb27ff229\",\n    group=\"a2f89923-421a-464e-bf4c-25eab39bb09f\"\n)\n```\n\n... or just pass in the object itself.\n\n```python\ngroup = pbi.group(\"a2f89923-421a-464e-bf4c-25eab39bb09f\")\n\ndataset = pbi.dataset(\n    \"cfafbeb1-8037-4d0c-896e-a46fb27ff229\"\n    ,group=group\n)\n```\n\nIf you need to access the raw json representation, this is supported to.\n\n```python\nsales = pbi.dataset(\"cfafbeb1-8037-4d0c-896e-a46fb27ff229\")\n\nprint(sales.raw)\n\n# {\n#   \"id\": \"cfafbeb1-8037-4d0c-896e-a46fb27ff229\",\n#   \"name\": \"SalesMarketing\",\n#   \"addRowsAPIEnabled\": False,\n#   \"configuredBy\": \"john@contoso.com\",\n#   ...\n# }\n```\n\n## Example: Working with Datasets\n\nLet's see how `pbipy` works by performing some operations on a Dataset.\n\nFirst, we initialize our client.\n\n```python\nfrom pbipy import PowerBI\n\npbi = PowerBI(bearer_token)\n```\n\nNow that we've got a client, we can load a Dataset from the API. To load a Dataset, we call the `dataset()` method with an `id` and `group` argument. In the Power BI Rest API, a **Group** and **Workspace** are synonymous and used interchangeably.\n\n```python\nsales = pbi.dataset(\n    id=\"cfafbeb1-8037-4d0c-896e-a46fb27ff229\",\n    group=\"f089354e-8366-4e18-aea3-4cb4a3a50b48\",\n)\n\nprint(sales)\n\n# \u003cDataset id='cfafbeb1-8037-4d0c-896e-a46fb27ff229', name='SalesMarketing', ...\u003e\n```\n\nDataset not updating? Let's look at the Refresh History. \n\nWe call the `refresh_history()` method on our Dataset. Easy.\n\n```python\nrefresh_history = sales.refresh_history()\n\nfor entry in refresh_history:\n    print(entry)\n\n# {\"refreshType\":\"ViaApi\", \"startTime\":\"2017-06-13T09:25:43.153Z\", \"status\": \"Completed\" ...}\n```\n\nNeed to kick off a refresh? That's easy too.\n\n```python\nsales.refresh()\n```\n\nHow about adding some user permissions to our Dataset? Just call the `add_user()` method with the User's details and permissions.\n\n```python\n# Give John 'Read' access on the dataset\nsales.add_user(\"john@contoso.com\", \"User\", \"Read\")\n```\n\nLastly, if we're feeling adventurous, we can execute DAX against a Dataset and use the results in Python.\n\n```python\ndxq_result = sales.execute_queries(\"EVALUATE VALUES(MyTable)\")\nprint(dxq_result)\n\n# {\n#   \"results\": [\n#     {\n#       \"tables\": [\n#         {\n#           \"rows\": [\n#             {\n#               \"MyTable[Year]\": 2010,\n#               \"MyTable[Quarter]\": \"Q1\"\n#             },\n# ...\n# }\n```\n\n## Example: Working with the Admin object\n\n`pbypi` also supports [Administrator Operations](https://learn.microsoft.com/en-us/rest/api/power-bi/admin), specialized operations available to users with Power BI Admin rights. Let's see how we can use these.\n\nFirst, we need to initialize our client. Then we call the `admin` method and initialize an `Admin` object.\n\n```python\nfrom pbipy import PowerBI\n\npbi = PowerBI(bearer_token)\nadmin = pbi.admin()\n```\n\nNeed to review some access on some reports? We can call the `report_users` method.\n\n```python\nusers = admin.report_users(\"5b218778-e7a5-4d73-8187-f10824047715\")\nprint(users[0])\n\n# {\"displayName\": \"John Nick\", \"emailAddress\": \"john@contoso.com\", ...}\n```\n\nWhat about understanding User activity on your Power BI tenant?\n\n```python\nfrom datetime import datetime\n\nstart_dtm = datetime(2019, 8, 31, 0, 0, 0)\nend_dtm = datetime(2019, 8, 31, 23, 59, 59)\n\nactivity_events = admin.activity_events(start_dtm, end_dtm)\n\nprint(activity_events)\n\n# [\n#   {\n#       \"Id\": \"41ce06d1\", \n#       \"CreationTime\": \"2019-08-13T07:55:15\", \n#       \"Operation\": \"ViewReport\", \n#       ...\n#   },\n#   {\n#       \"Id\": \"c632aa64\", \n#       \"CreationTime\": \"2019-08-13T07:55:10\", \n#       \"Operation\": \"GetSnapshots\", \n#       ...\n#   }\n# ]\n```\n\n## More examples\n\n### Datasets in a Workspace\n\n```python\ndatasets = pbi.datasets(group=\"f089354e-8366-4e18-aea3-4cb4a3a50b48\")\n\nfor dataset in datasets:\n    print(dataset)\n\n# \u003cDataset id='cfafbeb1-8037-4d0c-896e-a46fb27ff229', ...\u003e\n# \u003cDataset id='f7fc6510-e151-42a3-850b-d0805a391db0', ...\u003e\n```\n\n### List Workspaces\n\n```python\ngroups = pbi.groups()\n\nfor group in groups:\n    print(group)\n\n# \u003cGroup id='a2f89923-421a-464e-bf4c-25eab39bb09f', name='contoso'\u003e\n# \u003cGroup id='3d9b93c6-7b6d-4801-a491-1738910904fd', name='marketing'\u003e\n```\n\n### Create a Workspace\n\n```python\ngroup = pbi.create_group(\"contoso\")\nprint(group)\n\n# \u003cGroup id='a2f89923-421a-464e-bf4c-25eab39bb09f', name='contoso'\u003e\n```\n\n### Users and their access\n\n```python\ngroup = pbi.group(\"a2f89923-421a-464e-bf4c-25eab39bb09f\")\nusers = group.users()\n\nfor user in users:\n    print(user)\n\n# {\"identifier\": \"john@contoso.com\", \"groupUserAccessRight\": \"Admin\", ... }\n# {\"identifier\": \"Adam@contoso.com\", \"groupUserAccessRight\": \"Member\", ... }\n```\n\n## Power BI Rest API Operations\n\n`pbipy` methods wrap around the Operations described in the Power BI Rest API Reference:\n\n[Power BI REST APIs for embedded analytics and automation - Power BI REST API](https://learn.microsoft.com/en-us/rest/api/power-bi/)\n\n\n## What's implemented?\n\nMost of the core operations on Datasets, Workspaces (Groups), Reports, Apps, and Dataflows are implemented. Given the many available endpoints, not everything is covered by `pbipy`, so expect a few features to be missing.\n\nIf an operation is missing and you think it'd be useful, feel free to suggest it on the [Issues tab](https://github.com/andrewvillazon/pbipy/issues).\n\n| PowerBI Component   \t| Progress \t| Notes \t                                                                            |\n|---------------------\t|----------\t|-------------------------------------------------------------------------------------- |\n| Datasets            \t| Done     \t|       \t                                                                            |\n| Groups (Workspaces) \t| Done    \t|       \t                                                                            |\n| Reports             \t| Done      |       \t                                                                            |\n| Apps                \t| Done   \t|       \t                                                                            |\n| Dataflows           \t| Done    \t|       \t                                                                            |\n| Gateways           \t| Done    \t|       \t                                                                            |\n| Admin Operations     \t| Done    \t| Implements operations related to Datasets, Groups, Reports, Apps, and Dataflows only. |\n| Imports            \t| Done    \t| Import from One Drive for Business not implemented.                                   |\n| Everything else     \t| Backlog  \t|       \t                                                                            |\n\n## Contributing\n\n`pbipy` is an open source project. Contributions such as bug reports, fixes, documentation or docstrings, enhancements, and ideas are welcome. `pbipy` uses github to host code, track issues, record feature requests, and accept pull requests.\n\nView [CONTRIBUTING.md](https://github.com/andrewvillazon/pbipy/blob/master/CONTRIBUTING.md) to learn more about contributing.\n\n## Acknowledgements\n\nThe design of this library was heavily inspired by (basically copied) the [pycontribs/jira](https://github.com/pycontribs/jira) library. It also borrows elements of [cmberryay's pypowerbi wrapper](https://github.com/cmberryau/pypowerbi).\n\nThank You to all the contributors to these libraries for the great examples of what an API Wrapper can be.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewvillazon%2Fpbipy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrewvillazon%2Fpbipy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewvillazon%2Fpbipy/lists"}