Skip to main content

ABNF

PyPI abnf-tox CodeQL Docs

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:

  • TutorialParse 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

abnf-2.6.0.tar.gz (892.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

abnf-2.6.0-py3-none-any.whl (65.3 kB view details)

Uploaded Python 3

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

Hashes for abnf-2.6.0.tar.gz
Algorithm Hash digest
SHA256 945c1377ef6dfc25ae19fd6d6eafe767e6cf8d3a9cbd3e4cd9ef715607ee2068
MD5 0b2dfd75804047f0f284c187ea432436
BLAKE2b-256 d44daf4d6dcf45c46df607a98893061774def46bd0cb86806c83e6a5dca2ed8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for abnf-2.6.0.tar.gz:

Publisher: release.yml on declaresub/abnf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for abnf-2.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e40aed8e105846ba91a566f6e0f6878cc6cae61218bc949ca05b3577bed92c6e
MD5 bd08583b28abd5aa3e7d24fdffaa6ff5
BLAKE2b-256 de948028411685a01df6c7159d4eb0dd4ef8e0bf6812ab2815e78ea4bdf61436

See more details on using hashes here.

Provenance

The following attestation bundles were made for abnf-2.6.0-py3-none-any.whl:

Publisher: release.yml on declaresub/abnf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page