splunklib.data¶
The splunklib.data module reads the responses from splunkd in Atom Feed format, which is the format used by most of the REST API.
-
splunklib.data.
load
(text, match=None)¶ This function reads a string that contains the XML of an Atom Feed, then returns the data in a native Python structure (a
dict
orlist
). If you also provide a tag name or path to match, only the matching sub-elements are loaded.Parameters: - text (
string
) – The XML text to load. - match (
string
) – A tag name or path to match (optional).
- text (
-
splunklib.data.
record
(value=None)¶ This function returns a
Record
instance constructed with an initial value that you provide.Parameters: value ( dict
) – An initial record value.
-
class
splunklib.data.
Record
¶ This generic utility class enables dot access to members of a Python dictionary.
Any key that is also a valid Python identifier can be retrieved as a field. So, for an instance of
Record
calledr
,r.key
is equivalent tor['key']
. A key such asinvalid-key
orinvalid.key
cannot be retrieved as a field, because-
and.
are not allowed in identifiers.Keys of the form
a.b.c
are very natural to write in Python as fields. If a group of keys shares a prefix ending in.
, you can retrieve keys as a nested dictionary by calling only the prefix. For example, ifr
contains keys'foo'
,'bar.baz'
, and'bar.qux'
,r.bar
returns a record with the keysbaz
andqux
. If a key contains multiple.
, each one is placed into a nested dictionary, so you can writer.bar.qux
orr['bar.qux']
interchangeably.