abnf¶
abnf generates parsers from ABNF grammars (RFC 5234 and RFC 7405). Its main purpose is parsing data specified in RFCs — HTTP headers, email addresses, URIs, and the like — but it handles any ABNF grammar. It ships with 30+ ready-to-use grammar modules for common RFCs and has been used in production since it was first written for parsing HTTP headers in a web framework.
from abnf.grammars import rfc7232
node, _ = rfc7232.Rule("ETag").parse('W/"moof"', 0)
Installation¶
pip install abnf
pip install 'abnf[rust]' # optional Rust backend, for substantially faster parsing
See Use the Rust backend for what the [rust] extra buys you.
The documentation¶
This documentation follows the Diátaxis framework — four kinds of material, each answering a different need:
Tutorial — learning-oriented. Start here if you are new: build a working parser end to end.
How-to guides — task-oriented recipes for specific goals: validate input, walk a parse tree, load a grammar from a file, write your own grammar module, use the Rust backend.
Reference — information-oriented. The public API, the built-in core rules, the bundled grammars, and configuration knobs.
Explanation — understanding-oriented discussion: the combinator architecture, the two backends, alternation semantics, and how backtracking is kept in check.