Documenting Python Projects with MkDocs
Introduction
Project Documentation is necessary. Very necessary, I would emphasize.
At the beginning of my career, I learned the hard way that a project must be documented.
Let's go back in time – to the 2000s – when I was working as a Customer Representative for large US companies. I was part of a team and my colleagues and I had joined the company around the same month. So, for a while, there was no need to worry because nobody was going on vacation just a few weeks or months after starting a new job.
However, after some time, it inevitably would happen. And we were all assigned to back up each other. That is when documentation started to play a major part in my career.
The day the first person took a few days off, I panicked! I got to work and I didn't know what to do or even where to start. The tasks kept coming and piling up while I was trying to figure out how to process them.
In the end, everything turned out well. I was able to figure it out and move on. But from that day on, I knew that documentation needed to be in place for any time off or team movement, like promotions or offboardings.
In this post, we will learn how to create a simple (and effective) project documentation using Mkdocs
in Python. The final result will look similar to MkDocs documentation.
Building The Documentation
mkdocs
is a module in Python that allows us to create simple web pages using Markdown language. The benefit is that it is highly customizable, and gives your documentation a professional look, besides easily integrating with GitHub.
Additionally, mkdocs
leverages Markdown notation language, which is very simple to use, being just plain text with the addition of a couple of signs to point titles, subtitles, bullet points, italic, bold etc. To illustrate, Medium uses Markdown language for blogging.
Markdown is a lightweight markup language for creating web formatted text using a plain-text editor.
Preparation
I believe that the best time to create the documentation is once we finish the project. At that point, we already know which modules were used, how it was deployed, and how the project can be started and maintained. So, it is time to document those steps for the users.
When documenting something, my experience tells me to:
- Describe it as if you were describing how to run the project to a complete layperson.
- Try to avoid highly technical terms, and acronyms used in your company.
- Describe each step using clear and simple language.
- If the concept is too dense, or the task is too complex, try breaking it down into bullets.
Before starting with the documentation, let's create a sample project real quick, using the module uv
for virtual environment management. Here, I am using uv
and VSCode.
- Open a terminal and install
uv
withpip install uv
- Create a new project name "p2":
uv init p2
- Change the directory to access the new folder:
cd p2
- Set the Python version for the project:
pyenv local 3.12.1
- Create a new virtual environment:
uv venv --python 3.12.1
- Activate the environment:
venv/Scripts/activate
- Add some packages:
uv add pandas, numpy, scikit-learn, streamlit

Getting Started
Having the project created, let's add mkdocs
.
# Install mkdocs
uv add mkdocs
Next, we will create a new documentation folder.
# create a new documentation folder in your project
mkdocs new .
That command will generate a docs folder and the files needed for the documentation.
- File
mkdocs.yml
: It is used to configure your documentation webpage, like title, theme, and site structure, like adding new tabs. - Folder docs with the file
index.md
: This file is where you will write the documentation itself.

If we want to look at our documentation, we already can. Just use the serve command.
# Open a local server to display the docs
mkdocs serve

Now, we can just copy + paste that HTTP into a browser (or Ctrl + click) to see how the documentation currently is.

Customization
It is time to customize our documentation.
Let's start by changing the Title of the documentation page. Open the mkdocs.yml
file. You will see only that site_name
title in the default file.

Let's change it.
site_name: P2 Project Documentation
We can add a new tab About
with the information about the project. For that to actually work, we also need to add a markdown file about.md
to the folder docs.
site_name: P2 Project Documentation
nav:
- Home: index.md
- About: about.md
And we can change the theme if we want to. Check for built-in available themes here. Or for installable themes gallery here.
site_name: P2 Project Documentation
nav:
- Home: index.md
- About: about.md
theme: mkdocs
Here is the result, so far.

Next, let us start writing the documentation. This should be done in a markdown file within the folder docs.
I will write the whole example documentation to the file index.md
and the project meta information will go to the file about.md
.
- File index.md
We will erase the sample text that is in there and write our documentation instead.
# P2 Project
This project is an example of how we can write a professional documentation using `mkdocs` module in Python.
To learn MarkDown notation, use this [Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Here-Cheatsheet).
---
## Python Version
This project was built using **Python 3.12.1**
---
## Modules
* mkdocs >= 1.6.1
* numpy >= 2.1.3
* pandas >= 2.2.3
* scikit-learn >= 1.5.2
* seaborn >= 0.13.2
* streamlit >= 1.40.1
---
## Quick Start
To create a documentation with MkDocs, these are the main bash commands:
* Install mkdocs: `pip install mkdocs`
* Create a new documentation folder: `mkdocs new .`
* `mkdocs.yml` is the file to customize the web page, such as creating tabs, changing titles and themes.
* The files in the folder **docs** are the ones to hold the documentation text, using MarkDown notation.
- File about.md
# About This Project
* **Author:** Your Name
* **Purpose:** Exemplify how to create a professional looking documentation for your projects using MarkDown notation in Python.
---
### Contact
Find me on [Linkedin](https://www.linkedin.com/in/profile)
The final result is this beautiful documentation site.

Adding Functions and Docstrings
MkDocs also has ability to pull functions and respective docstrings from the code. To do that, first add the module MkDocstrings-Python using pip install mkdocstrings-python
. In our case, I am using uv
.
uv add mkdocstrings-python
Next, adjust the mkdocs.yml
file to add the plugin. Add the following lines to the end of the file and save it.
plugins:
- mkdocstrings:
default_handler: python
Now, let's look at our code. In this example project, we have only the file hello.py
with two functions.

Adding them to the documentation is pretty simple. Use three :::
followed by the path to your file. Since this file is in the main folder of the project, we simply add the file_name.function
. If it is within a folder, you can use something like folder.file.function
.
### Function
These are the functions used in the code `hello.py`
::: hello.main_func
::: hello.calculations
After saving the file, we can look at the result mkdocs serve
.

Now let's deploy the docs.
Deploying
Deploying our documentation page is simple.
First, we must create a GitHub page for the project, if we already don't have one.
Next, go back to the IDE terminal and we will build our page with the next command. This command will create the folders and files necessary to deploy the documentation website.
mkdocs build
[OUT]:
INFO - Cleaning site directory
INFO - Building documentation to directory: C:MyDocumentstestesp2site
INFO - Documentation built in 0.06 seconds
Now, need to add the GitHub repository in the mkdocs.yml
file, so the module knows where to deploy the documentation to.

Then we open a Git Bash Terminal to initialize Git and commit.
# Initialize Git
git init
# Add the reference repository
git remote add origin https://github.com/gurezende/MkDocs-Example.git
# Add files from the project
git add .
# Commit the files
git commit -m "Project Code and documentation"
# Create Branch Main
git branch -M main
# Push files to GitHub
git push -u origin main
And then we can deploy the documentation with the following bash code in a Powershell terminal.
mkdocs gh-deploy
## Output ##
INFO - Cleaning site directory
INFO - Building documentation to directory: C:MyDocumentstestesp2site
INFO - Documentation built in 0.08 seconds
WARNING - Version check skipped: No version specified in previous deployment.
INFO - Copying 'C:MyDocumentstestesp2site' to 'gh-pages' branch and pushing to GitHub.
Enumerating objects: 39, done.
Counting objects: 100% (39/39), done.
Delta compression using up to 12 threads
Compressing objects: 100% (37/37), done.
Writing objects: 100% (39/39), 829.12 KiB | 11.68 MiB/s, done.
Total 39 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), done.
remote:
remote: Create a pull request for 'gh-pages' on GitHub by visiting:
remote: https://github.com/gurezende/MkDocs-Example/pull/new/gh-pages
remote:
To https://github.com/gurezende/MkDocs-Example.git
* [new branch] gh-pages -> gh-pages
INFO - Your documentation should shortly be available at: https://gurezende.github.io/MkDocs-Example/
Notice that on the last line, we have the URL where the documentation was deployed. This address can be added to your GitHub readme file.
After deployment, we just need to push the updates again to update GitHub, using the following commands on a Git Bash terminal.
git add .
git commit -m "Online documentation added"
git push origin main
That's it! The documentation is live!
From now on, every time we update the markdown files from our project and command mkdocs gh-deploy
, the web page is updated and our documentation stays up to date. Easy like that!

Before You Go
Documenting your projects is important.
After all, nobody knows what was in your head when you developed something. Therefore, documenting is like showing your line of thought, the steps used to reach an end.
Open a window in your mind to show other people how you created that product and how to use it.
MkDocs make it so easy and looks super professional. I am sure it will help a lot in documenting your projects at work, helping fellow colleagues to navigate your code, as well as positively impacting anyone who looks at your portfolio from now on.
If you liked this content, follow me for more.
GitHub Repository
Here is the GitHub Repository for this article.
GitHub – gurezende/MkDocs-Example: Creating documentation for Python Projects with mkdocs
Learn More
If you want to see this content in video, here's a product from my Gumroad page.