IPython magic commands to copy text, variables, and history to your system clipboard.
Project description
Copy Text, Variables, and History to Clipboard from IPython
I built this to solve a constant point of friction: getting data out of a remote or local REPL and into my system clipboard. This is a cross-platform IPython plugin that adds smart %copy and %pickle magic commands. It seamlessly handles both local GUI clipboards and headless remote SSH sessions.
Installation
uv add ipython-copy
Once installed, load it in your IPython session:
%load_ext ipython_copy
To load it automatically every time you start IPython, you can add it to your ipython_config.py in the c.InteractiveShellApp.extensions list.
Usage
The plugin exposes a %copy magic command that tries to be smart about what you want to copy. It handles standard string inputs, looks up variables in your namespace, and can even reference your output history.
# Copy the last output
%copy
# Copy the output from a specific history line
%copy 7
# Copy the string representation of a specific variable
%copy my_var
# Copy a literal string
%copy hello world
You can also use it as a cell magic to easily copy multi-line blocks of text:
%%copy
Even multi
lines
work!
If you are dealing with complex data structures, use the %pickle magic to serialize Python objects directly to your clipboard and unpickle them later.
Features
- Smart line magic (
%copy) for copying the last output, history lines, or specific variables. - Cell magic (
%%copy) for cleanly copying multi-line blocks. %picklemagic to serialize and copy complex Python objects directly to the clipboard.- Fully cross-platform using
pyperclip. - Automatic headless and remote server support via OSC 52 sequence fallbacks.
Remote Environments and OSC 52
I frequently work in tmux on remote servers, which used to make clipboard access a nightmare. This plugin relies on pyperclip, which handles remote clipboard access automatically without you needing to configure anything.
Here is how it works under the hood:
- Automatic Fallback: By default,
pyperclipusesdetermine_clipboard()to find a working backend. If it cannot find a local GUI clipboard (likexclip,wl-clipboard, orpbcopy) and it detects that it is running inside a terminal (by checking if theTERMenvironment variable is set andsys.stdoutorsys.stderris a TTY), it will automatically fall back to the new OSC 52 backend. - Explicit Selection (Optional): If you want to bypass GUI clipboards and force the use of OSC 52, you can explicitly set it in your Python code:
import pyperclip pyperclip.set_clipboard("osc52")
The only external requirement: While the library requires no configuration, your terminal emulator (e.g., iTerm2, Alacritty, Windows Terminal, Kitty) must support the OSC 52 escape sequence.
- Most modern terminals support it out of the box.
- Some terminals might have security settings that disable OSC 52 by default or prompt the user for permission the first time a script tries to write to the clipboard.
Alternatives
- IPythonClipboard - cannot copy a variable to the clipboard, only line numbers.
- bwagner/clip.py - can copy variables to clipboard, but relies on AppKit.
- nova77/clip.py - the original script that this project iterated upon.
MIT License
This project was created from iloveitaly/python-package-template
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ipython_copy-0.1.2.tar.gz.
File metadata
- Download URL: ipython_copy-0.1.2.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02722b5e0c3189178964c0ccf354301f3f14c10b0e41adcad0f9987333aa463b
|
|
| MD5 |
b8f0bdb1d812df804cee121a734b4d00
|
|
| BLAKE2b-256 |
04777731498de49ad08f100d082ee8272d29a44b54113b07e28329118e0818d1
|
File details
Details for the file ipython_copy-0.1.2-py3-none-any.whl.
File metadata
- Download URL: ipython_copy-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf3eff93d79cd62f8b6de3f1c731975965a608803e7b05c2ccbe1a31da0f77af
|
|
| MD5 |
d2d70d385cea0f12e6982d294404e9ac
|
|
| BLAKE2b-256 |
8c793554f4ea233bd888e345da3a9bc7c7a55452d624931181a27df57a88ac8b
|