Splunk Dev

Splunk search head's python library Vs Python 3.8

vamsigurram
Path Finder

Hi,

From the below github link, I see this python code, which works on the search head(linux), when I use this command.

/opt/splunk/bin/splunk cmd python ko_change.py

https://github.com/harsmarvania57/splunk-ko-change/blob/master/ko_change.py

I see below import statements.

import splunk.rest as rest
import splunk.auth as auth

When I use these, import statements, in my laptop, vscode, it get below error.

"ModuleNotFoundError: No Module named "splunk.auth";  'splunk' is not a package"

"ModuleNotFoundError: No Module named "splunk.rest";  'splunk' is not a package"

I have splunk-sdk installed in my vscode. splunklib is working.

So the question here is, how come the above import statements work on splunk search head(Linux) , but not in vscode (in my laptop), even when I have splunk-sdk installed?

What library, do I need to install, to make splunk.auth and splunk.rest work in vscode (on my windows laptop)

 

Labels (3)
0 Karma
1 Solution

harsmarvania57
Ultra Champion

Hi,

I am developer/owner of that script and that script only works with Splunk Enterprise, you can't use that script with Splunk Python SDK.

Thanks,

Harshil

View solution in original post

0 Karma

harsmarvania57
Ultra Champion

Hi,

I am developer/owner of that script and that script only works with Splunk Enterprise, you can't use that script with Splunk Python SDK.

Thanks,

Harshil

0 Karma

inventsekar
SplunkTrust
SplunkTrust

Hi @vamsigurram .. got a curious question.. when this works on Search Head, why you want to run this on laptop?!

just for learning!

thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !
0 Karma

vamsigurram
Path Finder

@inventsekar Yes, its for learning more on splunk.rest.

But as @harsmarvania57 mentioned, its a bummer why splunk-sdk does not have those libraries.

Now I have to code directly in linux (without vscode)

0 Karma

inventsekar
SplunkTrust
SplunkTrust

(oops, i had assumed that you have installed splunk on your laptop, my bad!)

... soo, on your laptop, you installed only  the "splunk-sdk" and tried to run that github file!!!

 

"the splunk-sdk always needs the Splunk, at its base"(as per my understanding).

thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !
0 Karma

harsmarvania57
Ultra Champion

You can use vscode but you need to install Splunk Enterprise on your desktop.

0 Karma

vamsigurram
Path Finder

Good idea.

I will try that. Thanks again for your help.

0 Karma

thambisetty
SplunkTrust
SplunkTrust

@vamsigurram 

Below is the location where you will find splunk python modules.

$SPLUNK_HOME/lib/python2.7/site-packages/splunk

$SPLUNK_HOME/lib/python3.7/site-packages/splunk

 

————————————
If this helps, give a like below.
0 Karma

thambisetty
SplunkTrust
SplunkTrust

@harsmarvania57 

————————————
If this helps, give a like below.
0 Karma
Get Updates on the Splunk Community!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Enhance Security Operations with Automated Threat Analysis in the Splunk EcosystemAre you leveraging ...

Splunk Developers: Go Beyond the Dashboard with These .Conf25 Sessions

  Whether you’re building custom apps, diving into SPL2, or integrating AI and machine learning into your ...

Index This | How do you write 23 only using the number 2?

July 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...