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

PyPI version Documentation Status License: MIT

Generate live Markdown documentation from Python scripts — you choose exactly what appears.

CMX runs your script and captures the parts you mark, turning code and its output into a Markdown file. It works like a notebook, but you control what shows up: source, printed results, tables, images, and more. The core has zero third-party dependencies; richer blocks pull in small, opt-in extras.

Installation

Install the core from PyPI. It needs no third-party packages:

pip install cmx

Add extras only for the features you use:

Install Pulls in Enables
pip install cmx nothing text, operators, doc.print, doc.pre, capture, flush
pip install 'cmx[tables]' pandas doc.table, doc.csv
pip install 'cmx[images]' pillow, numpy array images, doc.image / figure / video
pip install 'cmx[figures]' matplotlib doc.savefig
pip install 'cmx[yaml]' pyyaml doc.yaml
pip install 'cmx[all]' all of the above everything

CMX requires Python 3.11 or later.

Quick start

Configure an output file, capture a block of code, then write it to disk. Create report.py:

from cmx import doc

doc.config(__file__)

with doc:
    doc @ "# Daily Report"
    total = sum(range(100))
    doc.print(f"Sum of 0-99: {total}")

doc.flush()

Run it with python report.py. CMX writes report.md next to the script:

# Daily Report

```python
total = sum(range(100))
doc.print(f"Sum of 0-99: {total}")
```

```
Sum of 0-99: 4950
```

The with doc: block captures its own source as a code fence and runs it; doc.print echoes to your terminal and appends the output. Code outside a with doc: block still runs — it just doesn't appear in the document.

Common patterns

Add text three equivalent ways. Each appends a text block and returns doc:

doc("## Results", end="\n")   # call form (end="\n" is the default)
doc @ "## Results"         # prefix @ operator
"## Results" | doc         # postfix | operator

Render a DataFrame (needs cmx[tables]):

import pandas as pd

with doc:
    doc.table(pd.DataFrame({"model": ["a", "b"], "acc": [0.95, 0.87]}))

Save and link an image (needs cmx[images]). A bare filename lands in the document's figure folder; a path with a slash is used as written:

import numpy as np

with doc:
    doc.image(np.random.rand(64, 64, 3), src="sample.png")

Render a config dict as YAML (needs cmx[yaml]):

with doc:
    doc.yaml({"model": "ResNet50", "epochs": 100})

Hide setup, keep results. doc.hide runs a block without showing it; variables it defines stay in scope:

with doc.hide:
    data = load_results()

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

Documentation

Full documentation: https://cmx-python.readthedocs.io

Runnable examples live in examples/core/ — see its README.

Development

git clone https://github.com/cmx/cmx-python.git
cd cmx-python
pip install -e '.[dev,docs]'   # editable install with test + docs tooling

make test       # run the pytest suite
make preview    # live-reload docs at http://localhost:8000
make docs       # build the HTML docs

See the Development guide for the full workflow.

Claude Code plugin

CMX ships a Claude Code plugin in .claude-plugin/ with skills that guide Claude through CMX's API and component usage when you work on a CMX project.

Project structure

cmx-python/
├── src/cmx/
│   ├── backends/        # markdown, components, md_table, html, latex
│   └── server/          # optional server stub
├── docs/                # Sphinx + MyST documentation
├── examples/core/       # numbered tutorial examples
├── tests/               # pytest suite + golden-file harness
├── .claude-plugin/      # Claude Code plugin
├── pyproject.toml       # project configuration
└── Makefile             # build automation

Contributing

Contributions are welcome. See the Development guide for setup, tests, and the publishing flow.

Authors

  • Ge Yang
  • Tom Tao

License

MIT — see LICENSE.

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.49.tar.gz (34.9 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.49-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cmx-0.0.49.tar.gz
  • Upload date:
  • Size: 34.9 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.49.tar.gz
Algorithm Hash digest
SHA256 0d2202d14d90542d78af8f10121cfe75e5d8f79168f58394f387db6ccab223d2
MD5 0e971931dbe4dba691fa06c47f9446ca
BLAKE2b-256 74ff8f27fd0fcdff75e8a32fe55a80cdc9e8587c93813eb27868dff2813c9258

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cmx-0.0.49-py3-none-any.whl
  • Upload date:
  • Size: 24.4 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.49-py3-none-any.whl
Algorithm Hash digest
SHA256 8056bbf2ba89060f35c093a000220d7a8732f3977a83d51824bfec9bd3f90fe8
MD5 8e76c75675e092cd9cd8915f986769ef
BLAKE2b-256 140aa9d82e335c340d5c8f85afbb832e351085f1004b3bb85e4a184fd632659f

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