There was a significant change in how Python code node works in version 1.111.0 - a switch from Python (Pyodide - legacy) to Python (Native - beta) runtime.
For more info see the docs here Code node documentation | n8n Docs
Tried to import some modules on version 1.120.4 hosted by n8n in a Cloud and got this:
- Worked:
re , zlib, base64 and json.
- Didn’t work:
bs(ModuleNotFoundError: No module named ‘bs’)
Unfortunately I didn’t find official list of modules, which are natively supported by current Python (Native - beta) in the Cloud, so I tried running below code:
import sys
import pkgutil
modules = sorted([module.name for module in pkgutil.iter_modules()])
return [{"modules": modules}]
and got:
[
"__future__",
"__hello__",
"__phello__",
"_android_support",
"_apple_support",
"_collections_abc",
"_colorize",
"_compat_pickle",
"_compression",
"_ios_support",
"_markupbase",
"_opcode_metadata",
"_py_abc",
"_pydatetime",
"_pyio",
"_pylong",
"_pyodide",
"_pyrepl",
"_sitebuiltins",
"_strptime",
"_sysconfigdata__emscripten_wasm32-emscripten",
"_threading_local",
"_weakrefset",
"abc",
"antigravity",
"argparse",
"ast",
"asyncio",
"base64",
"bdb",
"bisect",
"bz2",
"cProfile",
"calendar",
"cmd",
"code",
"codecs",
"codeop",
"collections",
"colorsys",
"compileall",
"concurrent",
"configparser",
"contextlib",
"contextvars",
"copy",
"copyreg",
"csv",
"ctypes",
"dataclasses",
"datetime",
"decimal",
"difflib",
"dis",
"doctest",
"email",
"encodings",
"enum",
"filecmp",
"fileinput",
"fnmatch",
"fractions",
"ftplib",
"functools",
"genericpath",
"getopt",
"getpass",
"gettext",
"glob",
"graphlib",
"gzip",
"hashlib",
"heapq",
"hmac",
"html",
"http",
"imaplib",
"importlib",
"inspect",
"io",
"ipaddress",
"json",
"keyword",
"linecache",
"locale",
"logging",
"mailbox",
"mimetypes",
"modulefinder",
"multiprocessing",
"netrc",
"ntpath",
"nturl2path",
"numbers",
"opcode",
"operator",
"optparse",
"os",
"pathlib",
"pdb",
"pickle",
"pickletools",
"pkgutil",
"platform",
"plistlib",
"poplib",
"posixpath",
"pprint",
"profile",
"pstats",
"pty",
"py_compile",
"pyclbr",
"pydoc",
"pyodide",
"queue",
"quopri",
"random",
"re",
"reprlib",
"rlcompleter",
"runpy",
"sched",
"secrets",
"selectors",
"shelve",
"shlex",
"shutil",
"signal",
"site",
"smtplib",
"socket",
"socketserver",
"sre_compile",
"sre_constants",
"sre_parse",
"stat",
"statistics",
"string",
"stringprep",
"struct",
"subprocess",
"symtable",
"sysconfig",
"tabnanny",
"tarfile",
"tempfile",
"textwrap",
"this",
"threading",
"timeit",
"token",
"tokenize",
"tomllib",
"trace",
"traceback",
"tracemalloc",
"tty",
"types",
"typing",
"unittest",
"urllib",
"uuid",
"warnings",
"wave",
"weakref",
"webbrowser",
"wsgiref",
"xml",
"xmlrpc",
"zipapp",
"zipfile",
"zipimport",
"zoneinfo"
]
However this does not list all the modules for some reason. For example zlib is not there, but can be imported.