TextFSM2¶
A drop-in replacement for Google's 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.
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 anything that behaves differently from textfsm.
Goals¶
- Faster ETL. Make TextFSM parsing fast enough that it stops being the slow step in network-automation ETL pipelines.
- 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.
- Lean on resources. Spend less CPU time and memory per parse, so each worker in a pipeline handles more devices.
- 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, and every pull request reports its effect on them.
- 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_outputacross 4 threads runs 2.0× faster than on standard 3.15; as fast or faster on 7 of 8 workloads.
Install¶
With pip:
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:
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:
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 — install, write a template, and parse output in 5 minutes.
- How-to guides: Migrate from textfsm · Configure cache and compatibility
- Reference: API, CLI, and environment · Template syntax · Benchmarks
- Explanation: How it works · Compatibility
- Upstream resources: google/textfsm · TextFSM Wiki