Sign inDemoInstall


Package Overview
File Explorer

Install Socket

Protect your apps from supply chain attacks



An IPython extension to copy and/or pickle input/output lines or variables.




Table of Contents

* `About`_
* `Installation`_
* `Usage`_
* `%clip`_
* `%pickle`_
* `Development and Contributing`_
* `License`_



IPythonClipboard has two line magic functions, %pickle and %clip. 
Both of these functions remove the tedious and annoying task of using the mouse to copy text from the IPython terminal.

``%pickle`` pickles a variable and copies it to your clipboard, and can also unpickle the data in your clipboard.

``%clip`` copies the contents of a cell or line to your clipboard.



The IPythonClipboard extension is a standard Python package that can be installed using pip:


    pip install IPythonClipboard

After the extension has been installed you can use it in your IPython shell by doing:


    In [1]: %load_ext ipython_clipboard

If you find yourself using this extension regularly, then you can place it in your IPython profile so that it's always ready to use when you open IPython.

Go to ``~/.ipython/profile_default/`` and add ``ipython_clipboard`` to:


    c.TerminalIPythonApp.extensions = [

If ``profile_default`` isn't present you can create it by running ``ipython profile create`` in your terminal.




``%clip`` is used to copy the contents of an input or output line/cell like so:


    In [1]: 'Hello World! ' * 2
    Out[1]: 'Hello World! Hello World! '

    In [2]: %clip  # This will copy the output of the previous line
    In [2]: %clip 1  # This will copy the output of line 1
    In [2]: %clip _1 # This will copy the output of line 1
    In [2]: %clip _i1  # this will copy the input of line 1

You can also use IPython cache variables (ie. ``_ __ ___ _i _ii _iii``)

The docstring of ``%clip`` is:


  %clip [line_number]

    Copies an input or output line to the clipboard.
    `_i7` copies the  input from line 7
    `_7`  copies the output from line 7
    `7`   copies the output from line 7

    positional arguments:
        line_number     The line number to copy the contents from


``%pickle`` is used to pickle a variable into the clipboard or unpickle the clipboard's content into a variable or print it to the screen.


    In [1]: my_list = [42, ('a', 'b'), 'XY', {'key': 'value'}, 3.14, True]

    In [2]: my_list
    Out[2]: [42, ('a', 'b'), 'XY', {'key': 'value'}, 3.14, True]

    In [3]: %pickle my_list  # This will pickle `my_list` and store it in your clipboard
    In [3]: %pickle _2 # This will pickle the output of line 2 and store it in your clipboard (it will still be a list)
    In [3]: %pickle _  # This will copy the most recent output

You can also use IPython cache variables (ie. ``_ __ ___ _i _ii _iii``), however, using an input line will not pickle the variable or expression output, it will be stored a string instead.

The docstring of ``%pickle`` is:


  %pickle [--output OUTPUT] [var]

    Pickles a variable and copies it to the clipboard or un-pickles clipboard contents and prints or stores it.

    `%pickle` unpickle clipboard and print
    `%pickle v` pickle variable `v` and store in clipboard
    `%pickle _` pickle last line's output and store in clipboard
    `%pickle -o my_var` unpickle clipboard contents and store in `my_var`

    positional arguments:
        var     The variable to pickle.

    optional arguments:
        --output OUTPUT, -o OUTPUT
                        The variable to store the output to.


Development and Contributing
Pull requests are welcome :)
For major changes, please open an issue first to discuss what you would like to change.


`MIT <>`_


`Greg Toombs <>`_ for reviewing and helping me improve IPythonClipboard's line number functionality



Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.


Related posts

SocketSocket SOC 2 Logo


  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc