# TextFSM2

A drop-in replacement for [Google's TextFSM](<https://github.com/google/textfsm>) with a Rust core: the same API and the same output, parsed much faster. It installs as `textfsm2`, next to `textfsm` rather than instead of it, and passes `google/textfsm`'s suite and all 7,810 tests in [ntc-templates](<https://github.com/networktocode/ntc-templates>).

> [!WARNING]
>
> **Experimental and heavily AI-assisted**
>
> This is my first Python package with a Rust core, and most of that Rust was written with AI coding assistants ("vibe-coded") while I was still learning the language. I have applied the software engineering habits I trust: upstream's test suite, every ntc-templates test, differential fuzzing against textfsm, strict linting, and CI on every change. I have polished it as far as I can, but no experienced Rust developer has reviewed the core yet. Try it in your own pipelines before you depend on it, keep `textfsm` as a fallback, and [report](<https://github.com/ryanmerolle/textfsm2/issues/new/choose>) anything that behaves differently from textfsm.

## Goals

1. **Faster ETL.** Make TextFSM parsing fast enough that it stops being the slow step in network-automation ETL pipelines.
2. **Threads and free-threaded Python.** Scale across threads on standard Python (the parser releases the GIL) and on free-threaded Python (3.14t and later), where TextFSM2 must be as fast as or faster than on standard Python.
3. **Lean on resources.** Spend less CPU time and memory per parse, so each worker in a pipeline handles more devices.
4. **Learn Rust by shipping.** Build, test, and release my first Python package with a Rust core (PyO3 and maturin).

None of these may cost exactness: output, exceptions, and error messages stay identical to textfsm. Every release measures each goal against textfsm in the [benchmarks](<https://ryanmerolle.github.io/textfsm2/reference/benchmarks/index.md>), and every pull request reports its effect on them.

![ntc-templates 9.4.0 (06fa3338) parse\_output (1,906 files): textfsm2 vs textfsm](<https://ryanmerolle.github.io/textfsm2/assets/benchmark-ntc-light.svg#only-light>) ![ntc-templates 9.4.0 (06fa3338) parse\_output (1,906 files): textfsm2 vs textfsm](<https://ryanmerolle.github.io/textfsm2/assets/benchmark-ntc-dark.svg#only-dark>)

- **Overall:** 12.3× faster than textfsm 2.1.1 (geometric mean across 7 parsing, threading, and end-to-end workloads; 91.9% less wall time).
- **Single-threaded parsing:** 7.3–10.2× faster (9.2× geometric mean); **multi-threaded (4 threads):** 33.4× faster.
- **ntc-templates `parse_output`:** 9.4× faster cold, 18.6× faster warm across 1,906 test files of ntc-templates 9.4.0 (06fa3338).
- **Resources:** ntc-templates `parse_output` (cold cache) uses 89% less CPU time than textfsm 2.1.1, with a peak of 96 MB against 49 MB.
- **Free-threaded Python (3.15t):** `parse_output` across 4 threads runs 2.0× faster than on standard 3.15; as fast or faster on 7 of 8 workloads.

## Install

```sh
uv add textfsm2             # primary (or: uv pip install textfsm2)
```

With `pip`:

```sh
pip install textfsm2
```

## Quick example

Import `textfsm2 as textfsm` directly, or call `textfsm2.alias_textfsm()` once at application startup so third-party libraries (`ntc-templates`, `netmiko`) use `textfsm2` automatically:

```python
import textfsm2 as textfsm

with open("template.textfsm", encoding="utf-8") as f:
    fsm = textfsm.TextFSM(f)
rows = fsm.ParseText(cli_output)
dicts = fsm.ParseTextToDicts(cli_output)
```

Validate or run a template from the command line:

```sh
uvx textfsm2 template.textfsm input.txt
textfsm2 template.textfsm input.txt
```

## Exploring next

- **Publishing the Rust core as a crate**, so Rust programs can parse TextFSM templates without Python.
- **Better errors for template authors and users**: point at the template line and rule that failed, and say why, adding detail without changing the error types and messages that code relies on today.

## Explore the docs

- **Tutorials:** [Quickstart](<https://ryanmerolle.github.io/textfsm2/tutorials/quickstart/index.md>) — install, write a template, and parse output in 5 minutes.
- **How-to guides:** [Migrate from textfsm](<https://ryanmerolle.github.io/textfsm2/guides/migration/index.md>) · [Configure cache and compatibility](<https://ryanmerolle.github.io/textfsm2/guides/configuration/index.md>)
- **Reference:** [API, CLI, and environment](<https://ryanmerolle.github.io/textfsm2/reference/api/index.md>) · [Template syntax](<https://ryanmerolle.github.io/textfsm2/reference/templates/index.md>) · [Benchmarks](<https://ryanmerolle.github.io/textfsm2/reference/benchmarks/index.md>)
- **Explanation:** [How it works](<https://ryanmerolle.github.io/textfsm2/explanation/how-it-works/index.md>) · [Compatibility](<https://ryanmerolle.github.io/textfsm2/explanation/compatibility/index.md>)
- **Upstream resources:** [google/textfsm](<https://github.com/google/textfsm>) · [TextFSM Wiki](<https://github.com/google/textfsm/wiki>)
