| Crates.io | textfsm-rs |
| lib.rs | textfsm-rs |
| version | 0.3.6 |
| created_at | 2026-01-10 06:19:03.294885+00 |
| updated_at | 2026-01-16 05:46:33.161626+00 |
| description | A Rust implementation of TextFSM |
| homepage | |
| repository | https://github.com/itsvrushabh/textfsm-rs |
| max_upload_size | |
| id | 2033577 |
| size | 178,019 |
A robust, performant, and safe Rust implementation of TextFSM. This library is designed to parse semi-structured text—specifically output from networking device CLI commands—into structured programmatic data (JSON, YAML, or Rust HashMaps).
Result handling.serde for serialization and pest for reliable template parsing.Value definitions (Filldown, Key, Required, List, Fillup), States, Rules, and Transitions.fancy-regex to support Python-style features like lookahead and lookbehind.CliTable logic to automatically select the right template based on device platform and command.unwrap() and panic!, ensuring your automation tools stay up.Add this to your Cargo.toml:
[dependencies]
textfsm-rs = "0.3.5" # Check crates.io for the latest version
use textfsm_rs::{TextFSM, DataRecordConversion};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. Initialize the FSM with a template
let mut fsm = TextFSM::from_file("templates/cisco_ios_show_version.textfsm")?;
// 2. Parse your CLI output
let records = fsm.parse_file("data/show_version.txt", Some(DataRecordConversion::LowercaseKeys))?;
// 3. Use the structured data
for record in records {
if let Some(version) = record.fields.get("Version") {
println!("Device Version: {}", version);
}
}
Ok(())
}
You can use textfsm-rs as a standalone command-line tool.
cargo install textfsm-rs
Parse a single file:
textfsm parse --template templates/cisco_ios_show_version.textfsm --input data/show_version.txt --format json
Auto-detect template (using ntc-templates index):
textfsm auto --index ntc_templates/templates/index --platform cisco_ios --command "show version" --input data/show_version.txt
Using the ntc-templates index style:
use textfsm_rs::CliTable;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let index = CliTable::from_file("ntc_templates/templates/index")?;
// Automatically find the template for a Cisco command
if let Some((dir, row)) = index.get_template_for_command("cisco_ios", "sh version") {
println!("Match found! Template: {}/{}", dir, row.templates[0]);
}
Ok(())
}
Contributions are welcome! Please ensure all tests pass:
cargo test
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.