Skip to main content

Professional terminal markdown renderer for streaming LLM responses

Project description

MarkRender 🎨

A professional terminal markdown renderer built for streaming LLM responses.

MarkRender is a Python library designed to bring beautifully rendered markdown directly to your terminal. It's especially good for displaying streaming output from large language models, ensuring a smooth, flicker-free experience with rich formatting and syntax highlighting.

✨ Features You'll Love

  • Streaming Optimized: Renders markdown chunks as they arrive, perfect for LLM interactions.
  • Gorgeous Themes: Comes with several built-in color themes to match your terminal aesthetic.
  • Smart Syntax Highlighting: Powered by Pygments, it makes your code blocks pop.
  • Full Markdown Support: Handles everything from headings and lists to tables, checkboxes, emojis, and links with robust streaming support.
  • Cross-Platform: Works on Windows, macOS, and Linux.

🚀 Get Started

Installation

It's super easy to get MarkRender up and running:

pip install git+https://github.com/Praneeth-Gandodi/markrender.git

Or, for development, clone the repository and install in editable mode:

git clone https://github.com/Praneeth-Gandodi/markrender.git
cd markrender
pip install -e .

Quick Usage

Here's how to render a simple markdown string

from markrender import MarkdownRenderer

renderer = MarkdownRenderer() 

markdown_text = """
# Project Title  
This is a comprehensive markdown example that demonstrates various features.  
It includes headers, lists, links, images, and code blocks.  

## Subsection Explanation  
- **Headers** are defined using `#` symbols.  
- **Lists** can be ordered or unordered.  
- **Links** use the syntax: `[text](url)`.  
- **Images** are added via `![alternative text](path)`.  

---

### Installation 
To get started, run the following command in your terminal:  
`pip install markrender`

### Feature Comparison
| Feature | Syntax |
| :--- | :--- |
| Bold | **text** |
| Italic | *text* |
| Inline Code | `code` |

> **Note:** Ensure your renderer is finalized after use to prevent memory leaks.
"""

renderer.render(markdown_text)
renderer.finalize()

How to render streaming api responses

from openai import OpenAI

renderer = MarkdownRenderer(theme='github-dark', line_numbers=True)

API_KEY = # Your openai api key

client = OpenAI(api_key=API_KEY)

stream = client.chat.completions.create(
    model="openai/gpt-oss-120b",
    messages=[
    {
        "role": "system",
        "content": "You are a highly capable AI assistant that answers clearly and concisely."
    },
    {
        "role": "user",
        "content": "Whats the difference between C and C++?"
    }
    ],
    stream=True
)
for chunk in stream:
    data = chunk.choices[0].delta.content
    if data: 
        renderer.render(data)

renderer.finalize() 

🎨 Advanced Configuration

You can customize the renderer's appearance and behavior with the following parameters:

from markrender import MarkdownRenderer

renderer = MarkdownRenderer(
    theme='monokai',         # Set the color style
    line_numbers=True,       # Show numbers next to code lines
    code_background=True,    # Add a background color to code blocks
    force_color=True,        # Always show colors
    stream_code=True         # Render code blocks line-by-line
)

Non-Streaming Code Blocks

If you prefer to render code blocks all at once after the entire block has been received, you can set stream_code=False. This is useful if you want to avoid seeing incomplete code blocks during streaming.

renderer = MarkdownRenderer(stream_code=False)

Available themes

  • github-dark
  • monokai
  • dracula
  • nord
  • one-dark
  • solarized-dark
  • solarized-light

📊 Table Rendering Excellence

MarkRender provides robust table rendering powered by the rich library. Tables are beautifully formatted with proper alignment, borders, and theme-appropriate colors. The renderer handles streaming edge cases gracefully, ensuring tables render correctly even when content arrives in chunks.

🤝 Contributing

We welcome contributions! Feel free to open issues or pull requests on our GitHub repository.

📄 License

MarkRender is released under the MIT License. See the LICENSE file for more 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

markrender-1.0.0.tar.gz (34.0 kB view details)

Uploaded Source

Built Distribution

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

markrender-1.0.0-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file markrender-1.0.0.tar.gz.

File metadata

  • Download URL: markrender-1.0.0.tar.gz
  • Upload date:
  • Size: 34.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for markrender-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b76c79928b7d68210199053c6a6bf1acfa10200dd8ce104a11cb6c8df5fd80a0
MD5 2c2a390559bcc68c6af9e91f5cc722bb
BLAKE2b-256 5e6e3c8f9683935781527fb42fda9faca106dd7d325f70a15727e23f068b3ddb

See more details on using hashes here.

File details

Details for the file markrender-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: markrender-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for markrender-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b7d3024a9c720614c368650ff80773cf1a284a5436a6f126799d764fced709b
MD5 8a958554326a78c236adfa90e6f376c6
BLAKE2b-256 8672187c194dd5f0a10c19f7f0bc487d84aa12d04d7e9d3271d92cea2bcaabef

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