Connect to your tabular model and perform operations programmatically
Project description
PyTabular
What is it?
PyTabular is a python package that allows for programmatic execution on your tabular models! This is possible thanks to Pythonnet and Microsoft's .Net APIs on Azure Analysis Services. The package should have the dll files included when you import it.
Getting Started
python3 -m pip install python_tabular
In your python environment, import pytabular and call the main Tabular Class. Only parameter needed is a solid connection string.
import pytabular
model = pytabular.Tabular(CONNECTION_STR)
DAX Query
model.Query(DAX_QUERY)
# Returns a Pandas DataFrame
Refresh Tables and Partitions
#filter down the collection to what you want to refresh
tables_to_refresh = [table for table in model.Tables if table.Name in ['Table1','Table2','Table3']]
#Queue up the tables and partitions that you want to refresh.
model.Refresh(tables_to_refresh)
#Once you are ready, update to execute the refresh
model.Update()
Built In Dax Query Helpers
#Query Every Column
model.Query_Every_Column() #Will return pd.DataFrame()
#Query Every Table
model.Query_Every_Table() #Will return pd.DataFrame()
'''
NOTE, notice the default values for the query_function argument.
Query_Every_Column will get COUNTROWS(VALUES(_))
and Query_Every_Table() will get COUNTROWS(_)
with '_' being replaced with the dax identifier to the table or column in question.
You can replace this str with anything you want. For example output the MIN(_) or MAX(_) of each column rather than the default queries.
'''
Backup & Revert a Table in Memory
model.Backup_Table('TableName') #This will backup the table with surround items (columns,measures,relationships,roles,hierarchies,etc.) and will add a suffix of '_backup'
#Make any changes to your original table and then revert or delete backup as necessary
model.Revert_Table('TableName') #This will essentially replace your original with _backup
Run BPA from TE2
TE2 = pytabular.TE2() #Feel free to input your TE2 File path or this will download for you.
BPA = pytabular.BPA() #Fee free to input your own BPA file or this will download for you from: https://raw.githubusercontent.com/microsoft/Analysis-Services/master/BestPracticeRules/BPARules.json
model.Analyze_BPA(TE2.EXE_Path,BPA.Location) #This will output a list of BPA violations...
I'm working on converting everything to the google docstring format and using those to populate the documentation. I still have some formatting issues to work through, but that should help with understanding what this package can do.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for python_tabular-0.0.9b0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c31ea02e6192d1147dc288218b91cdcee67f6dc47477e48cc325ef56785828c |
|
MD5 | 7d51eec2560176534237ff006f70bb17 |
|
BLAKE2b-256 | 7ca1f0e88e2fa2438a67c115476bf8812695f71469b197714f558bfafacb6dd0 |