Skip to main content

Clipboard utility for ipython

Project description

IPyclip

An IPyhon extension providing similar to windows' clip.exe

Setup

Install using:

pip install ipyclip  

You can now either load the extension manually with the ipython magic:

%load_ext ipyclip  

Or configure IPython to automatically load the extension by adding this to the IPython profile's configuration file:

c.InteractiveShellApp.extensions = [  
    'ipyclip'
]  

The clip object

When loading the extension, you get access to the clip object.
This is an instance of the ClipboardManager class, and it handles output and return value capture for you. Copying is done by calling pyperclip's copy method. clip is configured and injected into the shells user namespace when the extension is loaded.
Currently, only clip is provided out of the box, and the only stream it supports is sys.stdout.
The ClipboardManager class does support other stream objects in theory, but they weren't tested.

Usage

You interact with the clip object by "redirecting" the output of a statement into the object, like with shell redirection.

Copy Modes

  • > - Stream output.
  • >> - Stream output, add to last copied item.
  • / - return value, add to last copied item.
  • // - return value, add to last copied item.
  • | - auto (both stream and return value)

You can always copy the last execution's output by invoking:

copy()  

[!NOTE] Copying behavior. pyperclip.copy first turns the object it receives into a string by invoking its str(object), this means that objects lacking the __str__ method or raise an unhandled exception when __str__ is called will not be copied. This also means that when copying special characters (like \n) will behave as you would expect those characters to behave as part of the string that they're in. Ex:

"Hello\nworld!"
# Would be pasted like:
# Hello
# World

r"Hello\nworld"
# Would be pasted like:
# Hello\nworld

Stream Output

Override - >

{some_expression} > clip

Copies anything written to the stream during execution as is.

print("Some data") > clip  
# in clipboard: 'Some data\n'  
  
print("Some data", end="") > clip  
# in clipboard: "Some data"  
  
for i in range(5):  
    print(i) > clip  
  
# in clipboard:  
# "0\n1\n2\n3\n4\n"  

Concatenate - >>

{some_expression} >> clip

Adds the stream output to what was previously copied to the clipboard.

# last clip: ""
print("Some data") >> clip  
# in clipboard: Some data\n

# last clip: "Some data\n"
print("Other data", end="") > clip  
# in clipboard: Some data\nOther data
 
# last clip: Some data\nOther data
for i in range(5):  
   print(i) > clip  

# in clipboard: Some data\nOther data0\n1\n2\n3\n4\n

Return Value

Override - /

{some_expression} / clip

Copy the return value of the expression on the left. Stream output is ignored.

def ex1():
	return "Hello"

def ex2():
	return 1

def ex3():
	print("Hello")
	return "World"

def ex4():
	print("Example")
	# Return value is None	

ex1 / clip # In clipboard: Hello
ex2 / clip # In clipboard: 1
ex3 / clip # In clipboard: world
ex4 / clip # In clipboard: None

Concatenate - //

{some_expression} // clip

Adds the return value of the expression on the left to what was previously copied to the clipboard. Adds a line break to help separate the values.

def ex1():
	return "Hello"

def ex2():
	return 1

def ex3():
	print("Hello")
	return "World"

def ex4():
	print("Example")
	# Return value is None	

ex1 // clip # In clipboard: Hello
ex2 // clip # In clipboard: Hello\n1
ex3 // clip # In clipboard: Hello\n1world
ex4 // clip # In clipboard: Hello\n1world\nNone

Auto mode - |

{some_statement} | clip  

Copies both the stream output and the return value. Adds a line break between the stream output and return value if the stream output doesn't end with \n already.

print("Hello World") | clip # In clipboard: Hello World\nNone



def ex3():
	print("Hello")
	return "World"

def ex4():
	print("Example")
	# Return value is None	

ex1  clip # In clipboard: Hello
ex2 // clip # In clipboard: Hello\n1
ex3 // clip # In clipboard: Hello\n1world
ex4 // clip # In clipboard: Hello\n1world\nNone

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ipyclip-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ipyclip-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file ipyclip-0.1.0.tar.gz.

File metadata

  • Download URL: ipyclip-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for ipyclip-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9db81bfa305c6e6cfe593b2166b765ea56b980cb9bc0713be989b6dfd47a8f12
MD5 3691cdc7d20c62d972c167fb8540c172
BLAKE2b-256 591eed9a85355d8045bb341d896b6da2a6a99fc64ce4b30cf6a657dfcd544920

See more details on using hashes here.

File details

Details for the file ipyclip-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ipyclip-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for ipyclip-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 87e340f115e5b5e9d5fcf6406e8578241beafa24403131a0330e640cf7c6e03d
MD5 e422eed70fea78998f80e738f39150be
BLAKE2b-256 9b09795715d2d460c8ce4ca99a4917ece566c4e3b1ec28026001a8c7e60ea474

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page