Splunk Dev

Adding external library to custom app

tmontney
Builder

I would like to use https://pypi.org/project/keyring/ in my custom app. I've been able to do it on Linux but unable to on Windows.

I need pip to install it. I tried calling python from the Splunk provided one, but it won't work. I ended up installing the latest Python on my server to pull it. Even when installed and I install keyring, it can't be found. I've tried using sys.path.append but has not helped. I've tried placing the downloaded package (from C:\Users\{username}\AppData\Local\Programs\Python\Python39\Lib\site-packages) in my bin folder.

When I run splunk cmd python myscript.py, I get

Traceback (most recent call last):
File "C:\Program Files\Splunk\etc\apps\customapp1\bin\myscript.py", line 10, in <module>
import keyring
File "C:\Program Files\Splunk\etc\apps\customapp1\bin\keyring\__init__.py", line 1, in <module>
from .core import (
File "C:\Program Files\Splunk\etc\apps\customapp1\bin\keyring\core.py", line 10, in <module>
from . import backend
File "C:\Program Files\Splunk\etc\apps\customapp1\bin\keyring\backend.py", line 42
class KeyringBackend(metaclass=KeyringBackendMeta):
^
SyntaxError: invalid syntax

I'll also note that splunk cmd python myscript.py only works if I specify the scripts full path. (This has no trouble on my Linux one.) Otherwise, I get python: can't open file 'myscript.py': [Errno 2] No such file or directory. I have a Windows environment variable named "SPLUNK_HOME" set to "C:\Program Files\Splunk".

Labels (2)
0 Karma
Get Updates on the Splunk Community!

Splunk Classroom Chronicles: Training Tales and Testimonials (Episode 3)

Welcome back to Splunk Classroom Chronicles, our ongoing blog series that pulls back the curtain on Splunk ...

Operationalizing TDIR: Building a More Resilient, Scalable SOC

Optimizing SOC workflows with a unified, risk-based approach to Threat Detection, Investigation, and Response ...

Almost Too Eventful Assurance: Part 1

Modern IT and Network teams still struggle with too many alerts and isolating issues before they are notified. ...