Zachary Oldham
Zachary Oldham

Reputation: 868

Using Third Party Libraries in Snaplogic Script Snap

I am attempting to create a python script using the script snap to issue a batch request to a Cassandra cluster (the Cassandra script does not support batch operations for some reason), and I need a way to use the 'cassandra' library

I have looked through the documentation for a way to import python libraries that are not default things like random, but I can find no way to do this.

The specific import lines I am using are

from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider

But this obviously does not work because the Cassandra library for python is not installed on SnapLogic. I have no ability (AFAIK) to install libraries on SnapLogic. The specific error I get in case it is relevant is:

Failure: Cannot evaluate Script file: SQL_Demo_Cassandra_Script.py, Reason: ImportError: No module named cassandra in at line number 5, Resolution: Please fix the script file error at line: 5 column: -1

Upvotes: 3

Views: 1179

Answers (1)

Bilesh Ganguly
Bilesh Ganguly

Reputation: 4131

When you select Python in the Script snap it actually means Jython. So, you can, basically, import Java classes in your script.

So, you would need to get the driver (a JAR file) for Cassandra and upload it to all of the plex nodes and make sure to save it in the same path on all nodes.

Then you can add the JAR file to the path in the script and import the required classes.

Note: I have never tried it in SnapLogic.

Please refer to the StackOverflow question - Importing jars from Jython


Update #1:

Looks like this is the recommended way of using third party libraries.

From SnapLogic Docs:

While SnapLogic does not support importing third party libraries directly using the Script Snap, you can add their package/JAR files in a directory in your Groundplex nodes and then import them using this Snap.

For example, consider that you have added the JAR file, sample.jar, in the directory /opt/snaplogic/ext_jar/. Include the following statements in the script that you are running in the Script Snap to import this library:

import sys
# more code
sys.path.append('/opt/snaplogic/ext_jar/sample.jar')
# more code

Restrictions:

  • If you are using multiple Groundplex nodes then you must add the package/JAR files in each of those nodes.
  • You can import third party libraries only on Groundplex nodes.

Refer to - SnapLogic Docs - Script Snap

Upvotes: 2

Related Questions