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")
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, use the Rust backend.
- Reference — the public API, the built-in core rules, the bundled grammars, and configuration knobs.
- Explanation — 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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file abnf-2.6.0.tar.gz.
File metadata
- Download URL: abnf-2.6.0.tar.gz
- Upload date:
- Size: 892.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
945c1377ef6dfc25ae19fd6d6eafe767e6cf8d3a9cbd3e4cd9ef715607ee2068
|
|
| MD5 |
0b2dfd75804047f0f284c187ea432436
|
|
| BLAKE2b-256 |
d44daf4d6dcf45c46df607a98893061774def46bd0cb86806c83e6a5dca2ed8a
|
Provenance
The following attestation bundles were made for abnf-2.6.0.tar.gz:
Publisher:
release.yml on declaresub/abnf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
abnf-2.6.0.tar.gz -
Subject digest:
945c1377ef6dfc25ae19fd6d6eafe767e6cf8d3a9cbd3e4cd9ef715607ee2068 - Sigstore transparency entry: 2201638045
- Sigstore integration time:
-
Permalink:
declaresub/abnf@665391e01e43d9c63ac5b5e6cb9cd9c3b60decc4 -
Branch / Tag:
refs/tags/v2.6.0 - Owner: https://github.com/declaresub
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@665391e01e43d9c63ac5b5e6cb9cd9c3b60decc4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file abnf-2.6.0-py3-none-any.whl.
File metadata
- Download URL: abnf-2.6.0-py3-none-any.whl
- Upload date:
- Size: 65.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e40aed8e105846ba91a566f6e0f6878cc6cae61218bc949ca05b3577bed92c6e
|
|
| MD5 |
bd08583b28abd5aa3e7d24fdffaa6ff5
|
|
| BLAKE2b-256 |
de948028411685a01df6c7159d4eb0dd4ef8e0bf6812ab2815e78ea4bdf61436
|
Provenance
The following attestation bundles were made for abnf-2.6.0-py3-none-any.whl:
Publisher:
release.yml on declaresub/abnf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
abnf-2.6.0-py3-none-any.whl -
Subject digest:
e40aed8e105846ba91a566f6e0f6878cc6cae61218bc949ca05b3577bed92c6e - Sigstore transparency entry: 2201638342
- Sigstore integration time:
-
Permalink:
declaresub/abnf@665391e01e43d9c63ac5b5e6cb9cd9c3b60decc4 -
Branch / Tag:
refs/tags/v2.6.0 - Owner: https://github.com/declaresub
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@665391e01e43d9c63ac5b5e6cb9cd9c3b60decc4 -
Trigger Event:
push
-
Statement type: