Skip to content

Commit 2c1d6ef

Browse files
committed
Another README refactor
1 parent ff22dcc commit 2c1d6ef

File tree

1 file changed

+78
-74
lines changed

1 file changed

+78
-74
lines changed

README.md

Lines changed: 78 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,46 @@
33
[![Build Status](https://github.com/splunk/splunk-sdk-python/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/splunk/splunk-sdk-python/actions/workflows/test.yml)
44
![License](https://img.shields.io/badge/license-Apache%202.0-informational.svg)
55

6-
The Splunk Enterprise Software Development Kit (SDK) for Python contains library code designed to enable developers to build applications using the Splunk platform.
6+
The [Splunk Enterprise](https://www.splunk.com/en_us/products/splunk-enterprise.html) Software Development Kit (SDK) for Python is intended to be the primary way for developers to communicate with the Splunk platform's REST API.
77

8-
Splunk is a search engine and analytic environment that uses a distributed map-reduce architecture to efficiently index, search, and process large time-varying data sets.
8+
You may be asking:
9+
10+
- [What are Splunk apps?](https://help.splunk.com/en/splunk-enterprise/administer/admin-manual/10.0/meet-splunk-apps/apps-and-add-ons)
11+
- [What can Splunk apps do?](https://dev.splunk.com/enterprise/docs/developapps/extensionpoints)
12+
- [How do I write Splunk apps?](https://dev.splunk.com/enterprise/docs/welcome)
13+
- [Where does the SDK fit in all this?](https://dev.splunk.com/enterprise/docs/devtools/python/sdk-python/)
914

1015
## Getting started
1116

1217
### Requirements
1318

14-
#### Python compatibility
19+
#### Python
1520

16-
Splunk Enterprise SDK for Python is tested only with Python 3.7, 3.9 and 3.13. Latest version is always recommended.
21+
Please use the latest Python version supported when developing. Splunk Enterprise SDK for Python is tested with Python 3.9 and 3.13.
1722

1823
#### Splunk Enterprise
1924

20-
This SDK is only tested with Splunk versions supported in the [Splunk Software Support Policy](https://www.splunk.com/en_us/legal/splunk-software-support-policy.html)
25+
This SDK is only tested with Splunk Enterprise versions supported in the [Splunk Software Support Policy](https://www.splunk.com/en_us/legal/splunk-software-support-policy.html).
2126

2227
[Go here](http://www.splunk.com/download) to get Splunk Enterprise.
2328

24-
For more information, see the Splunk Enterprise [Installation Manual](https://docs.splunk.com/Documentation/Splunk/latest/Installation).
25-
2629
### Installing the SDK
2730

28-
Using `pip` is the easiest way to pull the SDK into your project. `poetry` and `uv` should work just as well.
31+
Using `pip` is the easiest way to pull the SDK into your project. `poetry` and `uv` should work just as well. A project-specific virtualenv is recommended.
2932

30-
A project-specific virtualenv is recommended.
33+
In your app's project folder:
3134

3235
```sh
33-
python -m venv .venv
34-
source .venv/bin/activate
35-
python -m pip install splunk-sdk
36+
$ python -m venv .venv
37+
$ source .venv/bin/activate
38+
# Bundle all your dependencies into `bin/` before deploying!
39+
# Skip it if you're not building an app.
40+
$ python -m pip install splunk-sdk --target bin/
3641
```
3742

38-
[See docs](https://dev.splunk.com/enterprise/docs/developapps/createapps/appanatomy/) for how to package additional dependencies with your app.
39-
40-
#### Optional: Create an `.env` file
43+
[See docs](https://dev.splunk.com/enterprise/docs/developapps/createapps/appanatomy/) on more details about packaging additional dependencies with your app.
4144

42-
To connect to Splunk Enterprise, many of the SDK examples and unit tests take command-line arguments that specify values for the host, port, and authentication. For convenience during development, you can store these arguments as key-value pairs in a `.env` file.
43-
44-
A file called `.env.template` exists in the root of this repository. Duplicate it as `.env`, then adjust it to your match your environment.
45-
46-
> **WARNING:** The `.env` file isn't part of the Splunk platform. This is **not** the place for production credentials!
47-
48-
### SDK usage examples
45+
### Using SDK in apps
4946

5047
The easiest and most effective way of learning how to use this library should be reading through the apps in our test suite, as well as the [splunk-app-examples](https://github.com/splunk/splunk-app-examples) repository. They show how to programmatically interact with the Splunk platform in a variety of scenarios - from basic metadata retrieval, one-shot searching and managing saved searches to building complete applications with modular inputs and custom search commands.
5148

@@ -77,10 +74,30 @@ import splunklib.client as client
7774
service = client.connect(host=<HOST_URL>, token=<SESSION_KEY>, autologin=True)
7875
```
7976

80-
### Customization
77+
#### Creating Custom Search Commands
78+
79+
TODO: Link docs about this
80+
81+
##### Accessing instance metadata in CSCs
82+
83+
- The `service` metadata object is created from the `splunkd` URI and session key passed to the command invocation the search results info file and is available in `MyCommand`.`generate`/`transform`/`stream`/`reduce` methods depending on the Custom Search Command.
84+
85+
```python
86+
from splunklib.searchcommands import StreamingCommand
87+
88+
class MyCommand(StreamingCommand):
89+
def get_metadata(self):
90+
# Access instance metadata
91+
service = self.service
92+
# Access Splunk service info
93+
info = service.info
94+
# [...]
95+
```
96+
97+
##### Field retention in CSC
8198

8299
When working with custom search commands such as Custom Streaming Commands or Custom Generating Commands, we may need to add new fields to the records based on certain conditions. Structural changes like this may not be preserved.
83-
If you're having issues with field retention, make sure to use `add_field(record, fieldname, value)` method from SearchCommand to add a new field and value to the record.
100+
If you're having issues with field retention, make sure to use `add_field(record, fieldname, value)` method from `SearchCommand` to add a new field and value to the record.
84101

85102
```diff
86103
class CustomStreamingCommand(StreamingCommand):
@@ -92,10 +109,10 @@ class CustomStreamingCommand(StreamingCommand):
92109
yield record
93110
```
94111

95-
### Customization for Generating Custom Search Command
112+
##### Using a helper method to generate events properly
96113

97114
- Generating Custom Search Command is used to generate events using SDK code.
98-
- Make sure to use `gen_record()` method from SearchCommand to add a new record and pass event data as comma-separated key=value pairs (mentioned in below example).
115+
- Make sure to use `gen_record()` method from `SearchCommand` to add a new record and pass event data as comma-separated key=value pairs (mentioned in below example).
99116

100117
```diff
101118
@Configuration()
@@ -108,9 +125,29 @@ class GeneratorTest(GeneratingCommand):
108125

109126
```
110127

111-
### Access metadata of Modular Inputs app example
128+
#### Modular Inputs Example App
129+
130+
[Go here](https://help.splunk.com/en/splunk-enterprise/developing-views-and-apps-for-splunk-web/10.0/modular-inputs/modular-inputs-basic-example) to find out more about setting up a Modular Input.
131+
132+
#### Accessing instance metadata in scripts
133+
134+
- The `service` metadata object is created from the `splunkd` URI and session key passed to the command invocation on the modular input stream respectively, and is available as soon as the `<script_name>.stream_events()` method is called.
135+
136+
```python
137+
from splunklib.modularinput import Script
138+
139+
class MyScript(Script):
140+
def stream_events(self, inputs, ew):
141+
# Access instance metadata
142+
service = self.service
143+
# Access Splunk service info
144+
info = service.info
145+
# [...]
146+
```
112147

113-
- In `stream_events()` one can access modular input app metadata from `InputDefinition` object
148+
#### Accessing Modular Inputs' metadata
149+
150+
- In `stream_events()` you can access Modular Input app metadata from `InputDefinition` object
114151
- See the [Modular Input App example](https://github.com/splunk/splunk-app-examples/blob/master/modularinputs/python/github_commits/bin/github_commits.py) for reference.
115152

116153
```python
@@ -123,43 +160,22 @@ class GeneratorTest(GeneratingCommand):
123160
checkpoint_dir = inputs.metadata["checkpoint_dir"]
124161
```
125162

126-
### Access `service` object in Custom Search Command & Modular Input apps
127-
128-
#### Custom Search Commands
129-
130-
- The `service` metadata object is created from the `splunkd` URI and session key passed to the command invocation the search results info file and is available in `MyCommand`.`generate`/`transform`/`stream`/`reduce` methods depending on the Custom Search Command.
131-
132-
```python
133-
from splunklib.searchcommands import StreamingCommand
163+
### Contributions
134164

135-
class MyCommand(StreamingCommand):
136-
def get_metadata(self):
137-
# Access instance metadata
138-
service = self.service
139-
# Access Splunk service info
140-
info = service.info
141-
# [...]
142-
```
165+
We welcome all contributions!
166+
If you would like to contribute to the SDK, see [Contributing to Splunk](https://www.splunk.com/en_us/form/contributions.html). For additional guidelines, see [CONTRIBUTING](CONTRIBUTING.md).
143167

144-
#### Modular Inputs app
168+
#### Testing
145169

146-
- The `service` metadata object is created from the `splunkd` URI and session key passed to the command invocation on the modular input stream respectively, and is available as soon as the `MyScript.stream_events` method is called.
170+
This repository contains both unit and integration tests. The latter need `docker`/`podman` to work.
147171

148-
```python
149-
from splunklib.modularinput import Script
172+
##### Create an `.env` file
150173

151-
class MyScript(Script):
152-
def stream_events(self, inputs, ew):
153-
# Access instance metadata
154-
service = self.service
155-
# Access Splunk service info
156-
info = service.info
157-
# [...]
158-
```
174+
To connect to Splunk Enterprise, many of the SDK examples and unit tests take command-line arguments that specify values for the host, port, and authentication. For convenience during development, you can store these arguments as key-value pairs in a `.env` file.
159175

160-
### Testing
176+
A file called `.env.template` exists in the root of this repository. Duplicate it as `.env`, then adjust it to your match your environment.
161177

162-
This repo contains both unit and integration tests. The latter need `docker`/`podman` to work.
178+
> **WARNING:** The `.env` file isn't part of the Splunk platform. This is **not** the place for production credentials!
163179
164180
```sh
165181
# Run entire test suite:
@@ -168,12 +184,13 @@ make test
168184
make test-unit
169185
```
170186

171-
#### Integration tests
187+
##### Integration tests
172188

173189
> NOTE: Before running the integration tests, make sure the instance of Splunk you are testing against doesn't have new events being dumped continuously into it. Several of the tests rely on a stable event count. It's best to test against a clean install of Splunk but if you can't, you should at least disable the \*NIX and Windows apps.
174190
175191
```sh
176-
# Make sure a local Splunk instance is running
192+
# This command starts a Splunk Docker container
193+
# and waits until it reaches an operational state.
177194
SPLUNK_VERSION=latest make docker-start
178195

179196
# Run the integration tests:
@@ -182,7 +199,7 @@ make test-integration
182199

183200
> Do not run the test suite against a production instance of Splunk! It will run just fine with the free Splunk license.
184201
185-
### Optional: Set up logging for splunklib
202+
### Setting up logging for splunklib
186203

187204
The default level is WARNING, which means that only events of this level and above will be visible
188205
To change a logging level we can call setup_logging() method and pass the logging level as an argument.
@@ -197,14 +214,6 @@ from splunklib import setup_logging
197214
setup_logging(logging.DEBUG)
198215
```
199216

200-
### Changelog
201-
202-
The [CHANGELOG](CHANGELOG.md) contains a description of changes for each version of the SDK. For the latest version, see the [CHANGELOG.md](https://github.com/splunk/splunk-sdk-python/blob/master/CHANGELOG.md) on GitHub.
203-
204-
### Branches
205-
206-
To learn more about our branching model, see [Branching Model](https://github.com/splunk/splunk-sdk-python/wiki/Branching-Model) on GitHub.
207-
208217
## Documentation and resources
209218

210219
| Resource | Description |
@@ -226,11 +235,6 @@ Stay connected with other developers building on the Splunk platform.
226235
- [Community Slack](https://splunk-usergroups.slack.com/app_redirect?channel=appdev)
227236
- [Splunk Answers](https://community.splunk.com/t5/Splunk-Development/ct-p/developer-tools)
228237

229-
### Contributions
230-
231-
We welcome all contributions!
232-
If you would like to contribute to the SDK, see [Contributing to Splunk](https://www.splunk.com/en_us/form/contributions.html). For additional guidelines, see [CONTRIBUTING](CONTRIBUTING.md).
233-
234238
### Support
235239

236240
- You will be granted support if you or your company are already covered under an existing maintenance/support agreement. Submit a new case in the [Support Portal](https://www.splunk.com/en_us/support-and-services.html) and include `Splunk Enterprise SDK for Python` in the subject line.

0 commit comments

Comments
 (0)