Python-Markdown extension for rendering pydantic BaseModel as table
Project description
Mdantic
This is an extension to Python-Markdown. It adds a new syntax so that you can reference a pydantic BaseModel
and translate its fields to a markdown table. (Get the name?) I originally make this to generate http api parameter tables with mkdocs, but you can use it for other stuffs if suitable.
The code itself is a direct modification to markdown-include since they do similar things.
Installation
Just use pip:
pip install markdown-mdantic
Usage
Currently this module has only one config option: init_code
which will execute any python code in the environment when its __init__
is called. In this way you can do something like adding system path, django setup etc, before run.
mkdocs
example:
markdown_extensions:
markdown_mdantic:
init_code: |
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "conf.default")
django.setup()
reference the model
Each reference must be in one line, starts with $pydantic:
(notice the single space after the colon), following the model import path which looks lik a.b.c.D
where D
is the model class itself (BaseModel).
**params**:
$pydantic: src.test.TestGetSchema
customize output
The resulting table is rendered using tabulate, in github
style. Currently there is no config option to change this and the table headers. PR is welcomed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for markdown_mdantic-1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03ecc341217d158939c1ec318d88c3cce11dca9f592628800b0d2db3400f31e3 |
|
MD5 | 0e15939c76c463a55dea807478b9c6f8 |
|
BLAKE2b-256 | f50efe33cfb777dea57b88ab7c020efa95051ba1fc7d5bdc1c0510eb3db308fe |