LogicVein Script Sandbox Utils
Convenience helpers for Python scripts that LogicVein Playbooks run in the
Script Sandbox container. They wrap the sandbox's file-and-stdout contract:
a Playbook hands your script its inputs in in.json, and your script returns
results by printing JSON to stdout.
Installation
From PyPI:
pip install lvi-script-sandbox-utils
From TestPyPI (pre-release / testing):
pip install \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple/ \
lvi-script-sandbox-utils
The sandbox runs scripts in a container, so the package has to be available
inside it. If your sandbox mounts a packages directory (for example
./packages:/packages), install into it:
pip install --target ./packages lvi-script-sandbox-utils
The library has no third-party dependencies (standard library only).
Upgrading from 0.1.x
0.1.x installed as logicvein.lvi_script_sandbox_utils. From 0.2.0 it is
the top-level package lvi_script_sandbox_utils, so change
from logicvein import lvi_script_sandbox_utils as lvi
to import lvi_script_sandbox_utils as lvi. The logicvein package is
left to lvi-api-client: when both shipped a logicvein/ directory,
pip install --target skipped whichever was installed second (or, with
--upgrade, deleted the first).
Usage
import lvi_script_sandbox_utils as lvi
device = lvi.get_device()
output = lvi.get_input("cli_output", default="") # "" in the Playbook's first script node
lvi.flush_output(hostname=device.device_hostname, line_count=len(output.splitlines()))
Functions
| Function | Purpose |
|---|---|
load_input(path=None, reload=False) |
The whole in.json as a dict, read once and cached. Treat it as read-only. |
get_input(input_type, default=...) |
Read an input from in.json. "cli_output" returns the previous node's result value; "device" returns the raw device dict. A missing input returns default, or raises KeyError if none was given; any other input_type raises ValueError. |
get_global(name, default=...) |
One Playbook global's value, e.g. get_global("hostname"). A missing global returns default, or raises KeyError naming the globals that are set. |
get_globals() |
Every Playbook global as {name: value}. |
get_metadata() |
Details of this run as an object: playbook, execution_id, executor, job_id, node, started_at, and so on. |
get_device(blank_none=True) |
The Playbook's device as an object with a basic set of properties (see below). |
get_full_device(blank_none=True) |
Like get_device(), with the additional properties included (uuid, lastBackup, severity, memoSummary, ...). |
set_output(key, value) |
Record a global for the next flush_output(). |
flush_output(**kwargs) |
Print the set_output() values plus kwargs (which win on a clash) to stdout as Playbook global variables (output.globals), then clear the set_output() values. Playbook globals are strings, so a list, dict, device or metadata object is printed as its JSON text (see below). |
flush_string_output(text) |
Print a string to stdout as base64-encoded raw output (output.raw). |
On the device objects:
hostnameandnetworkare renamed todevice_hostnameanddevice_network, so they don't collide with other Playbook variables.traitslists the device's capabilities frommetaJson(ssh,snmp,ncm, ...);customFieldsis dropped, since it repeatscustom1..custom5.- End-of-life/sale epochs (
endOfLife,endOfSale,softwareEndOfLife,softwareEndOfSale) becomeYYYY-MM-DDdates, andlastBackup,lastChange,lastDiscovery,lastTelemetrybecomeYYYY-MM-DDTHH:MM:SSZtimestamps, all in UTC.get_metadata().started_atis converted the same way. Nonevalues become""; passblank_none=Falseto keepNone.- A property LogicVein doesn't send is simply absent from the object.
vars(device) gives the properties as a dict, so
lvi.flush_output(**vars(device)) turns every property into a Playbook
global.
Output globals are strings
LogicVein reads output.globals as strings. It converts numbers and booleans
itself, but rejects the whole output if any value is a list or an object
(MismatchedInputException ... from Array value). flush_output() therefore
prints such values as their JSON text: device.traits becomes
'["icmp", "snmp", ...]', which a later script node can read back with
json.loads(lvi.get_global("traits")). For a different format, convert the
value yourself first, e.g. traits=", ".join(device.traits).
Where the input comes from
in.json is read on first use, not at import, and only once; load_input()
returns it as a dict (pass reload=True to read it again). The module
attributes device and device_full are built the first time a script uses
them. By default the file is in.json in the working directory, where the
sandbox puts it; set LVI_SANDBOX_INPUT to read another file, e.g. a saved
in.json while developing a script outside a Playbook:
LVI_SANDBOX_INPUT=./samples/in.json python my_script.py
Development and releases
See CONTRIBUTING.md for development setup and PUBLISHING.md for how releases are published.
Metadata
Release files for lvi-script-sandbox-utils 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lvi_script_sandbox_utils-0.6.1.tar.gz | 15.8 kB | Without provenance | Details for lvi_script_sandbox_utils-0.6.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lvi_script_sandbox_utils-0.6.1-py3-none-any.whl | Python 3 | none | any | Details for lvi_script_sandbox_utils-0.6.1-py3-none-any.whl |
Total release size: 28.0 kB
Release files / lvi_script_sandbox_utils-0.6.1.tar.gz
| Download URL | lvi_script_sandbox_utils-0.6.1.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
68b48cc1b3b0ffc3666ff685a5ea96741caf1317d101734d921857bd34fdbe3e
|
|
BLAKE2b-256 checksum How to use checksums |
43b7c98ff7913b640d840db73131bbf83702e17c1ec1138329d381bea54ad59b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Release files / lvi_script_sandbox_utils-0.6.1-py3-none-any.whl
| Download URL | lvi_script_sandbox_utils-0.6.1-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
77b4c765f2e41e5c73ac96ae3baff2db27cdd7a4245c8f4697b500f19252892d
|
|
BLAKE2b-256 checksum How to use checksums |
ad06892bff531f937ece96e9b4bdf1ef76f25bc8ef98093d9949c19efd35f9ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Security for lvi-script-sandbox-utils 0.6.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.