Skip to content
A fast, modern Sphinx theme with dark mode, full-text search, and Alpine.js interactivity. Star on GitHub ★

sphinx-copybutton

sphinx-copybutton adds a copy-to-clipboard button to every code block. Lumina positions and styles it automatically.

Setup

uv add sphinx-copybutton
conf.py
extensions = ["sphinx_copybutton"]

No additional configuration needed. The button appears on hover in the top-right corner of any code block — try it on any example on this page.

Filtering Prompt Characters

If your code blocks include shell prompts (e.g., $ for bash, >>> for Python REPL), configure the extension to strip them when copying:

conf.py
copybutton_prompt_text = r">>> |\.\.\. |\$ |> "
copybutton_prompt_is_regexp = True

This strips >>>, ..., $, and > prompts so readers copy only the actual commands.

See also

Code Blocks — for syntax highlighting, line numbers, captions, diffs, and tabbed code examples.