Automatic Python Code Documentation with Auto Codebase Documenter

5/5 - (30 votes)

Who has never been too lazy to document their code?

Auto Codebase Documenter is a tool you’ll love as it leverages the power of OpenAI’s GPT-3.5-turbo or GPT-4 to automatically evaluate and document the code you’ve written!

Great, right?

Basically, instead of spending hours documenting the structure and functionalities of your project, you will be able to take advantage of the last sunny days of the year since the tool takes care of everything for you. To paraphrase Sun Tzu in The Art of War: “The best documentation is that which generates itself.”

To start using Auto Codebase Documenter, simply install the package from PyPI via the pip command like this:

pip install auto-codebase-documenter

You will also need to set up a suitable Python environment. I strongly suggest using a virtual environment (venv). Here’s how to do it:

  1. Install Python 3.9.16 or higher.
  2. Check your Python version by running python --version or python3 --version.
  3. Create a virtual environment in the root directory using the command python -m venv venv.
  4. Activate this environment with “source venv/bin/activate” (Unix or MacOS) or “venv\Scripts\activate” (Windows).
  5. Install the necessary dependencies via the command “pip install -r requirements.txt”.

Don’t forget, you’ll also need an OpenAI API key to run queries on their AI model.

Once you have installed and configured everything you need, it will then be time to let Auto Codebase Documenter do its magic! You can use it from the command line or directly as a lib for your project. Simply import the class AutoCodebaseDocumenter and run it with the method process_all_files.

import os
from dotenv import load_dotenv 
from auto_codebase_documenter.AutoCodebaseDocumenter import AutoCodebaseDocumenter

openai_api_key = os.getenv("OPENAI_KEY")

documenter = AutoCodebaseDocumenter(openai_api_key)

And that’s it, the tool will take care of the rest!

You can customize the documentation process by editing the documenter_config.yaml file and change different settings there such as code path, folders to ignore, file types to include, and much more.

One of the best things about this tool is how it organizes and structures generated Markdown (.md) files into a dedicated directory called docs. The structure of the “docs” directory exactly reflects that of your project. So each processed file corresponds to a specific Markdown file! This saves a lot of time and obviously makes your project easier to read and understand.

So, with such clear and well-organized documentation, any new developers joining your project will be able to get to work much faster. And for seasoned developers who want to get started with a code review or refactoring process, this will make things a lot easier to understand.

Finally, for those who like working with Docker, simply use the provided Dockerfile and docker-compose.yml files, and build the container using the command bash You can then run it with the command bash

Discover it here.

Mohamed SAKHRI

I am Mohamed SAKHRI, the creator and editor-in-chief of Easy Tech Tutorials. Being a dedicated technology enthusiast, I have been blogging for a considerable time, offering practical and beneficial guides for different operating systems like Windows, Linux, and macOS, alongside Android tips and tricks. I also delve into WordPress-related topics. I am presently 35 years old.

Leave a Comment