API Reference¶
This reference is generated automatically from docstrings via mkdocstrings. See the Quickstart for a narrative walkthrough.
Functions¶
Public Python API: sample -> template, records, ast, canonical/readable DSL.
DSLResult(ast=TemplateAST(), canonical='', readable='', recognizers=list(), reason='', ready=False)
dataclass
¶
Bases: Serializable
Result of compiling a template into ast/canonical/readable/recognizers.
Attributes:
| Name | Type | Description |
|---|---|---|
ast |
TemplateAST
|
The parsed template AST (an empty |
canonical |
str
|
The canonical (regex-expanded) TextFSM template. |
readable |
str
|
The human-readable DSL form of the template. |
recognizers |
List[str]
|
Regex patterns that detect this block of text. |
reason |
str
|
Failure reason if |
ready |
bool
|
True if compiling succeeded. |
LLMResult(template='', records=list(), variables=dict(), handling=list(), reason='', ready=False)
dataclass
¶
Bases: Serializable
Result of asking an LLM to turn a sample into a template.
Attributes:
| Name | Type | Description |
|---|---|---|
template |
str
|
The LLM-authored TextFSM template ("" if generation failed). |
records |
List[Dict[str, str]]
|
Records the LLM claims to have parsed from the sample. |
variables |
Dict[str, str]
|
Per-variable explanations the LLM provided. |
handling |
List[str]
|
Notes on how the LLM handled ambiguous or edge-case lines. |
reason |
str
|
Failure reason if |
ready |
bool
|
True if generation succeeded. |
ValidationResult(data=None, args=None, kwargs=None, reason='', ready=False)
dataclass
¶
Bases: Serializable
Generic pass/fail validation outcome.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
Optional[Any]
|
The value that was validated (e.g. the template string, for
|
args |
Optional[list]
|
Reserved for callers that validate against positional inputs;
unused by |
kwargs |
Optional[dict]
|
Reserved for callers that validate against keyword inputs;
unused by |
reason |
str
|
Failure reason if |
ready |
bool
|
True if validation succeeded. |
DeliveryOutput(mode, output='', passed=False, error='')
dataclass
¶
Formatted result of running the full generate + compile pipeline.
Attributes:
| Name | Type | Description |
|---|---|---|
mode |
DeliveryMode
|
The verbosity mode |
output |
str
|
The formatted text (or JSON, if |
passed |
bool
|
True if the pipeline succeeded. |
error |
str
|
Failure detail if |
TemplateAST(values=list(), states=list())
dataclass
¶
Parsed representation of a TextFSM/DSL template.
Attributes:
| Name | Type | Description |
|---|---|---|
values |
List[ValueNode]
|
The |
states |
List[StateNode]
|
The states (each with its rules) parsed from the template. |
parse_to_dicts(template, sample)
¶
Parse sample with a TextFSM template, returning rows as dicts.
Source code in textfsm_ai/core/utils/template.py
22 23 24 25 | |
parse_to_lists(template, sample)
¶
Parse sample with a TextFSM template, returning rows of raw values.
Source code in textfsm_ai/core/utils/template.py
16 17 18 19 | |
validate_template(template)
¶
Validate that a TextFSM template is non-empty and syntactically valid.
Source code in textfsm_ai/core/utils/template.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
generate(sample, provider, api_key, model, *, endpoint='', api_version='', region='', project='', compartment_id='', max_retries=1, **kwargs)
¶
Ask an LLM to turn a sample into a template, parsed records, variable explanations, and handling notes. Never raises.
Source code in textfsm_ai/api.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
to_llm_result(sample, provider, api_key, model, *, endpoint='', api_version='', region='', project='', compartment_id='', max_retries=1, **kwargs)
¶
Alias of generate() — the full LLM result object.
Source code in textfsm_ai/api.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
to_llm_template(sample, provider, api_key, model, *, endpoint='', api_version='', region='', project='', compartment_id='', max_retries=1, **kwargs)
¶
LLM template string, or the failure reason if generation didn't succeed.
Source code in textfsm_ai/api.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
to_llm_records(sample, provider, api_key, model, *, endpoint='', api_version='', region='', project='', compartment_id='', max_retries=1, **kwargs)
¶
LLM-parsed records, or [] if generation didn't succeed.
Source code in textfsm_ai/api.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
to_llm_variables(sample, provider, api_key, model, *, endpoint='', api_version='', region='', project='', compartment_id='', max_retries=1, **kwargs)
¶
LLM variable explanations, or {} if generation didn't succeed.
Source code in textfsm_ai/api.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
to_llm_handling(sample, provider, api_key, model, *, endpoint='', api_version='', region='', project='', compartment_id='', max_retries=1, **kwargs)
¶
LLM handling notes, or [] if generation didn't succeed.
Source code in textfsm_ai/api.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
compile_dsl(template, records)
¶
Compile a template into its ast, canonical template, readable DSL, and recognizers. Never raises.
Source code in textfsm_ai/api.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
to_dsl_result(template, records)
¶
Alias of compile_dsl() — the full DSL result object.
Source code in textfsm_ai/api.py
275 276 277 | |
to_ast(template, records)
¶
AST, or an empty TemplateAST() if the template failed to compile.
Source code in textfsm_ai/api.py
280 281 282 283 | |
to_canonical(template, records)
¶
Canonical TextFSM template string, or the failure reason if compiling failed.
Source code in textfsm_ai/api.py
286 287 288 289 | |
to_readable(template, records)
¶
Human-readable DSL string, or the failure reason if compiling didn't succeed.
Source code in textfsm_ai/api.py
292 293 294 295 | |
to_recognizers(template, records)
¶
Recognizer regex patterns, or [] if compiling didn't succeed.
Source code in textfsm_ai/api.py
298 299 300 301 | |
run_pipeline(sample, provider, api_key, model, *, endpoint='', api_version='', region='', project='', compartment_id='', mode='default', as_json=False, max_tries=1)
¶
Full pipeline: sample -> template, records, ast, canonical, readable,
recognizers — packaged per mode ("quiet"/"default"/"info"/"debug").
Never raises for a failed run: check .passed/.error on the result.
Source code in textfsm_ai/api.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
Result types¶
Result types returned by the functions in :mod:textfsm_ai.api.
LLMResult
dataclass
¶
Bases: Serializable
Result of asking an LLM to turn a sample into a template.
Attributes:
| Name | Type | Description |
|---|---|---|
template |
str
|
The LLM-authored TextFSM template ("" if generation failed). |
records |
List[Dict[str, str]]
|
Records the LLM claims to have parsed from the sample. |
variables |
Dict[str, str]
|
Per-variable explanations the LLM provided. |
handling |
List[str]
|
Notes on how the LLM handled ambiguous or edge-case lines. |
reason |
str
|
Failure reason if |
ready |
bool
|
True if generation succeeded. |
Source code in textfsm_ai/api_models.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
DSLResult
dataclass
¶
Bases: Serializable
Result of compiling a template into ast/canonical/readable/recognizers.
Attributes:
| Name | Type | Description |
|---|---|---|
ast |
TemplateAST
|
The parsed template AST (an empty |
canonical |
str
|
The canonical (regex-expanded) TextFSM template. |
readable |
str
|
The human-readable DSL form of the template. |
recognizers |
List[str]
|
Regex patterns that detect this block of text. |
reason |
str
|
Failure reason if |
ready |
bool
|
True if compiling succeeded. |
Source code in textfsm_ai/api_models.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |