sphinx-copybutton
A Sphinx extension that adds a one-click copy button to your code blocks.
Repository Health
Technical Analysis
sphinx-copybutton is a small Sphinx extension that adds a copy button to the code blocks in your documentation. Readers can copy an entire snippet to their clipboard with a single click, instead of manually selecting text — a small touch that noticeably improves the experience of code-heavy docs.
It is enabled with a single entry in your conf.py, works out of the box with Sphinx’s default and third-party themes, and offers CSS and JavaScript hooks to customize the button’s appearance and which prompt characters it strips when copying.
What You Get
- A copy button automatically added to every code block in your Sphinx docs
- Configurable stripping of prompt characters like >>> and $ from copied text
- CSS and JavaScript hooks to restyle or fine-tune the button behavior
Common Use Cases
- Letting readers copy shell commands and code snippets in one click
- Stripping interactive prompts so pasted commands run without editing
- Polishing developer documentation and tutorials with minimal effort
Under The Hood
Architecture
sphinx-copybutton is a Sphinx extension whose Python side (sphinx_copybutton/__init__.py) registers config values and injects a bundled JavaScript file and stylesheet into the built HTML. At runtime the client script (built from clipboard.js) scans code blocks, appends a button, and copies text via the browser clipboard API, applying the configured prompt-stripping regexes.
Tech Stack
A hybrid of Python (the Sphinx extension glue) and vanilla JavaScript plus CSS for the front-end button, with clipboard.js bundled for copy support. It is packaged with setup.py/setup.cfg and tested via tox, shipping static assets inside the Python package.
Code Quality
The codebase is small and focused, splitting a thin Python registration layer from the browser-side script, with documentation built by Sphinx itself as a living demo. Testing centers on doc builds and a bundled test.js rather than a large unit suite, appropriate for a presentation-layer extension.
API Design
The developer experience is close to ideal for its scope: one line in conf.py delivers the core feature, and a handful of well-documented options cover prompt stripping and styling without boilerplate. The ReadTheDocs site demonstrates every option live, making configuration easy to discover.
Used by 3 apps in this directory
Apache Airflow
Data Engineering
Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.
argilla
AI Development · Data Engineering
Collaborate on high-quality AI training data with a self-hosted annotation platform built for LLMs, NLP, and multimodal models.
skrub
Developer Tools
Turn messy real-world dataframes into machine learning features — no manual wrangling required.