Skip to main content

Generate markdown API documentation for Google-style Python docstring.

Project description

docsai

Generate markdown API documentation for Google-style Python docstring.

Getting StartedFeaturesDocumentationSupportContributionChangelog

DocsAI makes it easy to generate beautiful markdown documentation for your Python API (see this example). It provides a simple command-line interface as well as a Python API to get full-fledged API documentation within seconds based on all of the Google-style docstrings in your code. This markdown documentation can be pushed to Github or integrated into your MkDocs site.

Highlights

  • ⏱  Simple CLI to generate markdown docs in seconds.
  • 📋  Supports Google-style Python Docstrings.
  • 📚  Compatible with Github Markdown and MkDocs.

Getting Started

Installation

Requirements: Python 3.6+.

pip install docsai

Usage

To generate Markdown-based API documentation for your Python project, simply execute:

docsai path/to/your/package

The path can be either a python package (folder) or a specific script. You can also specify one or multiple module-, class- or function-imports:

docsai my_package.AwesomeClass

With the default configuration, the Markdown documentation will be generated inside the ./docs folder in your working directory. You can find additional configuration options in the documentation section.

Type Channel
🚨  Bug Reports
🎁  Feature Requests
👩‍💻  Usage Questions
🗯  General Discussion
❓  Other Requests

Features

Source Code LinkingAPI OverviewMKDocs IntegrationDocstyle ValidationPrint to Console

Source Code Linking

DocsAI is capable to insert a badge on the right side of every module, class, method or function with a link the correct source-code file and line number. The default configuration will create relative paths to navigate within the Github Repo. This is useful if the documentation is hosted within the same repository as the source-code. If, the documentation is hosted outside of the Github repository, it is recommended to set the src-base-url:

docsai --src-base-url="https://github.com/example/my-project/blob/main/" my_package

The src-base-url is used as a prefix for all source-code linkings in the documentation.

API Overview

An API overview might be very useful in case your project has a large number modules, classes and functions. You can specify an overview-file with the docsai command to activate the generation of an API overview:

docsai --overview-file="README.md" my_package

The API overview will be written as markdown to the specified file with separated lists for all modules, classes, and functions of your project:

MkDocs Integration

The markdown documentation generated by docsai can be easily integrated into your mkdocs documentation site:

  1. Generate the markdown documentation into a subfolder (e.g. api-docs) inside your mkdocs documentation. We recommend to use the overview-file option and set the source-code URL via src-base-url, otherwise the source-code linking would not work:
docsai \
    --output-path="./docs/api-docs" \
    --overview-file="README.md" \
    --src-base-url="https://github.com/example/my-project/blob/main/" \
    my_package
  1. Install and apply the awesome-pages mkdocs plugin. This enables mkdocs to automatically discover and include all markdown files. The alternative would be to manually include all generated markdown files in the navigation section of the mkdocs.yaml. In order to use the awesome-pages plugin you need to 1) install the plugin via pip 2) Include it in the plugin section mkdocs.yaml and remove the navigation section (needs to be handled with .pages files).

  2. If you used the overview-file option, a .pages file will be automatically created. You can also manually create the .pages file within the api-docs subfolder (e.g. api-docs) with the following content:

    title: API Reference
    nav:
       - Overview: README.md
       - ...
    

Once you run or deploy your mkdocs documentation, you will see the API Reference section with all of your API markdown documentation.

Docstyle Validation

DocsAI can only parse valid Google-style docstring. To prevent the generation of invalid markdown documentation, you can use the validate flag:

docsai --validate my_package

This will run pydocstyle on your docstring and cancel the generation if an issue is found.

Print to Console

To get the markdown documentation as console output instead of the file generation, specify stdout as the output-path:

docsai --output-path=stdout my_package

Documentation

CLI Interface

docsai [OPTIONS] PATHS...

Arguments:

  • PATHS...: Selected paths or imports for markdown generation. [required]

Options:

  • --output-path TEXT: The output path for the creation of the markdown files. Set this to stdout to print all markdown to stdout. [default: ./docs/]
  • --src-base-url TEXT: The base repo link used as prefix for all source links. Should also include the branch name.
  • --overview-file TEXT: Filename of overview file. If not provided, no API overview file will be generated.
  • --remove-package-prefix / --no-remove-package-prefix: If True, the package prefix will be removed from all functions and methods. [default: True]
  • --ignored-modules TEXT: A list of modules that should be ignored. [default: ]
  • --watermark / --no-watermark: If True, add a watermark with a timestamp to bottom of the markdown files. [default: True]
  • --validate / --no-validate: If True, validate the docstrings via pydocstyle. Requires pydocstyle to be installed. [default: False]
  • --install-completion: Install completion for the current shell.
  • --show-completion: Show completion for the current shell, to copy it or customize the installation.
  • --help: Show this message and exit.

Programmatic API

DocsAI can also be used and integrated via its Python API. For example, to generate markdown for an arbitrary Python import or object:

from docsai import MarkdownGenerator

generator = MarkdownGenerator()

# Select a module (e.g. my_module) to generate markdown documentation
markdown_docs = generator.import2md(my_module)

To programmatically generate all markdown documentation files you can use generate_docs:

from docsai import generate_docs

# The parameters of this function correspond to the CLI options
generate_docs(["my_module"], output_path="./docs")

The full Python API documentation can be found here (generated via docsai).

Contribution

Development

Requirements: Docker and Act are required to be installed on your machine to execute the build process.

To simplify the process of building this project from scratch, we provide build-scripts - based on ml-buildkit - that run all necessary steps (build, check, test, and release) within a containerized environment. To build and test your changes, execute the following command in the project root folder:

act -b -j build

Refer to our contribution guides for more detailed information on our build scripts and development process.


Licensed MIT. Created and maintained with ❤️  by developers from KhulnaSoft.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docsai-0.5.2.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

docsai-0.5.2-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file docsai-0.5.2.tar.gz.

File metadata

  • Download URL: docsai-0.5.2.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.4

File hashes

Hashes for docsai-0.5.2.tar.gz
Algorithm Hash digest
SHA256 60d6d698fdd728d8e32877f37b41ecf0a6df784a89c6cf8273a1eea27f9c121e
MD5 527980cb2e98792698630cf3135b29c0
BLAKE2b-256 cd8a66f5a23456d965ca57e34d8863cb4f37211be8d1d58734e0062c1c6eff92

See more details on using hashes here.

File details

Details for the file docsai-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: docsai-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.4

File hashes

Hashes for docsai-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6869d6ead79fd617fa8fa62c1eb451486d9887500fe0763bf04d77f3c9a66b87
MD5 6f63733b907a5280dbb5fd4066816e4e
BLAKE2b-256 18459935beed4145603e4c9fa087c0767b8b3af782f4c1b4c6f9baa2e7adec63

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page