Skip to main content

Effortlessly convert nested Python dictionaries into intuitive Markdown tables.

Project description



mdfy teaser

mdfy

Transform text into beautiful markdown, effortlessly.

🌟 Features

  • Simplicity: Just a few lines of code and voila! An intuitive architecture made simple.
  • Modulability: Each module is highly independent, making it easy to use on its own.
  • Customizable: Extensible design allowing for easy customization.
  • Highly Tested: Robust unit tests ensure reliability.

🚀 Getting Started

Installation

pip install mdfy

Usage

Here's a quick start guide to get you up and running!

from mdfy import Mdfier, MdText, MdHeader

contents = [
  MdHeader("Hello, MDFY!"),
  MdText("{Life:bold} is {like:italic} a bicycle.")
  MdTable(MdTable({"head1": "content", "head2": "content"}))
]
Mdfy("markdown.md").write(contents)

# => markdown.md
#
# # Hello, MDFY!
# **Life** is *like* a bicycle.

Each mdfy element is string-convertible and can operate independently!

from mdfy import MdText, MdHeader, MdTable

print(MdHeader("Hello, MDFY!"))
print(MdText("{Life:bold} is {like:italic} a bicycle."))
print(MdTable({"head1": "content", "head2": "content"}))

# => result
#
# # Hello, MDFY!
# **Life** is *like* a bicycle.
# | head1 | head2 |
# | --- | --- |
# | content | content |

MdText Format

With MdText, you can flexibly specify text styles in a way similar to python's string formatting.

MdText("{a family:underline} of {plain-text formatting syntaxes:bold} that optionally can be {converted to {formal:italic} {markup languages:bold}:underline} such as {HTML:strong}")

a family of plain-text formatting syntaxes that optionally can be converted to formal markup languages such as HTML

MdTable

MdTable offers a flexible way to convert a Python dict to a Markdown table.

data = [
    {"precision": 0.845, "Recall": 0.662},
    {"precision": 0.637, "Recall": 0.802},
    {"precision": 0.710, "Recall": 0.680},
]

print(MdTable(data))

# The result will be
# | precision | Recall |
# | --- | --- |
# | 0.845 | 0.662 |
# | 0.637 | 0.802 |
# | 0.71 | 0.68 |

To transpose a table, all you need to do is pass True to the transpose parameter.

print(MdTable(data, transpose=True))

# | Key | Value 0 | Value 1 | Value 2 |
# | --- | --- | --- | --- |
# | precision | 0.845 | 0.637 | 0.71 |
# | Recall | 0.662 | 0.802 | 0.68 |

# And you can specify header labels when transpose
labels = ["Metrics", "Model 1", "Model 2", "Model 3"]
print(MdTable(data, transpose=True, labels=labels))

# | Metrics | Model 1 | Model 2 | Model 3 |
# | --- | --- | --- | --- |
# | precision | 0.845 | 0.637 | 0.71 |
# | Recall | 0.662 | 0.802 | 0.68 |

You can also specify the precision of float values.

data = [
    {"precision": 0.84544, "Recall": 0.662765},
    {"precision": 0.63743, "Recall": 0.802697},
    {"precision": 0.718203, "Recall": 0.6802435},
]
labels = ["Metrics", "Model 1", "Model 2", "Model 3"]
print(MdTable(data, transpose=True, labels=labels, precision=3))

# | Metrics | Model 1 | Model 2 | Model 3 |
# | --- | --- | --- | --- |
# | precision | 0.845 | 0.637 | 0.718 |
# | Recall | 0.663 | 0.803 | 0.680 |

✅ Testing

To run the tests:

python -m pytest

💡 Contributing

We welcome contributions!

📜 License

This project is licensed under the MIT License. See the LICENSE file for 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 Distribution

mdfy-0.0.6.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

mdfy-0.0.6-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file mdfy-0.0.6.tar.gz.

File metadata

  • Download URL: mdfy-0.0.6.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for mdfy-0.0.6.tar.gz
Algorithm Hash digest
SHA256 29ab1c096e0e50c7a8c97bf1ece2764d385bbe3169cb667b9185b50015149f05
MD5 49d7098b98f4267fd39286d524439817
BLAKE2b-256 7611c3ce89056fdf8a2fbb9219ea24e8a46b48d7553e502c526695ea1b00e304

See more details on using hashes here.

File details

Details for the file mdfy-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: mdfy-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for mdfy-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 fcfd48152d26c8b202629d6fc7c8cf130b4f69af2c23b0242edeae9efc16d3fa
MD5 8ac4125f7cbe128aa03ed6d3146b50a5
BLAKE2b-256 40f45ef5ca56549e9d93e896525dbec977284eb447f427bf58148cc20d8dbce3

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