How to Build an ETL App for Anaplan Data in Python with CData

Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Create ETL applications and real-time data pipelines for Anaplan data in Python with petl.

The rich ecosystem of Python modules lets you get to work quickly and integrate your systems more effectively. With the CData Python Connector for Anaplan and the petl framework, you can build Anaplan-connected applications and pipelines for extracting, transforming, and loading Anaplan data. This article shows how to connect to Anaplan with the CData Python Connector and use petl and pandas to extract, transform, and load Anaplan data.

With built-in, optimized data processing, the CData Python Connector offers unmatched performance for interacting with live Anaplan data in Python. When you issue complex SQL queries from Anaplan, the driver pushes supported SQL operations, like filters and aggregations, directly to Anaplan and utilizes the embedded SQL engine to process unsupported operations client-side (often SQL functions and JOIN operations).

Connecting to Anaplan Data

Connecting to Anaplan data looks just like connecting to any relational data source. Create a connection string using the required connection properties. For this article, you will pass the connection string as a parameter to the create_engine function.

Authenticating to Anaplan

The driver supports authenticating with Basic, Certificate, or OAuth. In every case, set Region to the region where your Anaplan account data is hosted (e.g., US1, which is the default).

Using Basic Authentication

Set AuthScheme to Basic, then supply your Anaplan User and Password. If your workspace uses single sign-on (SSO), you must be assigned as an Exception User to use Basic authentication.

Using Certificate Authentication

Set AuthScheme to Certificate, then supply the Certificate, CertificateType, and PrivateKey properties (and the matching CertificatePassword / PrivateKeyPassword if either is encrypted). The certificate must be a CA-issued X.509 certificate registered with your Anaplan tenant administrator.

Using OAuth Authentication

Register a custom OAuth application in Anaplan, then set the following properties:

  • OAuthClientId: The client Id assigned when you registered your custom OAuth application.
  • OAuthClientSecret: The client secret assigned when you registered your custom OAuth application.
  • CallbackURL: The redirect URI defined when you registered your application.
  • InitiateOAuth: Set to GETANDREFRESH to have the driver manage the OAuth token exchange and refresh automatically.

See the Getting Started chapter of the help documentation for a guide to creating a custom OAuth app and using OAuth.

After installing the CData Anaplan Connector, follow the procedure below to install the other required modules and start accessing Anaplan through Python objects.

Install Required Modules

Use the pip utility to install the required modules and frameworks:

pip install petl
pip install pandas

Build an ETL App for Anaplan Data in Python

Once the required modules and frameworks are installed, we are ready to build our ETL app. Code snippets follow, but the full source code is available at the end of the article.

First, be sure to import the modules (including the CData Connector) with the following:

import petl as etl
import pandas as pd
import cdata.anaplan as mod

You can now connect with a connection string. Use the connect function for the CData Anaplan Connector to create a connection for working with Anaplan data.

cnxn = mod.connect("OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;CallbackURL=your_callback_url;Region=US1;InitiateOAuth=GETANDREFRESH;")

Create a SQL Statement to Query Anaplan

Use SQL to create a statement for querying Anaplan. In this article, we read data from the Sales entity.

sql = "SELECT Region, Product FROM Sales WHERE Value = '100'"

Extract, Transform, and Load the Anaplan Data

With the query results stored in a DataFrame, we can use petl to extract, transform, and load the Anaplan data. In this example, we extract Anaplan data, sort the data by the Product column, and load the data into a CSV file.

Loading Anaplan Data into a CSV File

table1 = etl.fromdb(cnxn,sql)

table2 = etl.sort(table1,'Product')

etl.tocsv(table2,'sales_data.csv')

With the CData Python Connector for Anaplan, you can work with Anaplan data just like you would with any database, including direct access to data in ETL packages like petl.

Free Trial & More Information

Download a free, 30-day trial of the CData Python Connector for Anaplan to start building Python apps and scripts with connectivity to Anaplan data. Reach out to our Support Team if you have any questions.



Full Source Code


import petl as etl
import pandas as pd
import cdata.anaplan as mod

cnxn = mod.connect("OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;CallbackURL=your_callback_url;Region=US1;InitiateOAuth=GETANDREFRESH;")

sql = "SELECT Region, Product FROM Sales WHERE Value = '100'"

table1 = etl.fromdb(cnxn,sql)

table2 = etl.sort(table1,'Product')

etl.tocsv(table2,'sales_data.csv')

Ready to get started?

Download a free trial of the Anaplan Connector to get started:

 Download Now

Learn more:

Anaplan Icon Anaplan Python Connector

Python Connector Libraries for Anaplan Data Connectivity. Integrate Anaplan with popular Python tools like Pandas, SQLAlchemy, Dash & petl.