Skip to main content

REPL with Python Scripts via live documents - A documentation library for creating interactive markdown documentation from Python code

Project description

CMX - REPL with Python Scripts via Live Documents

PyPI version Documentation Status License: MIT

Create live, interactive documentation directly from your Python scripts.

CMX is a Python library that enables REPL-style documentation generation. It works like Jupyter notebooks but integrates directly into your Python scripts using context managers. Only code you include in a with doc: block appears in the output.

Features

  • Live Documentation: Generate markdown/HTML/LaTeX from Python code execution
  • Multiple Backends: Markdown (GitHub-compatible), HTML, and LaTeX output
  • Rich Components: Tables, images, videos, figures, YAML output
  • Context Management: Use with doc: blocks to control what appears
  • File Logging: Built-in support for saving images, videos, and data
  • Layout Control: Arrange content horizontally with row layouts

Quick Start

Install from PyPI:

pip install cmx

Create your first live document:

from cmx import doc

# Configure output (optional - auto-detects from script name)
doc.config(filename="output.md")

# Everything in 'with doc:' blocks appears in output
with doc:
    doc("# Hello, CMX!")

    for i in range(10):
        doc.print(i, end=' ')

Output in output.md:

for i in range(10):
    doc.print(i, end=' ')
0 1 2 3 4 5 6 7 8 9

Documentation

Full documentation is available at: https://cmx-python.readthedocs.io

Usage Examples

Basic Usage

from cmx import doc

doc.config(filename="output.md")

with doc:
    doc("# Hello, CMX!")

    for i in range(10):
        doc.print(i, end=' ')

doc.flush()

The @ Operator

The @ operator provides clean syntax for adding markdown (used extensively in vuer-ai repositories):

doc @ """
# Experiment Report

This is a clean way to add markdown content.
"""

with doc:
    doc @ "## Results"
    results = [1, 2, 3, 4, 5]
    doc.print(f"Total: {sum(results)}")

Tables

Display experiment results and metrics:

import pandas as pd

data = pd.DataFrame({
    'Model': ['ResNet50', 'VGG16', 'MobileNet'],
    'Accuracy': [0.95, 0.87, 0.92],
    'Parameters': ['25.6M', '138M', '4.2M']
})

with doc:
    doc.table(data)

Images

import numpy as np

image = np.random.rand(100, 100, 3)

with doc:
    doc.image(image, src="figures/random.png")

YAML Configuration

config = {
    'model': 'ResNet50',
    'batch_size': 32,
    'learning_rate': 0.001,
    'optimizer': 'Adam'
}

with doc:
    doc.yaml(config)

Hiding Setup Code

Keep documentation clean by hiding boilerplate:

with doc.hide:
    # This code runs but doesn't appear in output
    import numpy as np
    data = load_experiment_data()

with doc:
    doc @ "## Analysis Results"
    doc.print(f"Mean: {data.mean():.4f}")

Complete Workflow Example

from cmx import doc
import pandas as pd

doc.config(filename="experiment_report.md")

doc @ """
# Experiment Report
**Date**: 2024-01-15
"""

# Hidden setup
with doc.hide:
    results = load_results()

# Configuration
with doc:
    doc @ "## Configuration"
    doc.yaml({'model': 'ResNet50', 'epochs': 100})

# Results table
with doc:
    doc @ "## Results"
    df = pd.DataFrame(results)
    doc.table(df)

# Analysis
with doc:
    doc @ "## Analysis"
    best = df['accuracy'].max()
    doc.print(f"Best accuracy: {best:.2%}")

doc.flush()

More examples in the examples/core/ directory, including:

  • Basic usage patterns
  • Tables and data display
  • Image handling
  • YAML configuration output
  • Experiment analysis workflows
  • Complete reporting examples

See examples/core/README.md for detailed explanations.

Development

Set up a development environment:

# Clone the repository
git clone https://github.com/cmx/cmx-python.git
cd cmx-python

# Install in development mode
make dev

# Run tests
make test

# Preview documentation
make preview

Claude Code Skills

CMX includes Claude Code skills for enhanced assistance when working with the library. The skills are located in .claude-plugin/ and provide guidance on:

  • Basic usage patterns
  • Component usage (tables, images, videos, etc.)
  • Advanced features and best practices

Publishing

Build and publish to PyPI:

# Update VERSION file
echo "0.0.47" > VERSION

# Build and publish
make publish

Project Structure

cmx-python/
├── src/cmx/              # Main package source
├── docs/                 # Sphinx documentation
├── examples/             # Example scripts
│   ├── three/           # 3D visualization examples
│   └── old_demos/       # Legacy examples
├── tests/               # Test suite
├── .claude-plugin/      # Claude Code skills
├── pyproject.toml       # Project configuration
├── Makefile            # Build automation
└── README.md           # This file

Contributing

Contributions are welcome! Please see the Development Guide for details.

License

MIT License - see LICENSE file for details.

Author

Ge Yang (ge.ike.yang@gmail.com)

Links

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

cmx-0.0.48.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

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

cmx-0.0.48-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file cmx-0.0.48.tar.gz.

File metadata

  • Download URL: cmx-0.0.48.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for cmx-0.0.48.tar.gz
Algorithm Hash digest
SHA256 37b13b419bddedb2861ee5197a1b928646aaadaaa345480bb6a56ad677cdb264
MD5 55989593c90f8105a2f4b512ee2d33b4
BLAKE2b-256 9271499812444544e402a50bf9b31a46958aed6ff3d9aa27a814b348716fa5a9

See more details on using hashes here.

File details

Details for the file cmx-0.0.48-py3-none-any.whl.

File metadata

  • Download URL: cmx-0.0.48-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for cmx-0.0.48-py3-none-any.whl
Algorithm Hash digest
SHA256 8cc1c8c929dd492bd8f1b20befab5b21083953b54498958c20d60bf4e8119100
MD5 9216a91fffcbcbf3150d7e1d443e615f
BLAKE2b-256 b09f7442157b5327a8e107b47bee7d5c28fa52d18eccb5a1cc43a44be5690218

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