Skip to main content

Docdantic

Gitlab code coverage (specific job) GitLab Release (latest by SemVer) GitLab PyPI - Python Version

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

Features

  • Supports both Pydantic V1 and V2 models.
  • Automatically generate tables of Pydantic model fields with their details (name, type, required, default).
  • Supports nested Pydantic 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.

Metadata

Release files for docdantic 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for docdantic 0.3.1
File Interpreter ABI Platform Actions
docdantic-0.3.1-py3-none-any.whl Python 3 none any Details for docdantic-0.3.1-py3-none-any.whl

Release files / docdantic-0.3.1-py3-none-any.whl

Download URL docdantic-0.3.1-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70f3d71b4a4c1142acd311c4bdb58dd8633195b73a90bd46baca002059c8e6cb
BLAKE2b-256 checksum
How to use checksums
39ec752921addcdea5a2c6a5b566acf2600625976e0bb9d77fa9958e08870143
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.7 Linux/5.15.109+

Security for docdantic 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page