After a significant amount of refactoring, I'm very pleased to announce the latest release of my Python package for the Anaplan Bulk API. This package simplifies interacting with the Anaplan Auth and Bulk APIs. It supports Basic and Certificate authentication, certificates can be used directly or within a Java Keystore file. It supports more robust logging and contains more detailed documentation for its use. This package is now available on GitHub and for download using pip.
Note: The package used to handle Java Keystore files appears to be an inactive project and contains a bug that may cause issues during installation. Details for working around these issues can be found in the Github and PyPi pages for the Anaplan API package.
Note:While all of these scripts have been tested and found to be fully functional, due to the vast amount of potential use cases, Anaplan does not explicitly support custom scripts built by our customers. This article is for information only and does not suggest any future product direction. This library is a work in progress and will be updated with new features once they have been tested.
The attached Python library serves as a wrapper for interacting with the Anaplan API. This article will explain how you can use the library to automate many of the requests that are available in our Apiary, which can be found athttps://anaplanbulkapi20.docs.apiary.io/#.
This article assumes you have the requests, cryptography, and pyjks modules installed, as well as Python 3.7 or later. Please make sure you are installing these modules with Python 3, and not for an older version of Python. For more information on these modules, please see their respective websites:
Python (If you are using a Python version older or newer than 3.7 we cannot guarantee the validity of the article)
This returns a data object which contains a list of the specified resource. You can simply treat it like a dictionary, passing in the resource name and the object will return the corresponding ID.
You can upload a file of any size, in chunks between 1-50mb. This upload can be both local files, or strings of data held in memory. The package will continue reading from the file/buffer in specified increments until all data is uploaded to your Anaplan model. Flat file:
with open('/path/to/file.csv', 'r') as current_csv:
data = current_csv.read()
anaplan.file_upload(conn=conn, file_id=files_list["Users.csv"], chunk_size=2, data=data)
In the above example, both use local files but demonstrate how you can pass the data in as a string or simply provide the path to the local file. Once the upload is complete, you can move on to running your import action(s).
You can run any Anaplan action with this script and define a number of times to retry the request if there's a problem. In order to execute an Anaplan action, the ID is required. To execute, all that is required is the following:
results = anaplan.execute_action(conn=conn, action_id="118000000007", retry_count=3)
#For Anaplan Processes
for item in results:
#For other Anaplan actions
Once the specified action is complete, an object with the overall task results, task details, the file download (if applicable), and error dump (if applicable) is returned. Error dumps are only available for import actions, and are returned in a Pandas DataFrame. If the action is an export, the file is automatically downloaded and available as a string.
Downloading a File
There is no longer a dedicated need to download files, as export actions automatically pull the specified file. However, if you wish to download a file from Anaplan, you may do so.
The content in this article has not been evaluated for all Anaplan implementations and may not be recommended for your specific situation.
Please consult your internal administrators prior to applying any of the ideas or steps in this article.