Storm Libraries

Storm Libraries represent powerful tools available inside of the Storm query language.

$lib

The Base Storm Library. This mainly contains utility functionality.

$lib.cast(name, valu)

Normalize a value as a Synapse Data Model Type.

Args:
name (str): The name of the model type to normalize the value as. valu: The value to normalize.
Returns:
A object representing the normalized value.

$lib.dict(**kwargs)

Get a Storm Dict object.

Args:
**kwargs: An initial set of keyword arguments to place in the Dict.
Returns:
Dict: A Storm Dict object.

$lib.exit()

No doc for lib.exit

$lib.false

This constant represents a value of True that can be used in Storm. It is not called like a function, it can be directly used.

Examples:

Conditionally print a statement based on the constant value:

cli> storm if $lib.false { $lib.print('Is True') } else { $lib.print('Is False') }
Is False

$lib.fire(name, **info)

Fire an event onto the runtime.

Args:

name: The type of the event to fire.

**info: Additional keyword arguments containing data to add to the event.

Notes:
This fires events as storm:fire event types. The name of the event is placed into a type key, and any additional keyword arguments are added to a dictionary under the data key.
Examples:

Fire an event called demo with some data:

cli> storm $foo='bar' $lib.fire('demo', foo=$foo, knight='ni')
...
('storm:fire', {'type': 'demo', 'data': {'foo': 'bar', 'knight': 'ni'}})
...
Returns:
None: Returns None

$lib.guid(*args)

Get a random guid, or generate a guid from the arguments.

Args:
*args: Arguments which are hashed to create a guid.
Returns:
str: A guid.

$lib.import(name)

Import a Storm Package.

Args:
name (str): Name of the package to import.
Returns:
Lib: A StormLib instance representing the imported Package.

$lib.len(item)

Get the length of a item.

This could represent the size of a string, or the number of keys in a dictionary, or the number of elements in an array.

Args:
item: The item to get the length of.
Returns:
int: The length.

$lib.list(*vals)

Get a Storm List object.

Args:
*vals: Initial values to place in the list.
Returns:
List: A Storm List object.

$lib.max(*args)

Get the maximum value in a list of arguments

Args:
*args: List of arguments to evaluate.
Returns:
The largest argument.

$lib.min(*args)

Get the minimum value in a list of arguments

Args:
*args: List of arguments to evaluate.
Returns:
The smallest argument.

$lib.null

This constant represents a value of None that can be used in Storm. It is not called like a function, it can be directly used.

Examples:

Create a dictionary object with a key whose value is null, and call $lib.fire() with it:

cli> storm $d=$lib.dict(key=$lib.null) $lib.fire('demo', d=$d)
('storm:fire', {'type': 'demo', 'data': {'d': {'key': None}}})

$lib.pprint(item, prefix=’’, clamp=None)

The pprint API should not be considered a stable interface.

$lib.print(mesg, **kwargs)

Print a message to the runtime.

Args:

mesg (str): String to print.

**kwargs: Keyword arguments to substitute into the mesg.

Examples:

Print a simple string:

cli> storm $lib.print("Hello world!")
Hello world!

Format and print string based on variables:

cli> storm $d=$lib.dict(key1=(1), key2="two")
     for ($key, $value) in $d { $lib.print('{k} => {v}', k=$key, v=$value) }
key1 => 1
key2 => two

Use values off of a node to format and print string:

cli> storm inet:ipv4:asn
     $lib.print("node: {ndef}, asn: {asn}", ndef=$node.ndef(), asn=:asn) | spin
node: ('inet:ipv4', 16909060), asn: 1138
Notes:
Arbitrary objects can be printed as well. They will have their Python __repr()__ printed.
Returns:
None: Returns None.

$lib.set(*vals)

Get a Storm Set object.

Args:
*vals: Initial values to place in the set.
Returns:
Set: A Storm Set object.

$lib.sorted(valu)

Yield sorted values.

Args:
valu: An iterable oject to sort.
Returns:
Yields the sorted output.

$lib.text(*args)

Get a Storm Text object.

Args:
*args: An initial set of values to place in the Text. These values are joined together with an empty string.
Returns:
Text: A Storm Text object.

$lib.true

This constant represents a value of True that can be used in Storm. It is not called like a function, it can be directly used.

Examples:

Conditionally print a statement based on the constant value:

cli> storm if $lib.true { $lib.print('Is True') } else { $lib.print('Is False') }
Is True

$lib.undef

This constant can be used to unset variables and derefs.

Examples:

// Unset the variable $foo $foo = $lib.undef

// Remove a dictionary key bar $foo.bar = $lib.undef

// Remove a list index of 0 $foo.0 = $lib.undef

$lib.warn(mesg, **kwargs)

Print a warning message to the runtime.

Args:

mesg (str): String to warn.

**kwargs: Keyword arguments to substitute into the mesg.

Notes:
Arbitrary objects can be warned as well. They will have their Python __repr()__ printed.
Returns:
None: Returns None.

$lib.auth

A Storm Library for interacting with Auth in the Cortex.

$lib.auth.ruleFromText(text)

Get a rule tuple from a text string.

Args:
text (str): The string to process.
Returns:
(bool, tuple): A tuple containing a bool and a list of permission parts.

$lib.auth.gates

A Storm Library for interacting with Auth Gates in the Cortex.

$lib.auth.gates.get(iden)

Get a specific Gate by iden.

Args:
iden (str): The iden of the role to retrieve.
Returns:
Role: A Storm Gate object; or None if the role does not exist.

$lib.auth.gates.list()

Get a list of Gates in the Cortex.

Returns:
list: A list of Storm Gate objects.

$lib.auth.roles

A Storm Library for interacting with Auth Roles in the Cortex.

$lib.auth.roles.add(name)

Add a Role to the Cortex.

Args:
name (str): The name of the role.
Returns:
Role: A Storm Role object for the new user.

$lib.auth.roles.byname(name)

Get a specific Role by name.

Args:
name (str): The name of the role to retrieve.
Returns:
Role: A Storm Role object; or None if the role does not exist.

$lib.auth.roles.del(iden)

Delete a Role from the Cortex.

Args:
iden (str): The iden of the role to delete.
Returns:
None: Returns None.

$lib.auth.roles.get(iden)

Get a specific Role by iden.

Args:
iden (str): The iden of the role to retrieve.
Returns:
Role: A Storm Role object; or None if the role does not exist.

$lib.auth.roles.list()

Get a list of Roles in the Cortex.

Returns:
list: A list of Storm Role objects.

$lib.auth.users

A Storm Library for interacting with Auth Users in the Cortex.

$lib.auth.users.add(name, passwd=None, email=None)

Add a User to the Cortex.

Args:

name (str): The name of the user.

passwd (str): The users password. This is optional.

email (str): The user’s email address. This is optional.

Returns:
User: A Storm User object for the new user.

$lib.auth.users.byname(name)

Get a specific user by name.

Args:
name (str): The name of the user to retrieve.
Returns:
User: A Storm User object; or None if the user does not exist.

$lib.auth.users.del(iden)

Delete a User from the Cortex.

Args:
iden (str): The iden of the user to delete.
Returns:
None: Returns None.

$lib.auth.users.get(iden)

Get a specific User by iden.

Args:
iden (str): The iden of the user to retrieve.
Returns:
User: A Storm User object; or None if the user does not exist.

$lib.auth.users.list()

Get a list of Users in the Cortex.

Returns:
list: A list of Storm User objects.

$lib.axon

A Storm library for interacting with the Cortex’s Axon.

$lib.axon.urlfile(*args, **kwargs)

Retrive the target URL using the wget() function and construct an inet:urlfile node from the response.

Args: see $lib.axon.wget()

Returns:
inet:urlfile node on success. $lib.null on error.

$lib.axon.wget(url, headers=None, params=None, method=’GET’, json=None, body=None, ssl=True, timeout=None)

A method to download an HTTP(S) resource into the Cortex’s Axon.

Args:
url (str): The URL to download headers (dict): An optional dictionary of HTTP headers to send. params (dict): An optional dictionary of URL parameters to add. method (str): The HTTP method to use ( default: GET ). json (dict): A JSON object to send as the body. body (bytes): A bytes to send as the body. ssl (bool): Set to False to disable SSL/TLS certificate verification. timeout (int): Timeout for the download operation.
Returns:
dict: A status dictionary of metadata

Example:

$headers = $lib.dict() $headers.”User-Agent” = Foo/Bar

$resp = $lib.axon.wget(http://vertex.link, method=GET, headers=$headers) if $resp.ok { $lib.print(“Downloaded: {size} bytes”, size=$resp.size) }

$lib.backup

A Storm Library for interacting with the backup APIs in the Cortex.

$lib.backup.del(name)

Remove a backup by name.

Args:
name (str): The name of the backup to remove.

$lib.backup.list()

Returns a list of backup names.

Returns:
list[str]: A list of backup names.

$lib.backup.run(name=None, wait=True)

Run a cortex backup.

Args:

name (str): The name of the backup to generate.

wait (bool): If true, wait for the backup to complete before returning.

Returns:
str: The name of the newly created backup.

$lib.base64

A Storm Library for encoding and decoding base64 data.

$lib.base64.decode(valu, urlsafe=True)

Decode a string into a bytes object.

Args:

valu (str): The string to decode.

urlsafe (bool): Perform the decoding in a urlsafe manner if true.

Returns:
bytes: A bytes object for the decoded data.

$lib.base64.encode(valu, urlsafe=True)

Encode a bytes object to a base64 encoded string.

Args:

valu (bytes): The object to encode.

urlsafe (bool): Perform the encoding in a urlsafe manner if true.

Returns:
str: A base64 encoded string.

$lib.bytes

A Storm Library for interacting with bytes storage.

$lib.bytes.has(sha256)

Check if the Axon the Cortex is configured to use has a given sha256 value.

Args:
sha256 (str): The sha256 value to check.
Examples:

Check if the Axon has a given file:

# This example assumes the Axon does have the bytes
cli> storm if $lib.bytes.has(9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08) {
        $lib.print("Has bytes")
    } else {
        $lib.print("Does not have bytes")
    }

Has bytes
Returns:
bool: True if the Axon has the file, false if it does not.

$lib.bytes.put(byts)

Save the given bytes variable to the Axon the Cortex is configured to use.

Args:
byts (bytes): The bytes to save.
Examples:

Save a base64 encoded buffer to the Axon:

cli> storm $s='dGVzdA==' $buf=$lib.base64.decode($s) ($size, $sha256)=$lib.bytes.put($buf)
     $lib.print('size={size} sha256={sha256}', size=$size, sha256=$sha256)

size=4 sha256=9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
Returns:
(int, str): The size of the bytes and the sha256 hash for the bytes.

$lib.bytes.size(sha256)

Return the size of the bytes stored in the Axon for the given sha256.

Args:
sha256 (str): The sha256 value to check.

Examples:

$size = $lib.bytes.size($sha256)
Returns:
int: The size of the file or $lib.null if the file is not found.

$lib.bytes.upload(genr)

Upload a stream of bytes to the Axon as a file.

Examples:
($size, $sha256) = $lib.bytes.upload($getBytesChunks())
Returns:
(int, str): Returns a tuple of the file size and sha256.

$lib.cron

A Storm Library for interacting with Cron Jobs in the Cortex.

$lib.cron.add(**kwargs)

Add a recurring cron job to the Cortex.

Args:
**kwargs: Key-value parameters used to add the cron job.
Returns:
CronJob: A Storm CronJob object.

$lib.cron.at(**kwargs)

Add a non-recurring cron job to the Cortex.

Args:
**kwargs: Key-value parameters used to add the cron job.
Returns:
CronJob: A Storm CronJob object.

$lib.cron.del(prefix)

Delete a CronJob from the Cortex.

Args:
prefix (str): A prefix to match in order to identify a cron job to delete. Only a single matching prefix will be deleted.
Returns:
None: Returns None

$lib.cron.disable(prefix)

Disable a CronJob in the Cortex.

Args:
prefix (str): A prefix to match in order to identify a cron job to disable. Only a single matching prefix will be enabled.
Returns:
str: The iden of the CronJob which was disabled.

$lib.cron.enable(prefix)

Enable a CronJob in the Cortex.

Args:
prefix (str): A prefix to match in order to identify a cron job to enable. Only a single matching prefix will be enabled.
Returns:
str: The iden of the CronJob which was enabled.

$lib.cron.get(prefix)

Get a CronJob in the Cortex.

Args:
prefix (str): A prefix to match in order to identify a cron job to get. Only a single matching prefix will be retrieved.
Returns:
CronJob: A Storm CronJob object.

$lib.cron.list()

List CronJobs in the Cortex.

Returns:
list: A list of CronJob Storm objects.

$lib.cron.mod(prefix, query)

Modify the Storm query for a CronJob in the Cortex.

Args:

prefix (str): A prefix to match in order to identify a cron job to modify. Only a single matching prefix will be modified.

query (str): The new Storm query for the cron job.

Returns:
None: Returns None.

$lib.csv

A Storm Library for interacting with csvtool.

$lib.csv.emit(*args, table=None)

Emit a csv:row event for the given args.

Args:

*args: A list of items which are emitted as a csv:row event.

table (str): The name of the table to emit data too. Optional.

Returns:
None: Returns None.

$lib.dmon

A Storm Library for interacting with StormDmons.

$lib.dmon.add(text, name=’noname’)

Add a StormDmon to the Cortex.

Args:
text (str): The Storm query to execute. name (str): The name of the Dmon.

Examples:

Add a dmon that executes a query:

$lib.dmon.add(${ myquery }, name='example dmon')
Returns:
str: The iden of the newly created StormDmon.

$lib.dmon.bump(iden)

Restart the daemon

Args:
iden (str): The GUID of the dmon to restart.

$lib.dmon.del(iden)

Delete a StormDmon by iden.

Args:
iden (str): The iden of the StormDmon to delete.
Returns:
None: Returns None.

$lib.dmon.get(iden)

Return a Storm Dmon definition dict by iden.

Args:
iden (str): The iden of the Storm Dmon.
Returns:
(dict): A Storm daemon definition dict.

$lib.dmon.list()

Get a list of StormDmons.

Returns:
list: A list of StormDmons.

$lib.dmon.log(iden)

Get the messages from a StormDmon.

Args:
iden (str): The iden of the StormDmon to get logs for.
Returns:
list: A list of messages from the StormDmon.

$lib.dmon.start(iden)

Start a storm dmon.

Args:
iden (str): The GUID of the dmon to start.

$lib.dmon.stop(iden)

Stop a storm dmon.

Args:
iden (str): The GUID of the dmon to stop.

$lib.feed

A Storm Library for interacting with Cortex feed functions.

$lib.feed.fromAxon(sha256)

Use the feed API to load a syn.nodes formatted export from the axon.

Args:
sha256 (str): The sha256 of the file saved in the axon.
Returns:
int: The number of nodes loaded.

$lib.feed.genr(name, data)

Yield nodes being added to the graph by adding data with a given ingest type.

Args:

name (str): Name of the ingest function to send data too.

data: Data to feed to the ingest function.

Notes:
This is using the Runtimes’s Snap to call addFeedNodes(). This only yields nodes if the feed function yields nodes. If the generator is not entirely consumed there is no guarantee that all of the nodes which should be made by the feed function will be made.
Returns:
s_node.Node: An async generator that yields nodes.

$lib.feed.ingest(name, data)

Add nodes to the graph with a given ingest type.

Args:

name (str): Name of the ingest function to send data too.

data: Data to feed to the ingest function.

Notes:
This is using the Runtimes’s Snap to call addFeedData(), after setting the snap.strict mode to False. This will cause node creation and property setting to produce warning messages, instead of causing the Storm Runtime to be torn down.

$lib.feed.list()

Get a list of feed functions.

Returns:
list: A list of feed functions.

$lib.globals

A Storm Library for interacting with global variables which are persistent across the Cortex.

$lib.globals.get(name, default=None)

Get a Cortex global variables.

Args:

name (str): Name of the variable.

default: Default value to return if the variable is not set.

Returns:
The variable value.

$lib.globals.list()

Get a list of variable names and values.

Returns:
list: A list of variable names and values that the user can access.

$lib.globals.pop(name, default=None)

Delete a variable value from the Cortex.

Args:

name (str): Name of the variable.

default: Default value to return if the variable is not set.

Returns:
The variable value.

$lib.globals.set(name, valu)

Set a variable value in the Cortex.

Args:

name (str): Name of the variable.

valu: The value to set.

Returns:
The variable value.

$lib.inet.http

A Storm Library exposing an HTTP client API.

$lib.inet.http.get(url, headers=None, ssl_verify=True, params=None)

Get the contents of a given URL.

Args:

url (str): The URL to retrieve.

headers (dict): HTTP headers to send with the request.

ssl_verify (bool): Perform SSL/TLS verification. Defaults to true.

params (dict): Optional parameters which may be passed to the request.

Returns:
HttpResp: A Storm HttpResp object.

$lib.inet.http.post(url, headers=None, json=None, body=None, ssl_verify=True, params=None)

Post data to a given URL.

Args:

url (str): The URL to post to.

headers (dict): HTTP headers to send with the request.

json: The data to post, as JSON object.

body: The data to post, as binary object.

ssl_verify (bool): Perform SSL/TLS verification. Defaults to true.

params (dict): Optional parameters which may be passed to the request.

Returns:
HttpResp: A Storm HttpResp object.

$lib.inet.http.request(meth, url, headers=None, json=None, body=None, ssl_verify=True, params=None)

Make an HTTP request using the given HTTP method to the url.

Args:

meth (str): The HTTP method. (ex. PUT)

url (str): The URL to post to.

headers (dict): HTTP headers to send with the request.

json: The data to post, as JSON object.

body: The data to post, as binary object.

ssl_verify (bool): Perform SSL/TLS verification. Defaults to true.

params (dict): Optional parameters which may be passed to the request.

Returns:
HttpResp: A Storm HttpResp object.

$lib.inet.whois

A Storm Library for providing a consistent way to generate guids for WHOIS / Registration Data in Storm.

$lib.inet.whois.guid(props, form)

Provides standard patterns for creating guids for certain inet:whois forms.

Args:
props (dict): Dictionary of properties used to create the form form (str): The inet:whois form to create the guid for
Returns:
(str): A guid from synapse.common
Raises:
StormRuntimeError: If form is not supported in this method

$lib.json

No doc for $lib.json

$lib.json.load(text)

Parse a JSON string and return an object.

$lib.json.save(item)

Save an object as a JSON string.

$lib.layer

A Storm Library for interacting with Layers in the Cortex.

$lib.layer.add(ldef=None)

Add a layer to the Cortex.

Args:
ldef (dict): A Layer definition.
Returns:
Layer: A Storm Layer object.

$lib.layer.del(iden)

Delete a layer from the Cortex.

Args:
iden (str): The iden of the layer to delete.
Returns:
None: Returns None.

$lib.layer.get(iden=None)

Get a Layer from the Cortex.

Args:
iden (str): The iden of the layer to get. If not set, this defaults to the default layer of the Cortex.
Returns:
Layer: A Storm Layer object.

$lib.layer.list()

List the layers in a Cortex:

Returns:
list: A list of Storm Layer objects.

$lib.lift

A Storm Library for interacting with lift helpers.

$lib.lift.byNodeData(name)

Lift nodes which have a given nodedata name set on them.

Args:
name (str): The name to of the nodedata key to lift by.
Returns:
Yields nodes to the pipeline. This must be used in conjunction with the yield keyword.

$lib.macro

A Storm Library for interacting with the Storm Macros in the Cortex.

$lib.macro.del(name)

Delete a Storm Macro by name from the Cortex.

Args:
name (str): The name of the macro to delete.
Returns:
dict: The macro definition which has been removed from the Cortex.

$lib.macro.get(name)

Get a Storm Macro definition by name from the Cortex.

Args:
name (str): The name of the macro to get.
Returns:
dict: A macro definition.

$lib.macro.list()

Get a list of Storm Macros in the Cortex.

Returns:
list: a list of dictionaries representing Macro definitions.

$lib.macro.set(name, storm)

Add or modify an existing Storm Macro in the Cortex.

Args:

name (str): Name of the Storm Macro to add or modify.

storm (str): The Storm query to add to the macro.

Returns:
None: Returns None.

$lib.model

A Storm Library for interacting with the Data Model in the Cortex.

$lib.model.form(name)

Get a ModelForm by name.

Args:
name (str): The name of the form to retrieve.
Returns:
ModelForm: A Storm ModelForm object.

$lib.model.prop(name)

Get a ModelProp by name.

Args:
name (str): The name of the prop to retrieve.
Returns:
ModelProp: A Storm ModelProp object.

$lib.model.tagprop(name)

Get a ModelTagProp by name.

Args:
name (str): The name of the tag property to retrieve.
Returns:
ModelTagProp: A Storm ModelTagProp object.

$lib.model.type(name)

Get a ModelType by name.

Args:
name (str): The name of the type to retrieve.
Returns:
ModelType: A Storm ModelType object.

$lib.model.deprecated

A storm library for interacting with the model deprecation mechanism.

$lib.model.deprecated.lock(name, locked)

No doc for lib.model.deprecated.lock

$lib.model.deprecated.locks()

No doc for lib.model.deprecated.locks

$lib.model.edge

A Storm Library for interacting with light edges and manipulating their key-value attributes.

$lib.model.edge.del(verb, key)

Delete a key from the key-value store for a verb.

Args:

verb (str): The name of the Edge verb to remove a key from.

key (str): The name of the key to remove from the key-value store.

Returns:
None: Returns None.

$lib.model.edge.get(verb)

Get the key-value data for a given Edge verb.

Args:
verb (str): The Edge verb to look up.
Returns:
dict: A dictionary representing the key-value data set on a verb.

$lib.model.edge.list()

Get a list of (verb, key-value dictionary) pairs for Edge verbs in the current Cortex View.

Returns:
list: A list of (str, dict) tuples for each verb in the current Cortex View.

$lib.model.edge.set(verb, key, valu)

Set a key-value for a given Edge verb.

Args:

verb (str): The Edge verb to set a value for.

key (str): The key to set.

valu (str): The value to set.

Returns:
None: Returns None.

$lib.model.edge.validkeys()

Get a list of the valid keys that can be set on an Edge verb.

Returns:
list: A list of the valid keys.

$lib.model.ext

A Storm library for manipulating extended model elements.

$lib.model.ext.addForm(formname, basetype, typeopts, typeinfo)

Add an extended form definition to the data model.

$lib.model.ext.addFormProp(formname, propname, typedef, propinfo)

Add an extended property definition to the data model.

$lib.model.ext.addTagProp(propname, typedef, propinfo)

Add an extended tag property definition to the data model.

$lib.model.ext.addUnivProp(propname, typedef, propinfo)

Add an extended universal property definition to the data model.

$lib.model.ext.delForm(formname)

Remove an extended form definition from the model.

$lib.model.ext.delFormProp(formname, propname)

Remove an extended property definition from the model.

$lib.model.ext.delTagProp(propname)

Remove an extended tag property definition from the model.

$lib.model.ext.delUnivProp(propname)

Remove an extended universal property definition from the model.

$lib.pipe

A Storm library for interacting with non-persistent queues.

$lib.pipe.gen(filler, size=10000)

Generate and return a Storm Pipe by name.

Args:
filler (storm): A storm query to fill the Pipe. name (str): A name for the pipe (for IPC).
Perms:
storm.pipe.gen
Notes:
The filler query is run in parallel with $pipe.

Examples:

$pipe = $lib.pipe.gen(${ $pipe.puts((1, 2, 3)) })

for $items in $pipe.slices(size=2) {
$dostuff($items)

}

$lib.pkg

A Storm Library for interacting with Storm Packages.

$lib.pkg.add(pkgdef)

Add a Storm Package to the Cortex.

Args:
pkgdef (dict): A Storm Package definition.
Returns:
dict: The validated storm package definition.

$lib.pkg.del(name)

Delete a Storm Package from the Cortex.

Args:
name (str): The name of the package to delete.
Returns:
None

$lib.pkg.get(name)

Get a Storm package from the Cortex.

Args:
name (str): A Storm Package name.
Returns:
dict: The Storm package definition.

$lib.pkg.list()

Get a list of Storm Packages loaded in the Cortex.

Returns:
list: A list of Storm Package definitions.

$lib.ps

A Storm Library for interacting with running tasks on the Cortex.

$lib.ps.kill(prefix)

Stop a running task on the cortex.

Args:
prefix (str): The prefix of the task to stop. Tasks will only be stopped if there is a single prefix match.
Returns:
bool: True if the task was cancelled, false otherwise.

$lib.ps.list()

List tasks the current user can access.

Returns:
list: A list of task dictionaries.

$lib.queue

A Storm Library for interacting with persistent Queues in the Cortex.

$lib.queue.add(name)

Add a Queue to the Cortex with a given name.

Args:
name (str): The name of the queue.
Returns:
Queue: A Storm Queue object.

$lib.queue.del(name)

Delete a given named Queue.

Args:
name (str): The name of the queue to delete.
Returns:
None: Returns None.

$lib.queue.gen(name)

Get/add a Storm Queue in a single operation.

Args:
name (str): The name of the Queue to get/add.
Returns:
Queue: A Storm Queue object.

$lib.queue.get(name)

Get an existing Storm Queue object.

Args:
name (str): The name of the Queue to get.
Returns:
Queue: A Storm Queue object.

$lib.queue.list()

Get a list of the Queues in the Cortex.

Returns:
list: A list of queue definitions the current user is allowed to interact with.

$lib.regex

A Storm library for searching/matching with regular expressions.

$lib.regex.matches(pattern, text, flags=0)

Returns $lib.true if the text matches the pattern, otherwise $lib.false.

Notes:

This API requires the pattern to match at the start of the string.

Example:

if $lib.regex.matches(“^[0-9]+.[0-9]+.[0-9]+$”, $text) {
$lib.print(“It’s semver! …probably”)

}

$lib.regex.search(pattern, text, flags=0)

Search the given text for the pattern and return the matching groups.

Note:

In order to get the matching groups, patterns must use parentheses to indicate the start and stop of the regex to return portions of. If groups are not used, a successful match will return a empty list and a unsuccessful match will return $lib.null.

Example:

$m = $lib.regex.search(“^([0-9])+.([0-9])+.([0-9])+$”, $text) if $m {

($maj, $min, $pat) = $m

}

$lib.service

A Storm Library for interacting with Storm Services.

$lib.service.add(name, url)

Add a Storm Service to the Cortex.

Args:

name (str): Name of the Storm Service to add.

url (str): The Telepath URL to the Storm Service.

Returns:
dict: The Storm Service definition.

$lib.service.del(iden)

Remove a Storm Service from the Cortex.

Args:
iden (str): The iden of the service to remove.
Returns:
None: Returns None.

$lib.service.get(name)

Get a Storm Service definition.

Args:
name (str): The local name, local iden, or remote name, of the service to get the definition for.
Returns:
dict: A Storm Service definition.

$lib.service.has(name)

Check if a storm service is available in the Cortex.

Args:
name (str): The local name, local iden, or remote name, of the service to check for the existance of.
Returns:
bool: True if the service exists in the Cortex, False if it does not.

$lib.service.list()

List the Storm Service definitions for the Cortex.

Notes:
The definition dictionaries have an additional ready key added to them to indicate if the Cortex is currently connected to the Storm Service or not.
Returns:
list: A list of Storm Service definitions.

$lib.service.wait(name)

Wait for a given service to be ready.

Args:
name (str): The name, or iden, of the service to wait for.
Returns:
True: When the service is ready.

$lib.stats

A Storm Library for statistics related functionality.

$lib.stats.tally()

Get a Tally object.

Returns:
Tally: A Storm Tally object.

$lib.str

A Storm Library for interacting with strings.

$lib.str.concat(*args)

Concatenate a set of strings together.

Args:
*args: Items to join togther.
Returns:
str: The joined string.

$lib.str.format(text, **kwargs)

Format a text string.

Args:
text: The base text string. **kwargs: Keyword values which are substituted into the string.
Examples:

Format a string with a fixed argument and a variable:

cli> storm $list=(1,2,3,4)
     $str=$lib.str.format('Hello {name}, your list is {list}!', name='Reader', list=$list)
     $lib.print($str)

Hello Reader, your list is ['1', '2', '3', '4']!
Returns:
str: The new string.

$lib.str.join(sepr, items)

Join items into a string using a separator.

Args:
sepr (str): The separator used to join things with. items (list): A list of items to join together.
Examples:

Join together a list of strings with a dot separator:

cli> storm $foo=$lib.str.join('.', ('rep', 'vtx', 'tag')) $lib.print($foo)

rep.vtx.tag
Returns:
str: The joined string.

$lib.telepath

A Storm Library for making Telepath connections to remote services.

$lib.telepath.open(url)

Open and return a telepath RPC proxy.

Args:
url (str): The Telepath URL to connect to.
Returns:
Proxy: A Storm Proxy representing a Telepath Proxy.

$lib.time

A Storm Library for interacting with timestamps.

$lib.time.format(valu, format)

Format a Synapse timestamp into a string value using datetime.strftime().

Args:
valu (int): A timestamp in epoch milliseconds. format (str): The strftime format string.
Examples:

Format a timestamp into a string:

cli> storm $now=$lib.time.now() $str=$lib.time.format($now, '%A %d, %B %Y') $lib.print($str)

Tuesday 14, July 2020
Returns:
str: The formatted time string.

$lib.time.fromunix(secs)

Normalize a timestamp from a unix epoch time in seconds to milliseconds.

Args:
secs (int): Unix epoch time in seconds.
Examples:

Convert a timestamp from seconds to millis and format it:

cli> storm $seconds=1594684800 $millis=$lib.time.fromunix($seconds)
     $str=$lib.time.format($millis, '%A %d, %B %Y') $lib.print($str)

Tuesday 14, July 2020
Returns:
int: The normalized time in milliseconds.

$lib.time.now()

Get the current epoch time in milliseconds.

Returns:
int: Epoch time in milliseconds.

$lib.time.parse(valu, format)

Parse a timestamp string using datetime.strptime() into an epoch timestamp.

Args:
valu (str): The timestamp string to parse. format (str): The format string to use for parsing.
Examples:

Parse a string as for its month/day/year value into a timestamp:

cli> storm $s='06/01/2020' $ts=$lib.time.parse($s, '%m/%d/%Y') $lib.print($ts)

1590969600000
Returns:
int: The epoch timetsamp for the string.

$lib.time.sleep(valu)

Pause the processing of data in the storm query.

Args:
valu (int): The number of seconds to pause for.
Notes:
This has the effect of clearing the Snap’s cache, so any node lifts performed after the $lib.time.sleep(...) executes will be lifted directly from storage.

Returns:

$lib.time.ticker(tick, count=None)

Periodically pause the processing of data in the storm query.

Args:

tick (int): The amount of time to wait between each tick, in seconds.

count (int): The number of times to pause the query before exiting the loop. This defaults to None and will yield forever if not set.

Notes:
This has the effect of clearing the Snap’s cache, so any node lifts performed after each tick will be lifted directly from storage.
Returns:
int: This yields the current tick count after each time it wakes up.

$lib.trigger

A Storm Library for interacting with Triggers in the Cortex.

$lib.trigger.add(tdef)

Add a Trigger to the Cortex.

Args:
tdef (dict): A Trigger definition.
Returns:
Trigger: A Storm Trigger object.

$lib.trigger.del(prefix)

Delete a Trigger from the Cortex.

Args:
prefix (str): A prefix to match in order to identify a trigger to delete. Only a single matching prefix will be deleted.
Returns:
str: The iden of the deleted trigger which matched the prefix.

$lib.trigger.disable(prefix)

Disable a Trigger in the Cortex.

Args:
prefix (str): A prefix to match in order to identify a trigger to modify. Only a single matching prefix will be modified.
Returns:
str: The iden of the trigger that was disabled.

$lib.trigger.enable(prefix)

Enable a Trigger in the Cortex.

Args:
prefix (str): A prefix to match in order to identify a trigger to modify. Only a single matching prefix will be modified.
Returns:
str: The iden of the trigger that was enabled.

$lib.trigger.get(iden)

Get a Trigger in the Cortex.

Args:
iden (str): The iden of the Trigger to get.
Returns:
Trigger: A Storm Trigger object.

$lib.trigger.list()

Get a list of Triggers in the Cortex.

Returns:
list: A List of trigger objects the user is allowed to access.

$lib.trigger.mod(prefix, query)

Modify an existing Trigger in the Cortex.

Args:

prefix (str): A prefix to match in order to identify a trigger to modify. Only a single matching prefix will be modified.

query: The new Storm Query to set as the trigger query.

Returns:
str: The iden of the modified Trigger.

$lib.user

A Storm Library for interacting with data about the current user.

$lib.user.allowed(permname, gateiden=None)

Return True/False if the current user has the given permission.

$lib.user.name()

Get the name of the current runtime user.

Returns:
str: The name of the current user.

$lib.vars

A Storm Library for interacting with runtime variables.

$lib.vars.del(name)

Unset a variable in the current Runtime.

Args:
name (str): The variable name to remove.
Returns:
None: Returns None

$lib.vars.get(name, defv=None)

Get the value of a variable from the current Runtime.

Args:

name (str): Name of the variable to get.

defv: The default value returned if the variable is not set in the runtime.

Returns:
The value of the variable.

$lib.vars.list()

Get a list of variables from the current Runtime.

Returns:
list: A list of variable names and their values for the current Runtime.

$lib.vars.set(name, valu)

Set the value of a variable in the current Runtime.

Args:

name (str): Name of the variable to set.

valu: The value to set the variable too.

Returns:
None: Returns None.

$lib.version

No doc for $lib.version

$lib.version.matches(vertup, reqstr)

Return True if the given version tuple meets the requirements string.

Returns:
bool: True if the version meets the requirements.
Examples:

// Check if the synapse version is in a range $synver = $lib.version.synapse() if $lib.version.matches($synver, “>=2.9.0”) {

$dostuff()

}

$lib.version.synapse()

Return the synapse version tuple for the local cortex.

Returns:
tuple: A version tripple.

$lib.view

A Storm Library for interacting with Views in the Cortex.

$lib.view.add(layers, name=None)

Add a View to the Cortex.

Args:

layers (list): A list of idens which make up the view.

name (str): The name of the view.

Returns:
View: A Storm View object.

$lib.view.del(iden)

Delete a View from the Cortex.

Args:
iden (str): The iden of the view to delete.
Returns:
None: Returns None.

$lib.view.get(iden=None)

Get a View from the Cortex.

Args:
iden (str): The iden of the View to get. If not specified, returns the current View.
Returns:
View: A Storm View object.

$lib.view.list()

List the Views in the Cortex.

Returns:
list: A list of Storm View objects.