Reuse transformation code with transformation libraries.
RudderStack’s transformation libraries feature lets you reuse the same code in multiple transformations.
RudderStack now supports writing transformation libraries in Python for the RudderStack Cloud Growth and Enterprise plans.
Add transformation library
In the RudderStack dashboard, go to Collect > Transformations and click the Libraries tab. Then, click Create Library.
Add the library Name, Description and select the language to write the library function. You can also add multiple functions in a single library.
RudderStack supports Python libraries only in the RudderStack Cloud Growth and Enterprise plans.
Click Run Test to ensure the library code has the correct syntax. A Test Passed message pops up once the test runs successfully.
Use libraries in transformations
RudderStack provides some default libraries that you can import in your transformations for implementing various use cases like encrypting, decrypting, or hashing PII, parsing user agent, and using the localized version of Apple’s device mode information in your events.
To use the libraries in your existing transformations, note the library name listed in the Import library name column in the RudderStack dashboard:
RudderStack converts the library name into camel case without spaces; this becomes your library handle which you can use across multiple transformations. For example, if your library name is Sample Transformation Library, then the library handle would be sampleTransformationLibrary.
You can then use the library in a transformation with a simple import statement. Refer to the below use case for more information.
Suppose you want to filter the events that don’t contain an email address with the RudderStack domain. To do so, you can import a rudderEmail function from the transformation library isRudderEmail.
The rudderEmail function containing the filtering logic is shown below:
You cannot delete a library that is referenced or imported in a transformation.
To delete a library, go to Collect > Transformations > Libraries and click the Delete button next to the library that you want to delete.
Default RudderStack libraries
By default, RudderStack provides four predefined libraries which you can directly import into your transformations. Refer to the GitHub codebase for the code and implementation-specific details for these libraries.
Use the following structure to import the Rudderstack libraries:
A sample import statement is shown below:
The following table lists the default RudderStack libraries and their usage:
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
for the working of basic functionalities of the website. We also use third-party cookies that
analyze and understand how you use this website. These cookies will be stored in your browser
consent. You also have the option to opt-out of these cookies. But opting out of some of these
have an effect on your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.