ABNF
ABNF generates parsers from ABNF grammars as described in 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 in production use since it was first written for parsing HTTP headers in a web framework.
Installation
pip install abnf
pip install 'abnf[rust]' # optional Rust backend, for substantially faster parsing
ABNF is tested with Python 3.10–3.14.
Quick start
from abnf.grammars import rfc7232
# parse an ETag header value
node, offset = rfc7232.Rule("ETag").parse('W/"moof"', 0)
print(node.value) # 'W/"moof"'
# validate a whole string against a rule (raises ParseError otherwise)
from abnf.grammars import rfc5322
rfc5322.Rule("address").parse_all("test@example.com")
# compile your own rule; the RFC 5234 core rules are always available
from abnf import Rule
greeting = Rule.create('greeting = "hello" SP 1*ALPHA')
greeting.parse_all("hello world")
Parsing bytes
abnf parses code points, so parse and parse_all take a str. To parse wire
data, decode it with latin-1 — that maps the 256 byte values onto U+0000–U+00FF
one to one, so a code point is exactly an octet and octet-oriented grammars behave
as their RFCs describe:
rfc7230.Rule("request-line").parse_all(raw.decode("latin-1"))
See What abnf parses for why the encoding is the caller's choice.
Documentation
Full documentation is hosted at abnf.readthedocs.io and follows the Diátaxis framework:
- Tutorial — Parse your first header, a ten-minute end-to-end walkthrough.
- How-to guides — validate input, extract values with visitors, load a grammar from a file, write your own grammar module, exclude matches from a rule, use the Rust backend.
- Reference — the public API, the built-in core rules, the bundled grammars, and configuration knobs.
- Explanation — what abnf parses (code points, not bytes), the combinator architecture, the two backends, alternation semantics, and how backtracking is kept in check.
To build the docs locally:
pip install -e '.[docs]'
sphinx-build -W docs docs/_build/html
Contributing
Set up a development environment with the dev extra:
pip install -e '.[dev]' # or: uv sync --extra dev
Run the test suite (skip the slower fuzz tests with --ignore=tests/fuzz):
pytest --cov-report term-missing --cov=abnf
Pre-commit hooks run ruff, pyright, check-manifest, and tox. Install them once with
pre-commit install. See the Explanation and How-to docs for working with the
Rust backend.
Third-party packages
- abnf-to-regexp — converts ABNF to a regular expression.
Release files for abnf 2.8.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| abnf-2.8.3.tar.gz | 969.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| abnf-2.8.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.0 MB
Release files / abnf-2.8.3.tar.gz
| Download URL | abnf-2.8.3.tar.gz |
|---|---|
| Size | 969.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f1da81d2347c838132ce416d299522d837c65e07a797cde68ae656475736f862
|
|
BLAKE2b-256 checksum How to use checksums |
841a2f07cb0c74884577753306593a3a35124c1e1b6753b07061198ff359ad74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 24, 2026.
Transparency logRelease files / abnf-2.8.3-py3-none-any.whl
| Download URL | abnf-2.8.3-py3-none-any.whl |
|---|---|
| Size | 69.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c5492ebe9c8f24294d0dd4ba0ce9c53f2142cf3bdbce0bb0420abd5dca354a57
|
|
BLAKE2b-256 checksum How to use checksums |
f76d8e025c263adf174f4e3251780764faefe5437a3f09d90ef8c87ed2a72216
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 24, 2026.
Transparency log