# Quickstart

Install `textfsm2`, write a template for router output, parse it in Python, and verify the result from the command line in under five minutes.

If you are new to TextFSM templates, see the [Google TextFSM Wiki](<https://github.com/google/textfsm/wiki>) and its [Code Lab](<https://github.com/google/textfsm/wiki/Code-Lab>).

## 1\. Install `textfsm2`

Add `textfsm2` to your project with `uv`:

```sh
uv add textfsm2
```

Or with `pip`:

```sh
pip install textfsm2
```

## 2\. Create a template and sample input

Save this template as `interfaces.textfsm`. It declares three columns (`Vrf`, `Interface`, and `Addr`) and four state rules under `Start`:

```text
Value Filldown Vrf (\S+)
Value Required Interface (\S+)
Value List Addr (\d+\.\d+\.\d+\.\d+)

Start
  ^VRF ${Vrf}
  ^Interface ${Interface} -> Continue
  ^\s+inet ${Addr}
  ^$$ -> Record
```

Save this CLI output as `interfaces.txt`:

```text
VRF red
Interface eth0
  inet 10.0.0.1
  inet 10.0.0.2

Interface eth1
  inet 192.168.1.1
```

## 3\. Parse the text in Python

Import `textfsm2 as textfsm` and pass the template and input text to `TextFSM`:

```python
import textfsm2 as textfsm

with open("interfaces.textfsm", encoding="utf-8") as f:
    fsm = textfsm.TextFSM(f)

with open("interfaces.txt", encoding="utf-8") as f:
    raw = f.read()

print(fsm.header)
print(fsm.ParseText(raw))

fsm.Reset()
print(fsm.ParseTextToDicts(raw))
```

Run the script and confirm it prints structured rows and dicts:

```text
['Vrf', 'Interface', 'Addr']
[['red', 'eth0', ['10.0.0.1', '10.0.0.2']], ['red', 'eth1', ['192.168.1.1']]]
[{'Vrf': 'red', 'Interface': 'eth0', 'Addr': ['10.0.0.1', '10.0.0.2']}, ...]
```

## 4\. Test templates from the CLI

You can inspect or validate any template directly from the shell without writing Python:

```sh
# Using uv (no install needed)
uvx textfsm2 interfaces.textfsm interfaces.txt

# Inside a uv project environment
uv run textfsm2 interfaces.textfsm interfaces.txt

# Directly if installed in the active environment
textfsm2 interfaces.textfsm interfaces.txt
```

Pass a third file path containing the expected `FSM Table:` output to exit with status `1` on mismatch.

## Next steps

- Switch existing codebases and `ntc-templates` in [Migrate from textfsm](<https://ryanmerolle.github.io/textfsm2/guides/migration/index.md>).
- Look up every Value option and Rule action in [Template syntax](<https://ryanmerolle.github.io/textfsm2/reference/templates/index.md>).
- Explore the upstream [Code Lab](<https://github.com/google/textfsm/wiki/Code-Lab>) on the [google/textfsm](<https://github.com/google/textfsm>) repository.
