# Scripting in StackState

StackState uses scripting in many places to:

* Transform incoming data
* Query 4T data
* Describe state changes of the 4T data model
* Control the StackState UI
* Create reports
* Connect to external services

StackState scripts are written using the StackState Scripting Language (STSL), which is based on [Groovy](https://groovy-lang.org/). The choice of Groovy is motivated by the fact that StackState is written in Scala and runs on JVM. Currently, Groovy is the best and most performant script language for JVM. You aren't stuck to using Groovy though, you can use the [HTTP script API](/5.1/develop/reference/scripting/script-apis/http.md) to develop logic in any language.

{% hint style="info" %}
All scripts have a default (configurable) timeout of 15 seconds.
{% endhint %}

## Running Scripts

StackState scripts can be executed in the [Analytics environment](/5.1/use/stackstate-ui/analytics.md). This can be accessed from the main menu of the StackState UI. The Analytics Environment interface consists of a scripting panel on the left and the results panel on the right.

![Analytics environment](/files/kngAYWdRvd35edGnANM4)

Write a script in the **Query** panel and click **EXECUTE** to run it. The script output is displayed in the **Result** panel. Results can be viewed as a raw JSON string or as a preview generated by StackState automatically depending on the JSON object's type and content.

## Script APIs

All StackState functionality exposed via scripting is available via so-called script APIs. These are singleton objects starting with a capital case letter that contain a number of callable functions. Commonly used script APIs are:

* [Topology script API](/5.1/develop/reference/scripting/script-apis/topology.md) for querying the topology
* [HTTP script API](/5.1/develop/reference/scripting/script-apis/http.md) for calling out to external services
* [View script API](/5.1/develop/reference/scripting/script-apis/view.md) to get view definitions.

  Please have a look at the full list of [script APIs](/5.1/develop/reference/scripting/script-apis.md).

## Asynchronous and streaming programming

Most functions available through the StackState script APIs need some time to return a result. For efficiency reasons, StackState will suspend script execution while waiting for a result and continue other work on other background threads. When a function has an async return value, the word `async` is written before the return type in the script API documentation. This has implications for how to work with results. Please [read about async script results](/5.1/develop/reference/scripting/async-script-result.md) to understand how this works. On top of asynchronous programming, some APIs make use of [streaming](/5.1/develop/reference/scripting/streaming-script-result.md) to allow constant-memory processing of large amounts of data.

## See also

* [Analytics environment](/5.1/use/stackstate-ui/analytics.md)
* [Async script results](/5.1/develop/reference/scripting/async-script-result.md)
* [Streaming script results](/5.1/develop/reference/scripting/streaming-script-result.md)
* [Script APIs](/5.1/develop/reference/scripting/script-apis.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://archivedocs.stackstate.com/5.1/develop/reference/scripting/scripting-in-stackstate.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
