Skip to main content

Python-Powered Markdown with executable code and dynamic content

Project description

PyMD: Python-Powered Markdown

PyPI Downloads

PyMD is a revolutionary markup language that creates executable Python files that also render beautifully as markdown documents. All markdown content is prefixed with # (making it Python comments), while code blocks contain regular executable Python code that prints markdown during rendering.

Screen Shot

โœจ Features

๐Ÿ Core Functionality

  • Executable Python Files: Run directly with python filename.pymd
  • Dual Code Blocks: ``` for executable code, ```` for display-only
  • Variable Persistence: Variables persist across code blocks

๐Ÿ“ Document Creation

  • Commented Markdown: All markdown prefixed with # (Python comments)
  • Print-to-Markdown: print() statements output markdown during rendering
  • Dynamic Content: Execute Python code and display results inline

๐ŸŽจ Rich Media Support

  • Automatic Plot Capture: plt.show() saves and renders matplotlib plots
  • Video Rendering: Built-in video support with custom controls
  • Table Detection: Automatic markdown table formatting

๐Ÿ”ด Live Development

  • Real-time Preview: Auto-refresh as you edit with web editor
  • One-click Export: Export to HTML or Markdown with embedded media
  • Fast Rendering: Efficient parsing with caching

๐Ÿš€ Quick Start

Installation

Option 1: Install from PyPI (Recommended)

pip install pyexecmd
Option 2: Install from source
  1. Clone the repository:

    git clone https://www.github.com/treeleaves30760/PyMD
    cd PyMD
    
  2. Install in development mode:

    pip install -e .
    

Usage

For PyPI Installation

  1. Create a new PyMD document:

    pyexecmd create my_document.pymd
    
  2. Start live preview with web editor:

    pyexecmd serve --file my_document.pymd --port 8080
    

    Then open http://localhost:8080/editor in your browser for the full editor experience, or http://localhost:8080 for display-only view.

    Note for macOS users: Port 5000 is often used by AirPlay. Use --port 8000 or another port to avoid conflicts.

  3. Export Options:

    # Render to HTML
    pyexecmd render my_document.pymd -o output.html
    
    # Render to Markdown
    pyexecmd render my_document.pymd -f markdown -o output.md
    
For Conda Users (Recommended Development Setup)

If you're using conda for development, first activate the environment:

# Initialize conda and activate environment
source /opt/miniconda3/etc/profile.d/conda.sh && conda activate PyMD

# Verify activation
python --version && which python

Then use standard Python commands:

# Create a new PyMD document
python -m pymd.cli create my_document.pymd

# Start live preview with web editor
python -m pymd.cli serve --file my_document.pymd --port 8080

# Render to HTML
python -m pymd.cli render my_document.pymd -o output.html

# Render to Markdown
python -m pymd.cli render my_document.pymd -f markdown -o output.md

Web Editor Features

The web editor (available at /editor) includes:

  • ๐Ÿ“ Split-view editing: Side-by-side editor and live preview
  • ๐Ÿ–ฑ๏ธ One-click export: Export HTML and Markdown buttons in the interface
  • โšก Live rendering: Ctrl+S to execute code and update preview
  • ๐Ÿ’พ File management: Save and download your documents
  • ๐ŸŽจ Syntax highlighting: Python syntax highlighting with PyMD-specific features

๐Ÿ“ PyMD Syntax

Please refer to Syntex Guide to learn how to write the PyMD

๐Ÿš€ Quick Example Usage

1. Run as executable Python:

python example.pymd

2. Render as beautiful HTML:

python -m pymd.cli render example.pymd -o presentation.html

3. Export to standard Markdown:

python -m pymd.cli render example.pymd -f markdown -o documentation.md

4. Live editor with preview:

python -m pymd.cli serve --file example.pymd --port 8080
# Open http://localhost:8080/editor in your browser

How Export Works:

  • HTML Export: Full rendering with executed code output and styled markdown
  • Markdown Export: Removes # prefixes and converts to standard markdown
  • Source Files: Remain executable Python scripts with commented markdown
  • Compatibility: Exported markdown works with GitHub, GitLab, and other renderers

Output Directory Structure:

After rendering documents with images and videos, your output directory will look like:

my_project/
โ”œโ”€โ”€ document.pymd           # Source PyMD file
โ”œโ”€โ”€ document.html           # Rendered HTML output
โ”œโ”€โ”€ images/                 # Auto-generated plot images
โ”‚   โ”œโ”€โ”€ plot_1_abc123.png
โ”‚   โ””โ”€โ”€ plot_2_def456.png
โ””โ”€โ”€ videos/                 # Embedded video files
    โ”œโ”€โ”€ video_1_ghi789.mp4
    โ””โ”€โ”€ video_2_jkl012.mp4

Web Editor Features:

  1. Live Editing: Open http://localhost:8080/editor in your browser
  2. Syntax Highlighting: # prefixed markdown and Python code blocks
  3. Live Preview: See rendered output in real-time
  4. Export Options: Click ๐Ÿ“„ Export HTML or ๐Ÿ“ Export MD
  5. File Execution: Use Ctrl+S to execute code and update preview

๐ŸŽฏ Use Cases

  • ๐Ÿ“Š Data Science Reports: Python scripts that execute analysis AND generate beautiful reports with automatic plot capture
  • ๐Ÿ“š Executable Documentation: Documentation that actually runs and validates itself, with embedded visualizations and demo videos
  • ๐ŸŽ“ Interactive Tutorials: Learning materials that students can execute and modify, featuring live charts, tables, and instructional videos
  • ๐Ÿ“ˆ Living Dashboards: Python scripts that generate dynamic visual reports with automatic image saving
  • ๐Ÿ”ฌ Reproducible Research: Research papers where the code actually runs and produces publication-ready figures
  • ๐Ÿงช Literate Programming: Self-documenting code through executable markdown comments with inline visualizations
  • ๐Ÿ“‹ Technical Specifications: Specs that include working code examples and automatically generated plots
  • ๐Ÿค– AI/ML Workflows: Machine learning pipelines with embedded documentation and automatic model visualization
  • ๐Ÿ“‘ Business Reports: Automated reports with data tables and charts that update when code runs
  • ๐ŸŽจ Presentation Materials: Technical presentations that combine code, explanation, live visualizations, and demo videos

๐Ÿค 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyexecmd-0.1.7.tar.gz (43.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyexecmd-0.1.7-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

Details for the file pyexecmd-0.1.7.tar.gz.

File metadata

  • Download URL: pyexecmd-0.1.7.tar.gz
  • Upload date:
  • Size: 43.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for pyexecmd-0.1.7.tar.gz
Algorithm Hash digest
SHA256 6bf31ec59ad9bc2b51528df1964602683717c12d6f0acefe04e2aa8f5f984625
MD5 04ccd9d7546bb6d2f144ed2f75a99c9e
BLAKE2b-256 6521e3c34d9e29b5de612df5b1bf1e3fb6cf691cf632db4f9d84523ccc0cb483

See more details on using hashes here.

File details

Details for the file pyexecmd-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: pyexecmd-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 35.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for pyexecmd-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 7fa0f6bd288ce01d6873854395db97216e25aa19969b2f6ebaef2b808ba057dd
MD5 b5ccb77ba5f54daae517e342247ccda1
BLAKE2b-256 f7bc4aea22f81906cf94b9996f558e5fe3040cbd096bc87f59dbe4352e177f49

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page