# Converting HTML files to RST via PyPandoc Python Library

L**et's** see a procedure to convert HTML to RST file using the PyPandoc library by using Python.

An RST file is a document that contains code that is written in the reStructuredText markup language. The reStructuredText is used to apply basic styles and format the plain texts. They are used mostly for technical documentation of python programs.

In order to convert the documents into RST files, we will be using the following **2 approaches:**

1. Using Pandoc
    
2. Using Python code to convert an HTML file to an RST file.Using python code for file conversion:
    

### 1\. Using Pandoc:

Pandoc is a document conversion utility that is used to convert various files into different formats. In this article, we will be converting an Html file to an RST file.

So first we will convert a single HTML file to an RST file using the following steps:

1. Open the terminal in your system
    
2. Navigate the directory where the file that you wish to convert is stored. You can refer to the following link to know basic command prompt commands
    

[https://www.digitalcitizen.life/command-prompt-how-use-basic-commands/](https://www.digitalcitizen.life/command-prompt-how-use-basic-commands/)

3\. Now the next step is to run the following command in the terminal :

`C:\Users\lenovo> pandoc filename –o newname`

where the **filename** = name of the file that you wanted to convert and **newname** = name that you wish to give to the converted file.

for example:

`filename = file to convert for eg mytext.html`

`newname = new file name for eg mytext.rst (we are converting from Html to rest)`

It will look like the following screenshot :

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703051634022/aea0ccab-2acb-4049-a31e-8fc385f137cd.png align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703051635555/ca16206a-c461-4f02-a315-51dee52a0e89.png align="left")

4\. Finally you can see that the HTML file has been converted to an RST file.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703051636842/6af55358-c166-4858-81ea-f27f0430bd97.png align="left")

* Now we will be converting multiple HTML files to RST files using the pandoc library.
    

In order to use the pandoc library, we need to first install it. We can use the following command to install pandoc for python:

`C:\Users\lenovo>pip install pypandoc`

Now, the next step is to write the following in your python code:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703051638185/c477c69b-cbd3-41cc-8f98-924724efa31d.png align="left")

After executing the above code, all the files in that folder will get converted to RST files.

In this way, it becomes much easier to convert all files from a folder to another format using python. It becomes easier than following the terminal way when you have multiple files to convert.

### 2\. Using python code to convert all the files to RST files:

This approach is similar to the previous approach just the difference is, that here the code is not using the pypandoc library.

Write the following code for converting the file to RST format.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703051639426/4f743356-0e9d-40bd-87dc-9e779e919551.png align="left")

As we can see in the output we got the command to execute for each file.

To use the code, just refer [here](https://github.com/aniforverizon/Pypandoc/blob/main/panodc.ipynb).

Now, we can just copy the output and paste it into a terminal and all commands are executed. We have all our .rst files converted from .html files.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703051640734/ce42323e-ab41-4d55-90ac-4e0881fc1be9.png align="left")

**For any further Queries or anything related to Python Development ,Coding, Blogging, Tech Documentation you can DM me on** [**Linkedin**](https://in.linkedin.com/in/anubhav-chaturvedi-a7465a72) **or instagram id=**[**acanubhav94**](http://instagram.com/acanubhav94)**.**

**Special credits to my team members:** [**Siddhid**](https://www.linkedin.com/in/siddhid-gopujkar-209716188/) **and** [**Anshika**](https://www.linkedin.com/in/anshika-yadav-0a69381b7/)
