Skip to main content
Question

Cognite functions

  • April 4, 2025
  • 1 reply
  • 18 views

Forum|alt.badge.img

Hi team, I want to import some functions from util folder which is same directory of the folder in which handler.py. As files in util folder is being used by other cognite functions too, I can’t keep the files of util folder in function_folder but at the time of importing functions from files of util folder and after deploying cognite function it gives import error as 
 

so basically structure is 
Repo
function_folder- file1 and handler.py
util_folder - file2 and file 3 
And I want to use methods from file 2 into handler.py 
and I have added __init__.py in util folder 

2025-04-04T12:17+05:30 : Traceback (most recent call last): 2025-04-04T12:17+05:30 : File "/home/site/wwwroot/function/_cognite_function_entry_point.py", line 297, in import_user_module 2025-04-04T12:17+05:30 : handler = importlib.import_module(handler_module_path) 2025-04-04T12:17+05:30 : File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module 2025-04-04T12:17+05:30 : return _bootstrap._gcd_import(name[level:], package, level) 2025-04-04T12:17+05:30 : File "<frozen importlib._bootstrap>", line 1030, in _gcd_import 2025-04-04T12:17+05:30 : File "<frozen importlib._bootstrap>", line 1007, in _find_and_load 2025-04-04T12:17+05:30 : File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked 2025-04-04T12:17+05:30 : File "<frozen importlib._bootstrap>", line 680, in _load_unlocked 2025-04-04T12:17+05:30 : File "<frozen importlib._bootstrap_external>", line 850, in exec_module 2025-04-04T12:17+05:30 : File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed 2025-04-04T12:17+05:30 : File "/home/site/wwwroot/function/handler.py", line 5, in <module> 2025-04-04T12:17+05:30 : from utils.get_cognite_client import get_cdf_client 2025-04-04T12:17+05:30 : ModuleNotFoundError: No module named 'utils'
Please let me know if I am missing something

Hi ​@Shweta .

My understanding is that you have folders “util_folder” and “function_folder” in your repository, where the latter is the one that contains handler.py and which is zipped and uploaded to CDF. If so, this will not work, since the “util_folder” and its contents are not part of the zip-file of the Cognite Function. Hence, when the function is executed in CDF, it does not have the files in “util_folder”. The “util_folder” needs to be part of the zip-file of the Cognite Function.


Reply


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings