rich-codex 1.2.11


pip install rich-codex

  Latest version

Released: Apr 22, 2025


Meta
Author: Phil Ewels
Maintainer: Phil Ewels
Requires Python: >=3.7

Classifiers

Development Status
  • 3 - Alpha

Intended Audience
  • Developers

Operating System
  • OS Independent

Programming Language
  • Python
  • Python :: 3 :: Only
  • Python :: 3.7
  • Python :: 3.8
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12

rich-codex โšก๏ธ๐Ÿ“–โšก๏ธ

A GitHub Action / command-line tool which generates screengrab images of a terminal window, containing command outputs or code snippets.

๐Ÿ“š Documentation: https://ewels.github.io/rich-codex/ ๐Ÿ“š

PyPI Version

Introduction

Having code examples in your documentation is a fantastic way to help users understand what to expect from your tool.

Using terminal screenshots is a good way to do this because:

  • ๐ŸŒˆ Coloured terminal output is supported
  • โ†”๏ธ You can fit in long lines without scrolling or cropping (images are auto-resized)
  • ๐Ÿ˜Ž They look cool

However, manually generating these screenshots is a pain ๐Ÿ‘Ž๐Ÿป Remembering to update them every time you make a minor change means that they can easily get out of date.

Rich-codex automates this process for you. It searches markdown code for images with shell commands or code snippets. It runs these commands and saves a terminal screen-grab at the embedded path.

Typical use cases:

  • ๐Ÿ“ท Example CLI tool outputs that automatically stay in sync with your package
  • โ™ป๏ธ Syntax-highlighted code snippets that are always up to date with your examples/
  • ๐Ÿคฉ Fast and simple images for your docs with minimal setup

Quickstart

  1. ๐Ÿ“– Write some markdown docs, use an image tag with a backtick command inside:

    ![`cat docs/cat.txt | lolcat -S 1`](docs/img/cat.png)
    
  2. ๐Ÿค– Add a GitHub Action to automatically run the command, generate the image and commit to the repo:

    on: [push]
    jobs:
      rich_codex:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v3
    
          - name: Install your custom tools
            run: pip install lolcat
    
          - name: Generate terminal images with rich-codex
            uses: ewels/rich-codex@v1
            with:
              commit_changes: "true"
    
  3. ๐ŸŒˆ Enjoy reading your documentation My cat rainbow

How it works

Rich-codex is a command-line tool that you can run via a GitHub action or as a command line tool. It works with any markdown (including GitHub READMEs).

It collects either commands or code snippets, together with output filenames and configuration options. Commands are run in a subprocess and the standard output & standard error collected. These are then rendered as an image using Textualize/rich.

Rich-codex creates the images that your markdown docs expect. It doesn't require a HTML build-step and doesn't make any changes to your markdown or its output. As such, it's compatible with any documentation engine, including rendering markdown on github.com.

Rich-codex needs inputs (commands / snippets) and output filenames to work. These can be configured in four different ways:

  • ๐Ÿ–ผ Markdown images
    • Search markdown files for image tags with command alt text. eg: ![`rich-codex --help`](docs/img/rich-codex-help.svg)
  • ๐Ÿ’ฌ Markdown comments
    • Search markdown files for special HTML comments.
  • โžก๏ธ Command-line / action inputs
    • Specify a command or snippet using the action with inputs.
  • โš™๏ธ Config files
    • Use one or more YAML config files for multiple images and more complex customisation.

Images can be generated as SVG, PNG or PDF (detected by filename extension).

Keep reading! ๐Ÿ‘‰ https://ewels.github.io/rich-codex/

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
rich (>=12.4.3)
rich-click (>=1.5)
importlib-metadata
pyyaml
levenshtein (>=0.18.1)
jsonschema
GitPython