4 Replies Latest reply on Oct 20, 2019 10:35 PM by shriram Pillai

    Creating hyper extract using Python Extract API and pandas

    Michael Liu

      Hi experts,

       

      I'm using Tableau Extract API to create extracts (hyper files). I have loaded my data into pandas dataframe and I'm iterating rows and columns to put each value into extract by using these "setXXX" functions (e.g. setDouble(), setString() etc) according to the column types.

      Is there a quicker way to populate data into extract than iterating rows and columns? Can I do this in bulk?

       

      Thanks,

      Michael

        • 1. Re: Creating hyper extract using Python Extract API and pandas
          Jonas Eckhardt

          Hi Michael,

           

          with the Extract API 2.0, that is the way to go.

           

          You might want to try our pre-release of the new Hyper API (the successor of the Extract API). With the all-new Hyper API, Developers can now utilize full CRUD support at Hyper-speed and unleash the power of SQL to interact with .hyper files. We improved the extract creation performance and also enable to directly read from CSV files.

           

          To get access to the pre-release, you need to join the Tableau Develop Program. If you are not part of the Developer Program yet, register here and join the “Developer Program Sprint Demos!” under “AVAILABLE OPPORTUNITIES”. Then, go here for more information on Hyper API features, supported languages and platforms.

           

          Thanks

          Jonas

          • 2. Re: Creating hyper extract using Python Extract API and pandas
            Michael Liu

            Hi Jonas,

             

            Thank you very much for your reply. Good to know the new API supports full CRUD operations to the extracts, it's very helpful! I'll try out the pre-release version.

             

             

            Thanks,

            Michael

            • 3. Re: Creating hyper extract using Python Extract API and pandas
              William Ayd

              Hi Michael - I just released pantab for this exact purposes. It is still under active development so expect more features in the future, but for now this allows for easy reading and writing of single DataFrames in Hyper Extracts:

               

              Read / Write Hyper Extracts with pandas and pantab

               

              You can install directly from pip

              • 4. Re: Creating hyper extract using Python Extract API and pandas
                shriram Pillai

                Hi Michael,

                 

                Is there a quicker way to populate data into extract than iterating rows and columns? Can I do this in bulk?

                Yes, there is quicker way to populate. Have a look on below python code. I have used pandaleau along with tableau hyper API  to create extract. It directly reads the data  from MSSQL Server.

                 

                Note: You have to install Tableau Hyper API before running below code  (Extract API-Installing - Tableau ). Below code work for creating both .tde and .hyper file

                 

                import pyodbc

                import pandas as pd

                from pandleau import *

                 

                 

                driver = 'SQL Server'

                server = 'Your SQL Server Name'

                 

                cnxn = pyodbc.connect(driver='{SQL Server}', host=server, database='Your DB Name',trusted_connection='yes')

                q=('select * from [dbo].[Extract_Table]')        /* From MSSQL server*/

                df=pd.read_sql(q,cnxn)

                df_tableau = pandleau(df)

                df_tableau.to_tableau("C:\Users\Sh\TableauExtract.hyper", add_index=False)