Skip to main content

Release Notes Downloads GitHub CI Status License: MIT

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.
  • %pickle magic 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:

  1. Automatic Fallback: By default, pyperclip uses determine_clipboard() to find a working backend. If it cannot find a local GUI clipboard (like xclip, wl-clipboard, or pbcopy) and it detects that it is running inside a terminal (by checking if the TERM environment variable is set and sys.stdout or sys.stderr is a TTY), it will automatically fall back to the new OSC 52 backend.
  2. 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

MIT License


This project was created from iloveitaly/python-package-template

Metadata

Release files for ipython-copy 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ipython-copy 0.1.2
File Size Uploaded Provenance
ipython_copy-0.1.2.tar.gz 4.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ipython-copy 0.1.2
File Interpreter ABI Platform
ipython_copy-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.4 kB

Release files / ipython_copy-0.1.2.tar.gz

Download URL ipython_copy-0.1.2.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
02722b5e0c3189178964c0ccf354301f3f14c10b0e41adcad0f9987333aa463b
BLAKE2b-256 checksum
How to use checksums
04777731498de49ad08f100d082ee8272d29a44b54113b07e28329118e0818d1
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / ipython_copy-0.1.2-py3-none-any.whl

Download URL ipython_copy-0.1.2-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf3eff93d79cd62f8b6de3f1c731975965a608803e7b05c2ccbe1a31da0f77af
BLAKE2b-256 checksum
How to use checksums
8c793554f4ea233bd888e345da3a9bc7c7a55452d624931181a27df57a88ac8b
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for ipython-copy 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page