Registry / devops / sphinx-copybutton

sphinx-copybutton

JSON →
library0.5.2pypypi✓ verified 24d ago

sphinx-copybutton is a Sphinx extension that adds a 'copy' button to each of your code cells in Sphinx documentation. It is currently at version 0.5.2, actively maintained, and releases generally align with bug fixes, minor enhancements, or updates to stay compatible with Sphinx itself.

pip install sphinx-copybutton
INSTALL
IMPORT
SIG · SPHINX-COPYBUTTON
S
sphinx-copybutton
devopspythonv0.5.2
Install
5.4s avg
Import
Disk
94MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 92.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 5.4s · import 0.000s · 93MB
94MB installed
● package 94MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sphinx_copybutton
# In conf.py extensions = [ 'sphinx_copybutton' ]
Sphinx extensions are activated by adding their string name to the 'extensions' list in your Sphinx project's conf.py file, not via Python import statements.

To enable sphinx-copybutton, first install it using pip. Then, add 'sphinx_copybutton' to the `extensions` list within your Sphinx project's `conf.py` file. You can optionally configure its behavior, for example, by setting `copybutton_prompt_text` to exclude shell prompts from being copied.

# 1. Install the package: # pip install sphinx-copybutton # 2. Add 'sphinx_copybutton' to your conf.py extensions list: # conf.py import os import sys project = 'My Project' copyright = '2023, Author' extensions = [ 'sphinx.ext.autodoc', 'sphinx_copybutton' ] # Optional: Configure prompt text for copy button (example) copybutton_prompt_text = "$ " copybutton_prompt_is_regexp = False
Debug
Known issues
breakingIn v0.3.0, the handling of `copybutton_prompt_text` regex strings changed to use raw string formatting. This required users to update their `copybutton_prompt_text` string to remove previous 'double escaping'.
fix
Review your `copybutton_prompt_text` configuration. If you were double-escaping backslashes, you now only need a single escape (e.g., `"\\$ "` became `"\$ "`). Refer to the v0.3.0 release notes.
affects: >=0.3.0
gotchaStarting with v0.5.0, the copy button design was updated to match GitHub's behavior, and the SVG icon is directly inserted into the HTML instead of being linked via an `<img>` tag. This can break custom CSS that targeted the `<img>` element for styling the button.
fix
Update any custom CSS targeting the copy button to reflect the new SVG-based structure. You may need to target the `svg` element or its parent container directly. Inspect the generated HTML to identify the correct selectors.
affects: >=0.5.0
gotchaIn v0.5.2, a bug fix reversed the default exclusion of the `.gp` class from copy button processing. This change might unintentionally include prompt text in copied code for users who previously relied on `.gp` to be excluded by default.
fix
If you use code blocks with `... prompt` directives (which often apply the `.gp` class) and find prompts are now copied, explicitly configure `copybutton_prompt_text` with a regular expression (e.g., `^\$ `) to exclude them, ensuring `copybutton_prompt_is_regexp = True`.
affects: >=0.5.2
Upgrade
Version history
0.5.2latest on PyPI · released Apr 14, 2023
Audit
Dependencies
SphinxrequiredRequired to build documentation. sphinx-copybutton is a Sphinx extension.
Agent activity
14 hits · last 30 days
node
12
Resources
sphinx-copybutton — pip install sphinx-copybutton · libregistry