https://github.com/victorfsf/pickleclip
Simple clipboard tool for Python pickled objects.
https://github.com/victorfsf/pickleclip
clip clipboard pickle pickleclip
Last synced: about 1 year ago
JSON representation
Simple clipboard tool for Python pickled objects.
- Host: GitHub
- URL: https://github.com/victorfsf/pickleclip
- Owner: victorfsf
- License: mit
- Created: 2017-05-19T13:00:59.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-10-05T14:58:52.000Z (over 5 years ago)
- Last Synced: 2025-03-24T15:02:40.468Z (about 1 year ago)
- Topics: clip, clipboard, pickle, pickleclip
- Language: Python
- Size: 27.3 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pickleclip
[](https://badge.fury.io/py/pickleclip)
[](https://circleci.com/gh/victorfsf/pickleclip)
[](https://coveralls.io/github/victorfsf/pickleclip)
[](https://landscape.io/github/victorfsf/pickleclip/master)
*A Simple clipboard tool for Python (2.7+ and 3.4+) pickled objects.*
## Installation
If you're using **Linux**, be sure to install [pyperclip](https://github.com/asweigart/pyperclip)'s dependency, xclip:
```
sudo apt-get install xclip
```
Then, install via pip:
```
pip install pickleclip
```
## Usage:
Using `pickleclip` is as simple as copying and pasting text:
```python
In [1]: import pickleclip as picklec
In [2]: picklec.copy({'hello': 'world'})
In [3]: picklec.paste()
Out[3]: {'hello': 'world'}
```
To copy functions or any object that the native pickle package can't handle, use dillcopy/dillpaste (it'll use [dill](https://github.com/uqfoundation/dill) instead of pickle):
```python
In [1]: import pickleclip as picklec
In [2]: def add(x, y):
...: return x + y
In [3]: picklec.dillcopy(add)
In [4]: picklec.dillpaste()
Out[4]:
In [5]: picklec.dillpaste()(5, 10)
Out[5]: 15
```
Pickleclip will copy any python object supported by pickle (or dill) into your clipboard. You can paste it anywhere you'd like (in another shell, for instance), as long as you use the `pickleclip.paste` function.
### Copying from Python 3 to Python 2 using pickle
To get Python 3 objects to unpickle on Python 2, specify `protocol=2` when copying. Although pickle will try to map the new Python 3 names to the old module names used in Python 2, so that the pickle data stream is readable with Python 2, this does not come without limitations.
Going from Python 2 to Python 3 is even less trivial, and will mostly only work for the simplest cases. See also [pickle-compat](https://pypi.org/project/pickle-compat/).
By default, the highest [pickle protocol](https://docs.python.org/3/library/pickle.html#pickle-protocols) available to the interpreter is used. The higher the protocol used, the more recent the version of Python needed to read the pickle produced.
##### Python 3 shell:
```python
In [1]: import pickleclip as picklec
In [2]: picklec.copy({'hello': 'world'}, protocol=2)
```
##### Python 2 shell:
```python
In [1]: import pickleclip as picklec
In [2]: picklec.paste()
Out[2]: {'hello': 'world'}
```
### Copying from different Python versions using dill
It should work fine with basic objects (str, int, float, list, set, dict...), but it won't work with nothing too "fancy", (functions, custom objects...).