A Python library for parsing and editing RFC (Request for Comments) TXT documents.
- Parse RFC TXT documents and extract all sections
- Download RFCs directly from rfc-editor.org
- Edit all RFC document sections including:
- Title
- Abstract
- Status of This Memo
- Copyright Notice
- Table of Contents
- Numbered sections (1., 2., etc.)
- Acknowledgements
- Contributors
- Author's Address
- Add, update, and delete sections
- Save modified documents back to TXT format
pip install rfc-editorOr install from source:
pip install -e .from rfc_editor import RFCEditor
editor = RFCEditor()
doc = editor.load("rfc1234.txt")
# Or parse from string
doc = editor.parse(rfc_content_string)print(doc.rfc_number) # RFC number
print(doc.category) # e.g., "Standards Track"
print(doc.title) # RFC title
print(doc.abstract) # Abstract content# Get title
title = editor.get_title()
# Get abstract
abstract = editor.get_abstract()
# Get status of this memo
status = editor.get_status_of_memo()
# Get copyright (returns tuple of year and holders)
year, holders = editor.get_copyright()
# Get table of contents
toc = editor.get_toc()
# Get acknowledgements
acknowledgements = editor.get_acknowledgements()
# Get contributors
contributors = editor.get_contributors()
# Get author's address
address = editor.get_authors_address()
# Get section by title (returns RFCSection or None)
section = editor.get_section_by_title("Introduction")# Edit title
editor.set_title("New Title")
# Edit abstract
editor.set_abstract("New abstract content...")
# Edit status
editor.set_status_of_memo("New status content...")
# Edit copyright
editor.set_copyright(2024, "Example Corp")
# Edit TOC
editor.set_toc("1. Introduction\n2. Body")
# Update a numbered section
editor.update_section("1", content="Updated introduction content...")
# Add a new section
editor.add_section("5", "New Section", "Section content...")
# Delete a section
editor.delete_section("1")
# Edit by section title
editor.set_section_by_title("Introduction", "New content...")editor.save("output.txt")data = editor.to_dict()
print(data["title"])
print(data["sections"])
print(data["rfc_number"])
print(data["category"])from rfc_editor import download_rfc
# Download RFC directly as string
content = download_rfc(791)
# Download and save to file
download_rfc(791, "rfc791.txt")Or use the editor's download method:
from rfc_editor import RFCEditor
editor = RFCEditor()
doc = editor.download(791) # Download and parse
# Download and save to file first
doc = editor.download(791, "rfc791.txt")# Direct access to document attributes
print(doc.rfc_number) # RFC number (e.g., "791")
print(doc.category) # e.g., "Standards Track"
print(doc.title) # RFC title
print(doc.abstract) # Abstract content
print(doc.index) # Index section (if present)
# Access authors
for author in doc.authors:
print(author.name)
print(author.organization)
print(author.email)
print(author.address)
# Get section by number
section = doc.get_section("1")
print(section.number, section.title, section.content)# Update only the title of a section
editor.update_section("1", title="New Introduction Title")
# Update both title and content
editor.update_section("1", title="New Title", content="New content...")pip install -e ".[dev]"pytest tests/flake8 src/ tests/
ruff check src/ tests/
black --check src/ tests/rfc-editor/
├── src/
│ └── rfc_editor/
│ └── __init__.py # Main library code
├── tests/
│ ├── test_author.py
│ ├── test_document.py
│ ├── test_editor.py
│ └── test_section.py
├── pyproject.toml
├── README.md
├── .gitignore
└── SPEC.md
MIT