API, CLI, and environment reference¶
Reference for textfsm2 exports, CLI entrypoints, runtime cache controls, and environment variables. For the full upstream API, see google/textfsm and its wiki.
Python exports (textfsm2)¶
textfsm2 star-exports everything from textfsm2.parser plus alias_textfsm and __version__:
| Symbol | Purpose |
|---|---|
textfsm2.TextFSM(template, options_class=...) | Compile a TextFSM template file/stream into a reusable FSM |
fsm.ParseText(text, eof=True) | Parse text and return a list of row lists |
fsm.ParseTextToDicts(text, eof=True) | Parse text and return a list of dicts keyed by header |
fsm.Reset() | Reset runtime state back to Start |
textfsm2.clitable.CliTable(index_file, template_dir) | Map CLI commands and attributes to templates via an index file |
textfsm2.texttable.TextTable | Ordered table representation used by CliTable |
textfsm2.alias_textfsm() | Redirect import textfsm (textfsm.*) to textfsm2 process-wide |
Command-line interface (textfsm2)¶
Invoke the CLI with uvx, uv run, or directly from an installed environment:
uvx textfsm2 [--help] template [input_file [output_file]]
uv run textfsm2 [--help] template [input_file [output_file]]
textfsm2 [--help] template [input_file [output_file]]
| Arguments | Behaviour | Exit code |
|---|---|---|
-h, --help | Print module help and CLI usage | 0 |
template | Validate and print parsed FSM Template: | 0 |
template input_file | Print FSM Template: and parsed FSM Table: | 0 |
template input_file output_file | Compare parsed FSM Table: with output_file | 0 match, 1 mismatch |
| Invalid arguments or template/FSM error | Print error to stderr | 2 |
Rust cache helpers (textfsm2._core)¶
Internal runtime controls exposed by the Rust extension:
| Function | Signature / behaviour |
|---|---|
cache_info() | Return (hits, misses, size, maxsize) |
cache_clear() | Empty the compiled-template cache |
set_cache_size(n) | Set max cached templates (0 disables caching) |
set_scratch_pool(n) | Set warm regex search-buffer sets retained per template |
Environment variables¶
| Variable | Default | Effect |
|---|---|---|
TEXTFSM_SKIP_NONPARTICIPATING_GROUPS | off | Opt in to google/textfsm#151 behaviour when truthy |
TEXTFSM_CACHE_SIZE | 128 | Max compiled templates cached in memory (0 disables; < 0 raises ValueError) |
TEXTFSM_SCRATCH_POOL | 1 | Warm search-buffer sets per template (0 frees after parse; < 0 raises ValueError) |