Skip to main content

A Python library to parse and edit RFC TXT documents

Project description

RFC Editor Library

A Python library for parsing and editing RFC (Request for Comments) TXT documents.

Features

  • Parse RFC TXT documents and extract all sections
  • 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

Installation

pip install rfc-editor

Or install from source:

pip install -e .

Usage

Parse an RFC Document

from rfc_editor import RFCEditor

editor = RFCEditor()
doc = editor.load("rfc1234.txt")

# Or parse from string
doc = editor.parse(rfc_content_string)

Access Document Sections

print(doc.rfc_number)  # RFC number
print(doc.category)   # e.g., "Standards Track"
print(doc.title)      # RFC title
print(doc.abstract)  # Abstract content

Query Sections

# 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 Sections

# 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...")

Save the Document

editor.save("output.txt")

Convert to Dictionary

data = editor.to_dict()
print(data["title"])
print(data["sections"])

Development

Install Dev Dependencies

pip install -e ".[dev]"

Run Tests

pytest tests/

Run Linting

flake8 src/ tests/
ruff check src/ tests/
black --check src/ tests/

Project Structure

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

Version

0.1.0.1

License

MIT

Project details


Download files

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

Source Distribution

rfc_editor-0.1.0.3.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

rfc_editor-0.1.0.3-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file rfc_editor-0.1.0.3.tar.gz.

File metadata

  • Download URL: rfc_editor-0.1.0.3.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rfc_editor-0.1.0.3.tar.gz
Algorithm Hash digest
SHA256 435fb7d402b5fb186a2482d27ccb32835e41523a09569240aa63534b4e945a7f
MD5 7f192c3380af760f09226241d1092ec7
BLAKE2b-256 9a3dfb76a11ca8e9a67b932609ea68dd4b1bb2c03164cfa6dc48bfcd8b0d9df2

See more details on using hashes here.

Provenance

The following attestation bundles were made for rfc_editor-0.1.0.3.tar.gz:

Publisher: pypi-publish.yml on daedalus/rfc-editor

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

File details

Details for the file rfc_editor-0.1.0.3-py3-none-any.whl.

File metadata

  • Download URL: rfc_editor-0.1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rfc_editor-0.1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6952aea8cd6fb22d285a3037323002bb6705b81f5b25c612bca32bbe3228693c
MD5 628eb931f3835e9b7a21bd4cc14af2b2
BLAKE2b-256 56ad3e0e6ca054a89ce17a2def8486f6ebdb35d1ab195060f2ecdedeafcf8d5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for rfc_editor-0.1.0.3-py3-none-any.whl:

Publisher: pypi-publish.yml on daedalus/rfc-editor

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