Help

Re: Importing libraries

Solved
Jump to Solution
3036 1
cancel
Showing results for 
Search instead for 
Did you mean: 
D_A_VFX
5 - Automation Enthusiast
5 - Automation Enthusiast

I have a task that requires itertools. but I am having no luck. is it possible to import from itertools? or any other library for that matter? thanks

1 Solution

Accepted Solutions
kuovonne
18 - Pluto
18 - Pluto

You cannot import libraries in Scripting app.

You can copy/paste in minified versions of libraries into your script if they are small enough and in a single file.

There are also creative ways of having the script itself get raw library files and use eval.

Or you can write a custom app, which can import node modules.

See Solution in Thread

7 Replies 7
kuovonne
18 - Pluto
18 - Pluto

You cannot import libraries in Scripting app.

You can copy/paste in minified versions of libraries into your script if they are small enough and in a single file.

There are also creative ways of having the script itself get raw library files and use eval.

Or you can write a custom app, which can import node modules.

like this one

Many thanks to @Bill.French and @Jeremy_Oglesby !

oLπ

I personally don’t like storing libraries in tables where users who don’t know any better can do unexpected things with them.

An alternative is to get the library from a cdn. This method is slightly better because base users can’t mess with the library. However, keep in mind that every time you use eval you have to really trust the source.

This example gets the mathjs library from a cdn. It isn’t very useful since you can use use Math out of the box, but in theory it should work with other libraries.

Plus, it looks like you can’t use eval in automation scripts.

await getMathJs()
async function getMathJs() {
  const response = await fetch("https://cdnjs.cloudflare.com/ajax/libs/mathjs/7.5.1/math.min.js");
  const minifiedLibrary= await response.text();
  eval(minifiedLibrary)
}

let answer = math.round(math.e, 3)
output.inspect(answer)

answer = math.round(math.pi, 15)
output.inspect(answer)

I have used eval() in the past without issue.

I doubt this would work in any case because eval() would likely trip over anything minified. Try …

eval('0 == 1')

Pretty sure it should work.

eval won’t work for me in an automation action script. I get an error saying that it is not defined.

image

Why wouldn’t eval() work on something minified? Minified code is still valid code. The code that I posted works for me in scripting app.

Good to know - so this is simply an issue with script actions I guess. That’s unfortunate - there should be no limitation on eval; importing libraries is a different animal.

Hi kuovonne!

Thank you for this technique=)

I'm trying to use it to import some functions from a file I have stored in Github, but I get a "not defined" error when I call the functions in the Airtable script. Any idea why?

I've already checked the fetch is working fine and also tried with a simple example succesfully, but no luck with the complete set of functions.