How splunk/splunk-sdk-python works
Project type and purpose
• This is an open-source SDK library (“Splunk Enterprise SDK for Python”) rather than a standalone application.
• Its purpose is to provide Python modules that developers can import into their own apps to connect to, index, search, and interact programmatically with a Splunk Enterprise instance via the Splunk REST API (and modular input and custom search command frameworks).
File structure
• Top-level artifacts:
– splunklib/ ← core SDK modules (client, binding, data, modularinput, searchcommands, utils)
– docs/ ← Sphinx documentation source and build scripts
– tests/ ← PyTest/unittest test suites (unit tests, integration tests, data fixtures)
– scripts/ ← helper scripts for environment setup and test orchestration
– docker-compose.yml ← spins up a Splunk Enterprise container for integration tests
– Makefile ← targets to build, test, and tear down local Docker Splunk instance
– setup.py, MANIFEST.in, .env, CI workflows
• Key patterns:
– Modular separation of SDK functionality into sub-packages
– Standard Python project layout with source, docs, tests, utilities
– CI integration (GitHub Actions, tox, pytest) and Docker-based integration testing
README for additional insights
• Confirms the Python versions supported, Splunk versions targeted, usage examples for connecting via username/password, tokens, session keys
• Highlights extensibility points: custom search commands (StreamingCommand, GeneratingCommand), modular inputs (InputDefinition), and the service object for API calls
• Describes developer workflows: adding fields, generating records, setting up logging
a. Developer Application Layer
– Your Python application imports splunklib.client, splunklib.searchcommands, etc.
– It calls client.connect(...) to obtain a Service object.
b. Splunk SDK Core (splunklib)
– binding.py: HTTP/REST call construction & response parsing
– client.py: high-level Service and namespace abstractions
– data.py, results.py: wrappers for indexed/search results
– modularinput/: classes for building custom modular inputs and streaming events
– searchcommands/: base classes & decorators for custom search commands (streaming, generating, reporting, eventing)
– utils.py: shared helpers
c. External Splunk Enterprise Service
– Exposes REST endpoints on port 8089 (configured via .env/docker-compose)
– The SDK’s REST calls flow over HTTPS/TCP to this service
d. Test & CI Infrastructure
– docker-compose.yml spins up a Splunk container
– pytest + Makefile orchestrate integration tests against the running container
– GitHub Actions workflows invoke make test, lint, release
Architectural patterns & design principles
• Modular package structure for single-responsibility (client, binding, commands, inputs)
• Adapter/wrapper pattern around Splunk’s REST API
• Extension points via abstract base classes (StreamingCommand, GeneratingCommand, Script)
• Separation between core library and examples/tests
Elements
• Clear labels for each component: Developer App, each splunklib module, Splunk Enterprise Service, Test Harness
• Developer App → splunklib.client → splunklib.binding → Splunk REST API
• Developer App → splunklib.searchcommands → Splunk command framework
• CI Pipeline → Docker Compose → Splunk Container ← Test Runner
• External systems (Splunk Enterprise container) in another (e.g., green)
• CI/Test components in a third (e.g., orange)
Detailed capture of essential elements
• Don’t omit the modularinput and searchcommands sub-packages—they are key extension points
• How the .env file and docker-compose.yml configure host, port, credentials for local tests
• Sphinx docs pipeline (docs/ → HTML) as a peripheral component
• CI workflows (GitHub Actions → pytest/tox → coverage reports)