Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

jonkarde/python-ssas

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-ssas

Prerequisites:

  • Good working knowledge of:
    • Microsoft SQL Server Analysis Services (Tabular models)
    • Python (specifically pandas)
  • Some knowledge required:
    • General Microsoft .Net familiarity

Motivation:

I’ve been working for some time analyzing data using two unrelated tools – Python (primarily pandas), and DAX in Microsoft’s Tabular models. They are very different – Python is open source, Microsoft’s products are (obviously) not. It was frustrating to not be able to merge them. If I wanted to get data from a DAX data model into a Pandas dataframe, I would typically need to first export it to a file (like CSV) and then read it from there.

Also, I wanted a way to programatically "refresh" the data model (called "processing" it) from Python.

Solution:

Inspired by @akavalar's great post, I discovered a nice workaround:

  • DAX models (or any Analysis Services model) have several .Net APIs, see here for the Microsoft documentation
  • Also, there is a fantastic Python library called Pythonnet that enables near seamless integration between Python and .Net. This is for the mainstream Python, called CPython, and not to be confused with the .Net implementation of Python which is called IronPython.

Using these ingredients, I created my ssas_api.py module with some utilities that I use frequently. Note that this just uses the parts of the APIs that I needed; there is a wealth more available, just dig through the documentation.

Note: I've only been using Azure Analysis Services, so the code is designed for that regarding the URL of the server and authentication string.

I haven't found anything like this online, so feel free to use it.

Quickstart

In [1]: import ssas_api
   ...: 
   ...: conn = ssas_api.set_conn_string(
   ...:     ssas_server='<YOUR_SERVER>',
   ...:     db_name='<YOUR_DATABASE>',
   ...:     username='<USERNAME>',
   ...:     password='<PASSWORD>'
   ...: )

In [2]: dax_string = '''
   ...: //any valid DAX query
   ...: EVALUATE
   ...: CALCULATETABLE(MyTable)
   ...: '''

In [3]: df = ssas_api.get_DAX(connection_string=conn, dax_string=dax_string)

About

A proof of concept to integrate Python and Microsoft Analysis Services

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.