reStructuredText | .rst file to HTML file using Python for documentation

reStructuredText — it is a file format for text data that is mainly used by Python-based communities to develop documentation in a simple way similar to other tools like Javadoc for Java. Most Python-based software and library documents are written using reStructuredText, and therefore important to study when working in any organization.

Like Python, RST syntax is also sensitive to indentation.

Sample reStructuredText code:
Some basic HTML syntax and rendering are shown below.


usage syntax HTML rendering
Heading *****


italic * italic *

bold ** bold ** bold
link `gfg & lt; & gt; `
verbatim `` Some text or code``

 Some text or code 


************************* *****
This is example of rst on GFG
****** *************************

* Python.Engineering in italic *

** Python.Engineering in bold **

`Gfg website & lt; www. & gt; `

`` Python.Engineering in vebatim``

Save the file with the extension .rst .

Python code:

Below is the Python code for converting files. rst to HTML files.  docutils — it is a predefined library loaded during Python installation. The publish_file method is used to convert the first to HTML, passing the filenames as parameters.

import docutils.core

docutils.core.publish_file (

source_path = "restructured.rst" ,

destination_path = " Output.html " ,

writer_name = " html " )

After running the Python code, the HTML file will be generated in the same directory as as the first file. HTML is more complex than normal human-written HTML because it is generated automatically. The following image shows the HTML rendering of the reStructuredText shown above.