Configure cache and compatibility¶
Tune memory usage, enable unreleased google/textfsm#151 behaviour, and run CLI template checks in CI.
Size the compiled-template cache¶
textfsm2 keeps compiled programs in a process-wide LRU cache. The default size (128) uses roughly 30 MB when full.
Increase the cache if your workload cycles through hundreds of templates (for example, parsing across all ntc-templates platforms):
Or adjust the limit and inspect hit/miss counts at runtime:
from textfsm2 import _core
_core.set_cache_size(2048)
hits, misses, size, maxsize = _core.cache_info()
_core.cache_clear()
Disable caching when memory matters more than repeated template lookups:
Free warm search buffers after each parse¶
Each cached template retains a pool of warm regex scratch buffers (1 per template by default, ~130 KB once used). Release buffers immediately after each parse by setting:
Negative values for TEXTFSM_CACHE_SIZE or TEXTFSM_SCRATCH_POOL raise ValueError when importing textfsm2.
Opt in to google/textfsm#151 behaviour¶
textfsm2 defaults to textfsm 2.1.1 behaviour for non-participating alternation groups (see Compatibility). Opt in to upstream main branch behaviour per class/instance or process-wide:
Or set the environment variable before starting Python:
Validate templates in CI from the CLI¶
Compare a template and sample input against a golden FSM Table: output file:
Inside a uv project or installed environment:
uv run textfsm2 template.textfsm input.txt expected_table.txt
textfsm2 template.textfsm input.txt expected_table.txt
The command prints Data match! and exits 0 on success, prints Data mis-match! and exits 1 on mismatch, and exits 2 on invalid usage or template errors.