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.
Notice: This project is still WIP and need more examples to adapt to most of the possible BaseModel models.
Installation
Just use pip:
pip install markdown-mdantic
Usage
Config options
init_code 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.
Note: Please note that the init_code thing is a huge security issue if
you run that with untrusted input. Use it with caution!
columns is a comma-separated list of table columns to use in each table.
The default is to use all columns ["key", "type", "required", "description", "default"].
mkdocs
example:
markdown_extensions:
mdantic:
init_code: |
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "conf.default")
django.setup()
columns: [key, type, required, default]
Some time ago the extension name used here should be markdown_mdantic, but
after some point it seems there will only be one file after installation in
python's site-packages directory (mdantic.py) so now we should use the name
mdantic.
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
like a.b.c.D where D is the model class itself (which is subclass of BaseModel).
**params**:
$pydantic: src.test.TestGetSchema
customize output
The resulting table is rendered using tabulate, in github style. The columns config option can be used to
restrict the columns to show. Styling cannot be changed at the moment. PR is welcomed.
Metadata
Release files for markdown-mdantic 2.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| markdown-mdantic-2.1.1.tar.gz | 6.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| markdown_mdantic-2.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.5 kB
Release files / markdown-mdantic-2.1.1.tar.gz
| Download URL | markdown-mdantic-2.1.1.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cfc6bbf1e426bff14bcbd92b720e5f778c1d609a1ed9c7356fa98698d58732e0
|
|
BLAKE2b-256 checksum How to use checksums |
88792755ccead635ae5c37272007a4614cfd3f844e7d088625afda45145084ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.8
|
Release files / markdown_mdantic-2.1.1-py3-none-any.whl
| Download URL | markdown_mdantic-2.1.1-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a691773aa5ea770b6386df02711fbd1e892efa7e6d8c63769fbb30e6f0e43b7a
|
|
BLAKE2b-256 checksum How to use checksums |
368af6daedf42bdcf4b5874d93d8d1c598e5a606867f755d2335a12acb6b4a7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.8
|