Python-Powered Markdown with executable code and dynamic content
Project description
PyMD: Python-Powered Markdown
PyMD is a revolutionary markup language that combines familiar markdown syntax with the full power of Python execution. Write beautiful documents using standard markdown headers, lists, and text, while executing Python code in clearly separated code blocks!
โจ Features
- ๐ Markdown Syntax: Use familiar markdown headers (#), lists (-), and plain text
- ๐ Dual Code Block Types:
- ``` (3 backticks): Execute Python code and show output
- ```` (4 backticks): Display code with syntax highlighting only
- ๐ Variable Persistence: Variables persist across code blocks in the same document
- ๐ด Live Preview: Real-time rendering with auto-refresh as you edit
- ๐ Rich Visualizations: Built-in support for matplotlib, pandas, and other data science libraries
- ๐งฎ Dynamic Content: Execute Python code and display results inline
- ๐ฑ Beautiful Output: Clean, responsive HTML with modern styling
- โก Fast Rendering: Efficient parsing and rendering engine
- ๐ Auto-Refresh: Changes reflect immediately in the live preview
- ๐ฌ Smart Comments: Display blocks use
//for cleaner code presentation
๐ Quick Start
Installation
Option 1: Install from PyPI (Recommended)
pip install pyexecmd
Option 2: Install from source
-
Clone the repository:
git clone https://www.github.com/treeleaves30760/PyMD cd PyMD
-
Install in development mode:
pip install -e .
Usage
-
Create a new PyMD document:
pyexecmd create my_document.pymd
-
Start live preview:
pyexecmd serve my_document.pymd --port 8080
Then open http://localhost:8080 in your browser
Note for macOS users: Port 5000 is often used by AirPlay. Use
--port 8000or another port to avoid conflicts. -
Render to HTML:
pyexecmd render my_document.pymd -o output.html
๐ PyMD Syntax
PyMD combines familiar markdown syntax with Python code execution:
Markdown Content (Outside Code Blocks)
Headers:
# Main Title
## Section Title
### Subsection Title
Lists:
- Unordered list item
- Another unordered item
1. Ordered list item
2. Another ordered item
Plain Text:
This is a paragraph of regular text.
You can write multiple paragraphs easily.
Comments:
// This is a comment and will be ignored
Python Code Blocks
Simple Code Execution:
```
x = 42
y = "Hello, PyMD!"
print(f"{y} The answer is {x}")
```
Data Analysis:
```
import pandas as pd
import numpy as np
# Create sample data
data = pd.DataFrame({
'Name': ['Alice', 'Bob', 'Charlie'],
'Score': [95, 87, 92]
})
print("Sample Data:")
pymd.table(data)
```
Visualizations:
```
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.figure(figsize=(8, 5))
plt.plot(x, y, 'b-', linewidth=2)
plt.title("Sine Wave Visualization")
plt.grid(True)
pymd.image(plt.gcf(), "Beautiful sine wave")
```
Code Display (Method 1 - Using pymd.code()):
```
sample_code = '''
def factorial(n):
if n <= 1:
return 1
return n * factorial(n-1)
'''
pymd.code(sample_code, "python")
print(f"Factorial of 5 is: {factorial(5)}")
```
Code Display (Method 2 - Using four backticks):
````
def factorial(n):
// Base case
if n <= 1:
return 1
// Recursive case
return n * factorial(n-1)
// Example usage (not executed)
result = factorial(5)
````
Key Features
- Variable Persistence: Variables defined in one code block are available in subsequent blocks
- Mixed Content: Alternate between markdown content and Python code seamlessly
- Two Code Block Types:
- Three backticks (```): Execute Python code and show output
- Four backticks (````): Display code with syntax highlighting (no execution)
- Clean Separation: Clear visual distinction between documentation and executable code
- Rich Output: Code execution results are displayed with beautiful formatting
- Smart Comment Styling: Display blocks use
//comments for cleaner presentation
๐ Project Structure
PyMD/
โโโ pymd/ # Main package directory
โ โโโ __init__.py # Package initialization
โ โโโ cli.py # Command-line interface
โ โโโ renderer.py # Core rendering engine
โ โโโ server.py # Live preview server
โโโ example.pymd # Example PyMD document
โโโ pyproject.toml # Package configuration
โโโ MANIFEST.in # Additional files to include
โโโ LICENSE # MIT License
โโโ requirements.txt # Python dependencies
โโโ README.md # This file
๐ ๏ธ API Reference
Markdown Syntax (Outside Code Blocks)
# Header- Create level 1 heading## Header- Create level 2 heading### Header- Create level 3 heading- Item- Unordered list item1. Item- Ordered list itemPlain text- Regular paragraph text// Comment- Comments (ignored during rendering)
PyMD Functions (Inside Code Blocks)
pymd.h1(text)- Create level 1 heading programmaticallypymd.h2(text)- Create level 2 heading programmaticallypymd.h3(text)- Create level 3 heading programmaticallypymd.text(content)- Create paragraph text programmaticallypymd.code(content, language)- Display code block with syntax highlightingpymd.image(plot_obj, caption)- Render matplotlib plotspymd.table(data)- Render pandas DataFrames or tables
CLI Commands
# Create new PyExecMD file from template
pyexecmd create <filename> [--force]
# Start live preview server
pyexecmd serve <file> [--port PORT] [--host HOST] [--debug]
# Render PyExecMD to HTML
pyexecmd render <input> [-o OUTPUT]
๐ฏ Use Cases
- ๐ Data Science Reports: Combine analysis, visualizations, and explanations
- ๐ Interactive Documentation: Living documents that update with code changes
- ๐ Educational Materials: Tutorials with executable examples
- ๐ Dashboard Reports: Dynamic reports with real-time data
- ๐ฌ Research Papers: Academic papers with reproducible results
๐ Examples
Check out example.pymd for a comprehensive demonstration of PyMD features, including:
- Markdown-style headers, lists, and text
- Python code execution with output
- Beautiful data visualizations with matplotlib
- Dynamic calculations and variable persistence
- Interactive tables with pandas
- Mixed content workflow
- Real-time preview updates
๐ค Contributing
We welcome contributions! Please feel free to submit issues, feature requests, or pull requests.
๐ 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 pyexecmd-0.1.3.tar.gz.
File metadata
- Download URL: pyexecmd-0.1.3.tar.gz
- Upload date:
- Size: 28.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2152768d20745a99372e067bb6768ce6380194f2a4331bbfe3ed08025e154a83
|
|
| MD5 |
85e87c8b3862f7338c4d1c02ce3f4c4c
|
|
| BLAKE2b-256 |
b7d605ba79c11b99378d18b52b0c23ab68a6ad35a808cbcec250cd71b18e8af5
|
File details
Details for the file pyexecmd-0.1.3-py3-none-any.whl.
File metadata
- Download URL: pyexecmd-0.1.3-py3-none-any.whl
- Upload date:
- Size: 23.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8621a828535565d90e2a4e0719b46fc3f44c06c7f077689a462db9070acab6fb
|
|
| MD5 |
0f41550758c2a3f51cda224fa951b2dd
|
|
| BLAKE2b-256 |
7862a5f6c249db27ab99fd16e68c38d95830e3f29d1c80a1310c0dd467700146
|