Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Using MarkItDown

00:00 Okay, it’s time to use MarkItDown. For starters, you can download the materials for this course by clicking on the Supporting Material button below. After that, you should be able to find the following files under the data subdirectory.

00:15 You have different formats like CSV, Excel, PDF, and so on. Your first goal is converting the employees Excel file into Markdown. You can see the Excel file here.

00:28 You have columns First Name, Last Name, Department, Position, and Start Date. Okay, let’s go ahead and start your first challenge, which is converting employees.xlsx into Markdown using MarkItDown.

00:44 Inside of the directory MARKITDOWN_REALPYTHON, I’ve created convert_files.py. You can see that my data is also here. The first thing you need to do is import the MarkItDown class from the markitdown package. from markitdown import MarkItDown.

01:05 Pay attention that the first markitdown, so from markitdown, is all lowercase, but import MarkItDown, you need to capitalize M, I, and D.

01:18 Then you need to create an instance of the MarkItDown class and store it in the variable md. So md equals MarkItDown.

01:28 Pay attention that M, I, and D are capitalized, and open close parentheses. You can think of md as your converter object. You’ll call its methods whenever you want to convert a file.

01:40 And now you can call the .convert() method on the converter and store it in result. So result equals md.convert(), and then inside of the parentheses, you need to put the path of the file you want to convert.

01:57 For you, it’s the employees.xlsx inside of the data subfolder in your root directory. So open close quotes, ./data/employees.xlsx, and then close the quotes.

02:18 And finally, you want to access the Markdown text stored inside the result using .markdown, and you can print it afterwards. So print(result.markdown).

02:31 Okay, perfect. Now we can go to the terminal and run this. So python convert_files.py.

02:43 And here you go. You have the same columns that you saw before. You have successfully created an .md file out of the Excel sheet.

02:53 Well done. You just converted your first file using MarkItDown. Here’s a challenge for you. What if you wanted to batch-convert files in several different formats using the same script?

03:04 And here’s a hint for you. You’ll need both MarkItDown and Python’s pathlib library. Whenever you come up with your solution, you can test it out using the files from the course materials you downloaded earlier, except for the PNG files.

03:18 You’ll deal with the PNG files in the next lessons. You’ll also find a sample solution called batch_converter.py in the course materials. Try writing your own solution first and then check it out.

03:30 Okay, now you understand how and why to use the MarkItDown library. But what if you wanted to use MarkItDown while chatting with an LLM like Claude? In the next lesson, you’ll learn how to connect the MarkItDown MCP server to your LLM.

Become a Member to join the conversation.