Skip to main content

A markdown plugin for generating docs from Pydantic models

Project description

Docdantic

PyPI - Python Version

Docdantic is a Python library that enables the automatic generation of Markdown documentation from Pydantic v2 models. It works as an extension of the Markdown package, extracting model details and creating neat tables with model fields and their properties.

Features

  • Automatically generate tables of Pydantic v2 model fields with their details (name, type, required, default).
  • Supports nested Pydantic v2 models.
  • Configurable exclusion of specific fields from the documentation.

Installation

pip install docdantic

Usage

Using the Docdantic Extension

To generate documentation directly from Markdown files, you can use the Docdantic extension. Simply include the !docdantic: import.path.to.Model directive in your Markdown text:

# MyModel Reference

!docdantic: my_module.MyModel

Docdantic will replace the !docdantic directive with a table of model field details.

Using Docdantic in Python Code

If you want to programmatically generate Markdown documentation from Pydantic v2 models, you can use Docdantic in your Python code. Here's an example:

import markdown
from docdantic import Docdantic

markdown_text = "Here are the details of my model:\n\n!docdantic: your.model.path"
converted_text = markdown.markdown(markdown_text, extensions=[Docdantic()])

# `converted_text` will contain the Markdown text with the model documentation

You can include the !docdantic: your.model.path directive in your Markdown text as before, and the markdown.markdown method will process it using the Docdantic extension.

Configuration

Docdantic allows you to exclude specific fields from the generated documentation by using the exclude configuration. You can provide a JSON object in the exclude field of the configuration to specify which fields to exclude. For example:

!docdantic: my_module.MyModel
    {
        "exclude": {
            "MyModel": ["field1", "field2"]
        }
    }

In the example above, the fields field1 and field2 will be excluded from the documentation of the MyModel model. Notice the configuration has to be indented with 2-4 spaces or a tab.

License

This project is licensed under the terms of the MIT license. See LICENSE for more details.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

docdantic-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file docdantic-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: docdantic-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.15.109+

File hashes

Hashes for docdantic-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1a31dc8e64a1d2480ccb29fd0f1b47715bcfc709e37d7f3df47a3dd9e1be5856
MD5 fb238e63d86ce69e2de4864eab56bce6
BLAKE2b-256 da9bb27e0af3e10a96744e8a992974a77133988e963c359099a5d8247e9eb104

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