Transform text into beautiful markdown, effortlessly.
Project description
mdfy
mdfy is a Python library that makes creating markdown documents as simple as writing Python code. Generate reports, documentation, and structured content with an intuitive, object-oriented API.
🚀 Quick Start
Installation
pip install mdfy
Usage
from mdfy import Mdfier, MdHeader, MdText, MdTable
# Create markdown content
content = [
MdHeader("My Report"),
MdText("This quarter's sales were [excellent:bold]!"),
MdTable([
{"Product": "Laptop", "Sales": 1200, "Growth": "+15%"},
{"Product": "Phone", "Sales": 800, "Growth": "+8%"}
])
]
# Generate markdown file
Mdfier("report.md").write(content)
📖 Documentation
| Resource | Description |
|---|---|
| Getting Started | Step-by-step tutorial for beginners |
| User Guide | Complete feature documentation |
| Examples | Real-world usage examples |
| API Reference | Complete API documentation |
Basic Features
| Feature | Description |
|---|---|
| Text styling | Format text with bold, italic, and more - even in the middle of text |
| Headers | Multiple levels for document structure |
| Links | Internal and external linking |
| Lists | Ordered and unordered with nesting support |
| Tables | From dictionaries and lists with formatting |
| Images | With alt text and titles |
| Code blocks | With syntax highlighting |
| Quotes | For emphasis and citations |
| Horizontal rules | For section separation |
| Table of Contents | Automatic generation from headers |
Basic Usage
import mdfy as m
# Create content
content = [
m.header("My Report"),
m.text("This quarter's sales were [excellent:bold]!"),
m.table(
[
{"Product": "Laptop", "Sales": 1200, "Growth": "+15%"},
{"Product": "Phone", "Sales": 800, "Growth": "+8%"},
]
),
]
# Generate markdown file
m.Mdfier.from_filepath("report.md").write(content)
Output:
# My Report
This quarter's sales were [excellent:bold]!
| Product | Sales | Growth |
| --- | --- | --- |
| Laptop | 1200 | +15% |
| Phone | 800 | +8% |
🎨 Core Elements
Headers & Text
MdHeader("Title", level=1) # # Title
MdText("[Bold:bold] and [italic:italic]") # **Bold** and *italic*
Data & Lists
MdTable(data, precision=2) # Convert dicts/lists to tables
MdList(items, numbered=True) # • Bullet or 1. Numbered lists
Code & More
MdCode("print('hello')", syntax="python") # Syntax-highlighted code blocks
You can use a shortened syntax for convenience:
import mdfy as m
# Create a header
header = m.header("My Report", level=1) # # My Report
text = m.text("This quarter's sales were [excellent:bold]!")
table = m.table([
{"Product": "Laptop", "Sales": 1200, "Growth": "+15%"},
{"Product": "Phone", "Sales": 800, "Growth": "+8%"}
])
💡 Real-world Examples
Dynamic Reports
import mdfy as m
def generate_sales_report(sales_data):
total = sum(item['amount'] for item in sales_data)
return [
m.header("Sales Report"),
m.text(f"Total Revenue: [${total:,}:bold]"),
m.table(sales_data, precision=2)
]
m.Mdfier.from_filepath("sales.md").write(generate_sales_report(quarterly_data))
Data Analysis
# Convert pandas DataFrame to markdown table
df_summary = df.describe()
table = MdTable(df_summary.to_dict(), precision=3)
# Create analysis report
analysis = [
MdHeader("Data Analysis Report"),
MdText("Dataset contains [1,000:bold] records with [95%:bold] completeness."),
MdTable(df_summary.to_dict(), precision=3)
]
🔧 Advanced Features
- Nested Content: Organize content hierarchically
- Custom Formatting: Flexible text styling with
[text:style]syntax - Table Customization: Headers, row labels, precision control, transposition
- Independent Elements: Each element can be used standalone
- Type Safety: Full type hints for better IDE support
- ""Table of Contents**: Automatically generated from headers
🤝 Contributing
We welcome contributions! Here's how to get started:
# Development setup
git clone https://github.com/argonism/mdfy.git
cd mdfy
uv sync --all-groups
# Run tests
python -m pytest
Areas we'd love help with:
- 🐛 Bug reports and fixes
- 📚 Documentation improvements
- ✨ New element types
- 🎨 Styling and formatting features
📜 License
This project is licensed under the MIT License.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mdfy-0.11.0.tar.gz.
File metadata
- Download URL: mdfy-0.11.0.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc480509f1738e92537d407f72e04d63ad73f1d840f6ea84f7244be741fdbc7d
|
|
| MD5 |
0a90c00b38832cf5ee5288555d5563b0
|
|
| BLAKE2b-256 |
213994870d31feeb60c25ac4ad56a521135724cfe91f7117dd33657983b117b0
|
Provenance
The following attestation bundles were made for mdfy-0.11.0.tar.gz:
Publisher:
publish.yml on mdfy-org/mdfy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdfy-0.11.0.tar.gz -
Subject digest:
fc480509f1738e92537d407f72e04d63ad73f1d840f6ea84f7244be741fdbc7d - Sigstore transparency entry: 651323434
- Sigstore integration time:
-
Permalink:
mdfy-org/mdfy@52f1a534c49e41c86a27569de8f85837317ba58a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mdfy-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@52f1a534c49e41c86a27569de8f85837317ba58a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file mdfy-0.11.0-py3-none-any.whl.
File metadata
- Download URL: mdfy-0.11.0-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
830b03e2a7c0b512b2b96acba8106c9e4d618e0103b7be1ebdfe8e68e3534934
|
|
| MD5 |
e0e3f72e26f4c660992e6b60ce1aca7a
|
|
| BLAKE2b-256 |
914d0d171539c3b1079052da2cb1f17a1a3ab033e22ae4652225c3945616f0c4
|
Provenance
The following attestation bundles were made for mdfy-0.11.0-py3-none-any.whl:
Publisher:
publish.yml on mdfy-org/mdfy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdfy-0.11.0-py3-none-any.whl -
Subject digest:
830b03e2a7c0b512b2b96acba8106c9e4d618e0103b7be1ebdfe8e68e3534934 - Sigstore transparency entry: 651323435
- Sigstore integration time:
-
Permalink:
mdfy-org/mdfy@52f1a534c49e41c86a27569de8f85837317ba58a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mdfy-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@52f1a534c49e41c86a27569de8f85837317ba58a -
Trigger Event:
workflow_dispatch
-
Statement type: