Typing Stubs for docutils

0.22.3.20260408 · active · verified Thu Apr 09

types-docutils provides high-quality type hints and stub files for the docutils library, enabling static type checkers like MyPy to validate code that uses docutils. It's part of the typeshed project, which maintains external type stubs for various popular Python packages. The current version is 0.22.3.20260408, with releases tied to updates in typeshed.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic usage of the docutils library. When types-docutils is installed, a static type checker like MyPy can analyze this code for type consistency and errors, ensuring that docutils functions are called with correct arguments and their return values are handled appropriately.

import os
from docutils.core import publish_string

# Example RST document
rst_document: str = """
.. role:: red
  :red:`This is red text.`

  .. admonition:: Note
    This is an admonition block.
"""

# publish_string is a core docutils function to process RST
# With types-docutils installed, type checkers can validate the arguments and return type.
html_output: str = publish_string(
    source=rst_document,
    writer_name="html",
    settings_overrides={'initial_header_level': 2}
)

print("Generated HTML snippet (first 200 chars):\n", html_output[:200])

# To see type checking in action, save this to 'app.py'
# and run 'mypy app.py' after 'pip install types-docutils docutils mypy'.
# Introduce a deliberate error, e.g., 'writer_name=123', and mypy will flag it.

view raw JSON →