Specs API Reference
specs
Core spec system for texer - glom-style specs with type checking.
Spec
Bases: ABC
Base class for all specs. Specs are lazy evaluation descriptors.
Source code in src/texer/specs.py
Ref
dataclass
Bases: Spec
Reference to a data path using glom-style dot notation.
Examples:
Ref("name") -> data["name"]
Ref("user.email") -> data["user"]["email"]
Ref("items.0.value") -> data["items"][0]["value"]
Source code in src/texer/specs.py
resolve(data, scope=None)
Resolve the reference path against data.
Source code in src/texer/specs.py
Comparison
dataclass
Bases: Spec
A comparison expression for use in Cond.
Source code in src/texer/specs.py
resolve(data, scope=None)
Evaluate the comparison.
Source code in src/texer/specs.py
And
dataclass
Or
dataclass
Iter
dataclass
Bases: Spec
Iterate over a collection, applying a template to each item.
Examples:
Iter(Ref("items"), template=Row(Ref("name"), Ref("value"))) Iter(Ref("points"), x=Ref("x"), y=Ref("y")) # For coordinates Iter(Ref("points"), x=Ref("x"), y=Ref("y"), marker_size=Ref("size")) # With marker sizes
Source code in src/texer/specs.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 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 188 189 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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
resolve(data, scope=None)
Resolve by iterating over source and applying template.
Source code in src/texer/specs.py
Format
dataclass
Bases: Spec
Format a value using Python format specification.
Examples:
Format(Ref("value"), ".2f") -> f"{value:.2f}" Format(Ref("pct"), ".1%") -> f"{pct:.1%}" Format(Ref("num"), "04d") -> f"{num:04d}"
Source code in src/texer/specs.py
resolve(data, scope=None)
Resolve and format the value.
Source code in src/texer/specs.py
FormatNumber
dataclass
Bases: Spec
Format numbers with advanced options for significant digits, thousands separators, and more.
Handles the -0.00 case by removing the minus sign. Strings pass through unchanged by default.
Examples:
FormatNumber(Ref("value"), sig=2) -> "1.2" for 1.234 FormatNumber(Ref("value"), decimals=2) -> "1.23" for 1.234 FormatNumber(Ref("large_num"), thousands_sep=True) -> "2,000" for 2000 FormatNumber(Ref("value"), sig=2, thousands_sep=",") -> "1,200" for 1234
Source code in src/texer/specs.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 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 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
resolve(data, scope=None)
Resolve and format the value.
Source code in src/texer/specs.py
Cond
dataclass
Bases: Spec
Conditional logic - returns one value or another based on condition.
Examples:
Cond(Ref("x") > 5, "red", "blue") Cond(Ref("active"), "\checkmark", "")
Source code in src/texer/specs.py
resolve(data, scope=None)
Evaluate condition and return the selected branch (not resolved).
Note: This returns the branch itself, not its resolved value. This allows Raw and other special specs to be handled properly by the evaluation layer.
Source code in src/texer/specs.py
Literal
dataclass
Bases: Spec
A literal value that doesn't need resolution.
Examples:
Literal("some text") Literal(42)
Source code in src/texer/specs.py
Raw
dataclass
Bases: Spec
Raw LaTeX code that should not be escaped.
Works universally in any context: as a plot item, row element, cell content, etc.
Examples:
Raw(r"\textbf{bold}") Raw(r"\hline") Raw(r"\draw (0,0) -- (1,1);") # In a plot Raw(r"\cmidrule{2-4}") # In a table
Source code in src/texer/specs.py
Call
dataclass
Bases: Spec
Call a function with resolved arguments.
Examples:
Call(len, Ref("items")) Call(max, Ref("values"))
Source code in src/texer/specs.py
Join
dataclass
Bases: Spec
Join multiple specs with a separator.
Examples:
Join([Ref("first"), Ref("last")], " ")
Source code in src/texer/specs.py
resolve_value(value, data, scope=None)
Resolve a value which may be a Spec or a plain value.