Forum Discussion
How to Connect to Power BI Service Datasets and Pull Data Using Python Locally (Outside Fabric)
- 1 year ago
I did a test on this and it's working , & this is a general pro workspace , not a permium one
following is the test python code
import adodbapi # Connection string (edit table and workspace as needed) conn = adodbapi.connect("Provider=MSOLAP.8; \ Data Source='powerbi://api.powerbi.com/v1.0/myorg/Testws'; \ Initial Catalog='db1'") # Create cursor cursor = conn.cursor() # Replace 'YourTableName' with a real table name in your data model dax_query = "EVALUATE 'table'" print("Querying table: table") cursor.execute(dax_query) # Fetch column names columns = [column[0] for column in cursor.description] print("Columns:", columns) # Fetch all rows rows = cursor.fetchall() for row in rows: print(row) # Close the connection cursor.close() conn.close() - 1 year ago
Hi kushanNa
Thanks for this approach — it's working fine. A couple of key points to keep in mind:
Use a lower version of Python (e.g., 3.7), as the latest versions are not supported.
Avoid spaces in the workspace name, as this is causing issues.
Currently, it uses SSO authentication, but I’m looking to use an Azure Service Principal (SPN) instead, as I’m building an application. If you know of any method to bypass SSO authentication or enable SPN-based auth, please share it.
Thanks!
Akhil Grandhi
Apologise for the misunderstanding
I think this is what you need ? but unfortunately I'm using a free account, so I don't have a premium space to test this
https://stackoverflow.com/questions/56347765/connect-to-power-bi-xmla-endpoint-with-python
https://stackoverflow.com/questions/56075159/convert-listadodbapi-apibase-sqlrow-to-pd-dataframe
I did a test on this and it's working , & this is a general pro workspace , not a permium one
following is the test python code
import adodbapi
# Connection string (edit table and workspace as needed)
conn = adodbapi.connect("Provider=MSOLAP.8; \
Data Source='powerbi://api.powerbi.com/v1.0/myorg/Testws'; \
Initial Catalog='db1'")
# Create cursor
cursor = conn.cursor()
# Replace 'YourTableName' with a real table name in your data model
dax_query = "EVALUATE 'table'"
print("Querying table: table")
cursor.execute(dax_query)
# Fetch column names
columns = [column[0] for column in cursor.description]
print("Columns:", columns)
# Fetch all rows
rows = cursor.fetchall()
for row in rows:
print(row)
# Close the connection
cursor.close()
conn.close()
- AkhilGrandhi11 year agoHelper I
Hi kushanNa
Thanks for this approach — it's working fine. A couple of key points to keep in mind:
Use a lower version of Python (e.g., 3.7), as the latest versions are not supported.
Avoid spaces in the workspace name, as this is causing issues.
Currently, it uses SSO authentication, but I’m looking to use an Azure Service Principal (SPN) instead, as I’m building an application. If you know of any method to bypass SSO authentication or enable SPN-based auth, please share it.
Thanks!
Akhil Grandhi- AkhilGrandhi11 year agoHelper I
Hi kushanNa
Thanks for this approach — it's working fine. A couple of key points to keep in mind:
Use a lower version of Python (e.g., 3.7), as the latest versions are not supported.
Avoid spaces in the workspace name, as this is causing issues.
Currently, it uses SSO authentication, but I’m looking to use an Azure Service Principal (SPN) instead, as I’m building an application. If you know of any method to bypass SSO authentication or enable SPN-based auth, please share it.
Thanks!
Akhil Grandhi- kushanNa1 year agoSuper User
I think i found a service principal based solution for this , but since you have marked your comment as an answer could you please start a new thread and provide me the link ? I will provide my findings in there , thanks for your understanding 🙂
- AkhilGrandhi11 year agoHelper I
Hi kushanNa
I'm trying to run this code but encountering the following error. Could you please clarify how the authentication process works? Can I directly copy and paste the connection string, or is there any configuration like python version or .net version etc or permission I need to set to execute this script successfully?
- kushanNa1 year agoSuper User
What dose the error says ? should be in the far right corner
A usual Microsoft authentication login should pop up once the code run successfully , that's how it authentication with your fabric account
make sure you have correct workspace name in here (testws) change it to yours (db1) change it to your dataset name
Data Source='powerbi://api.powerbi.com/v1.0/myorg/Testws'; \ Initial Catalog='db1'")and also change the table name to your table
# Replace 'YourTableName' with a real table name in your data model dax_query = "EVALUATE 'table'"