# Run pipelines

You can run a [pipeline](https://preview.docs.tenzir.com/375/375/explanations/pipeline.md) via the [platform](https://app.tenzir.com), on the command line using the `tenzir` binary, or as code via the configuration file.

## In the platform

Run a pipeline by writing typing it in the editor and hitting the *Run* button.

The following invariants apply:

1. You must start with an input operator
2. The browser is always the output operator

The diagram below illustrates these mechanics:

For example, write `from {x: 42}` and click *Run* to see a single event show up.

## On the command line

On the command line, run `tenzir <pipeline>` where `<pipeline>` is the definition of the pipeline. See [Installation](https://preview.docs.tenzir.com/375/375/guides/installation.md) for how to get the binary.

The command-line runner completes open pipelines with standard input or standard output. A pipeline that already starts with a source and ends with a sink runs as written:

```sh
tenzir 'from_file "events.json" { read_json } | to_file "events.csv" { write_csv }'
```

A transformation-only pipeline reads JSON events from standard input and writes TQL events to standard output:

```sh
echo '{"x":1}' | tenzir 'select x | head'
```

A parser-to-printer pipeline reads bytes from standard input and writes bytes to standard output:

```sh
cat input.yaml | tenzir 'read_yaml | select x | write_csv'
```

The diagram below illustrates these mechanics:

For example, run `tenzir 'version | drop dependencies'` to see a single event in the terminal:

```tql
{
  version: "5.0.1+g847fcc6334",
  tag: "g847fcc6334",
  major: 5,
  minor: 0,
  patch: 1,
  features: [
    "chart_limit",
    "modules",
    "tql2_from",
    "exact_schema",
    "tql2_only",
  ],
  build: {
    type: "Release",
    tree_hash: "ef28a81eb124cc46a646250d1fb17390",
    assertions: false,
    sanitizers: {
      address: false,
      undefined_behavior: false,
    },
  },
}
```

You could also render the output differently by choosing a different format:

```sh
tenzir 'version | drop dependencies | write_csv'
tenzir 'version | drop dependencies | write_ssv'
tenzir 'version | drop dependencies | to_file "version.parquet" { write_parquet }'
```

Instead of passing the pipeline description to the `tenzir` executable, you can also load the definition from a file via `-f`:

```sh
tenzir -f pipeline.tql
```

This will interpret the file contents as pipeline and run it.

## As Code

In addition to running pipelines interactively, you can also deploy *pipelines as code (PaC)*. This infrastructure-as-code-like method differs from the app-based deployment in two ways:

1. Pipelines deployed as code always start with the Tenzir node, ensuring continuous operation.
2. To safeguard them, deletion via the user interface is disallowed.

Here’s a an example of deploying a pipeline through your configuration:

\<prefix>/etc/tenzir/tenzir.yaml

```yaml
tenzir:
  pipelines:
    # A unique identifier for the pipeline that's used for metrics, diagnostics,
    # and API calls interacting with the pipeline.
    suricata-over-tcp:
      # An optional user-facing name for the pipeline. Defaults to the id.
      name: Onboard Suricata from TCP
      # An optional user-facing description of the pipeline.
      description: |
        Onboards Suricata EVE JSON from TCP port 34343.
      # The definition of the pipeline. Configured pipelines that fail to start
      # cause the node to fail to start.
      definition: |
        accept_tcp "0.0.0.0:34343" {
          read_suricata
        }
        publish "suricata"
      # Pipelines that encounter an error stop running and show an error state.
      # This option causes pipelines to automatically restart when they
      # encounter an error instead. The first restart happens immediately, and
      # subsequent restarts after the configured delay, defaulting to 1 minute.
      # The following values are valid for this option:
      # - Omit the option, or set it to null or false to disable.
      # - Set the option to true to enable with the default delay of 1 minute.
      # - Set the option to a valid duration to enable with a custom delay.
      restart-on-error: 1 minute
      # Add a list of labels that are shown in the pipeline overview page at
      # app.tenzir.com.
      labels:
        - Suricata
        - Onboarding
      # Disable the pipeline.
      disabled: false
      # Pipelines that are unstoppable will run automatically and indefinitely.
      # They are not able to pause or stop.
      # If they do complete, they will end up in a failed state.
      # If `restart-on-error` is enabled, they will restart after the specified
      # duration.
      unstoppable: true
```

## Contents

- [Manage-a-pipeline](https://preview.docs.tenzir.com/375/guides/basic-usage/manage-a-pipeline.md)