Skip to main content

Markdown Template

Project version Supported python versions License CodeFactor Grade Code style

A tool to help primarily with generating Markdown tables based on a set of files. This is particularly useful to repositories that contain several subprojects, such as userscript repos.

Installation

This will install md-template and natsort as well as pyyaml for the userscript preset.

pip install md-template[full]

For the most minimal installation.

pip install md-template
# or with natsort (recommended)
pip install md-template[natsort]

Usage

Command-line

The easiest but most restricted method.

# md-template --help
md-template table --preset scoop --dry-run

Class-based

See table.presets for more detailed examples.

from pathlib import Path
from typing import Iterable

from mdtemplate.table import TableTemplate


class MyTemplate(TableTemplate):
    files = "bucket/*.json"
    columns = ("Name", "Branch")
    source = "README.md"  # default

    def handle_path(self, path: Path) -> Iterable[Iterable[str]]:
        # create a row
        yield [
            # include information using the current filepath
            f"Column 1: **{path.name}**",
            # use information from the git repository
            f"Column 2: {self.repository.branch}",
        ]


if __name__ == "__main__":
    MyTemplate().parse_args().render()

Function-based

from pathlib import Path
from typing import Iterable

from mdtemplate.table import TableTemplate


def handle_path(self: TableTemplate, path: Path) -> Iterable[Iterable[str]]:
    # create a row
    yield [
        # include information using the current filepath
        f"Column 1: **{path.name}**",
        # use information from the git repository
        f"Column 2: {self.repository.branch}",
    ]


if __name__ == "__main__":
    TableTemplate(
        files="bucket/*.json",
        columns=("Name", "Branch"),
        source="README.md",  # default
        handle_path=handle_path,
    ).parse_args().render()

Output

Both the class-based and function-based examples above generate the same table.

Input

# My Repository

<!-- table -->
| Manifests |
| --------- |

<!-- table-end -->

Release files for md-template 0.2.1

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

Source distribution (sdist)

Source distribution for md-template 0.2.1
File Size Uploaded
md_template-0.2.1.tar.gz 15.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for md-template 0.2.1
File Interpreter ABI Platform
md_template-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 25.3 kB

Release files / md_template-0.2.1.tar.gz

Download URL md_template-0.2.1.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4bf30f66d8daedd4ed9aff41cd270c5519db408afb5a9299d8dda09385a7de2c
BLAKE2b-256 checksum
How to use checksums
65f15d4b7098453279b74ac71d265ee7d1d0cf3f16ac7b94ad90999ce66c0f47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.5.4

Release files / md_template-0.2.1-py3-none-any.whl

Download URL md_template-0.2.1-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0ca17d24a3c4b5d34d3f9507b6a6e33d18198607bacf8b428fa172c9adc5bb8
BLAKE2b-256 checksum
How to use checksums
e2cd3804b22270629bf68db50f8ca0d66d32c6148866a00df6e930e111c4aa70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.5.4

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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