Building for the Splunk Platform

"ModuleNotFoundError: No module named 'sn_sec_util'" error on loading python custom module


I have created a custom python script named "" in the bin folder of the splunk app. I want to load this file in the python REST handler "" which is also in the bin folder.

But I am facing the issue at the import statement mentioning "ModuleNotFoundError: No module named 'sn_sec_util".

Here is the file "" with import statement of the module "" in the line 4.

import sys
import splunk
import logging, logging.handlers
import sn_sec_util as snutil
from urllib.parse import unquote

class Submit(

    def handle_submit(self):
         payload = self.request['payload']
         sessionKey = self.sessionKey
    handle_POST = handle_submit 
Labels (2)
0 Karma

Splunk Employee
Splunk Employee

Hey gsabhay77,

Your ability to import other modules will depend on your PYTHONPATH which is specific to your system where Splunk is running. The easiest way to debug the path that the script is running from is to output sys.path:

import sys
print(sys.path) // ['', '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8', ...]

Without getting too much into your system setup if you simply need the directory that your file resides in to be added to the path you could do so by adding the current absolute path that the file is running from using:

import os
import sys


Adding those lines to the top of your script should hopefully resolve your issue.

0 Karma
Get Updates on the Splunk Community!

Build Scalable Security While Moving to Cloud - Guide From Clayton Homes

 Clayton Homes faced the increased challenge of strengthening their security posture as they went through ...

Mission Control | Explore the latest release of Splunk Mission Control (2.3)

We’re happy to announce the release of Mission Control 2.3 which includes several new and exciting features ...

Cloud Platform | Migrating your Splunk Cloud deployment to Python 3.7

Python 2.7, the last release of Python 2, reached End of Life back on January 1, 2020. As part of our larger ...