Package: pymsasdax
AboutI wanted to consume some info from Azure Analysis Services from python and didn't see a convenient way to to do, so I wrote this. It should also work just fine with XMLA endpoints on Power BI Premium.pymsasdax is a small Python Module for running DAX queries against Microsoft Analysis Services, using COM Interop. It does some basic typesniffing and returns a best guess Pandas Dataframe.This does assume that the MSOLAP client is installed - you can get it fromhereI've done very little testing, so consider this alpha code. If you run into timeouts, make sure you're setting the timeout to an appropriate duration when creating the Connection.tidy_column_names will remove brackets and replace spaces with underscores in the returned dataframe's columns. Set it to False in the Connection init if you don't want this behavior.Also, this is my first module up on pypi and I'm not exactly an expert on python, so feel free to submit an issue or a pull request. If I ended up reinventing the wheel here (ha!) and there was an easier way to do this, also please let me know.I hope you find this useful!Python before 3.9This should actually work fine with for python 3 under 3.9. I've used this code for a couple of years now without incident -- I was just lazy when building this package. Ithinkyou'd need backports to supportdateparser. Feel free to path and submit a PR if you like.Usage examplesHave an interactive prompt for Login to the resourcefrompymsasdaximportdaxwithdax.Connection(data_source='asazure://<region name>.asazure.windows.net/<instance here>,initial_catalog='<my tabular database>')asconn:df=conn.query('EVALUATE ROW("a", 1)')print(df)Query a Power BI Premium Workspace XMLA endpointYou can also find the endpoint in your workspace settings, as shown below. You'll use the dataset name as the initial_catalog.frompymsasdaximportdaxwithdax.Connection(data_source='powerbi://api.powerbi.com/v1.0/myorg/<workspace name, spaces are fine>',initial_catalog='<dataset name - spaces are fine>')asconn:df=conn.query('EVALUATE ROW("a", 1)')print(df)Use an app idfrompymsasdaximportdaxwithdax.Connection(data_source='asazure://<region name>.asazure.windows.net/<instance here>',initial_catalog='<my tabular database>'uid='app:<client id>@<tenant id>',password='<client secret>')asconn:df=conn.query('EVALUATE ROW("a", 1)')df.to_csv("raw_data.csv",index=False)Rename columns your wayfrompymsasdaximportdaxdefmy_column_renamer(colname):returncolname.lower()withdax.Connection(data_source='asazure://<region name>.asazure.windows.net/<instance here>',initial_catalog='<my tabular database>',tidy_map_function=my_column_renamer)asconn:df=conn.query('EVALUATE SUMMARIZECOLUMNS (etc....etc...etc...)')print(df)Dev NotesVersion History2023.1020fix timeout not being honored as CommandTimeout2023.1018fix bug using effective_user_name or kwargs2023.1017fix bug using effective_user_name2023.1016Add at least some docstringsAdd Premium XMLA endpoint exampleAdd effective_user_name parameter to connectionPass **kwargs as additional connection string key value pairs2023.1013Fix issue with column names populating from when i made initial package versionAllow specificiation of column name cleanup function2023.1001 - InitialTestsYes. There aren't any. Feel free to submit a PR.BuildingThis might not be right but if you ever go to update pypi -bumpver update --dry --set-version="2023.1020"
pip-compile pyproject.toml
python -m pip install -e . 
#test
python -m build
twine check dist/*
twine upload dist/*