Skip to content


Point %pastebin to gist #1670

merged 2 commits into from

3 participants

IPython member

Unfortunately has closed down. This updates the %pastebin magic to use gists instead. The results look like this:

We don't try to use any of the advanced features of gist, such as authenticating to make gists associated with your account. That could be added if there's demand for it, but for now we just send some content and return a URL.


Change the docstring to github gist maybe.

Do you think a raw_input for an optionnal description could be usefull ?

IPython member

Since gist allows for a file description, it would be nice to add that as an optional flag (the current default is fine if not given). Naming the file could also be done, but I think that's less important. But I think the description field could in fact be useful.

IPython member

Thanks both, I've made those changes.

IPython member

And tested them, of course:

IPython member

Great! Merging now, thanks.

@fperez fperez merged commit 970a0df into ipython:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 32 additions and 6 deletions.
  1. +32 −6 IPython/core/
38 IPython/core/
@@ -21,6 +21,7 @@
import inspect
import imp
import io
+import json
import os
import sys
import shutil
@@ -30,7 +31,7 @@
from StringIO import StringIO
from getopt import getopt,GetoptError
from pprint import pformat
-from xmlrpclib import ServerProxy
+from urllib2 import urlopen
# cProfile was added in Python2.5
@@ -2231,15 +2232,40 @@ def magic_save(self,parameter_s = ''):
print cmds
def magic_pastebin(self, parameter_s = ''):
- """Upload code to the 'Lodge it' paste bin, returning the URL."""
+ """Upload code to Github's Gist paste bin, returning the URL.
+ Usage:\\
+ %pastebin [-d "Custom description"] 1-7
+ The argument can be an input history range, a filename, or the name of a
+ string or macro.
+ Options:
+ -d: Pass a custom description for the gist. The default will say
+ "Pasted from IPython".
+ """
+ opts, args = self.parse_options(parameter_s, 'd:')
- code =
+ code =
except (ValueError, TypeError) as e:
print e.args[0]
- pbserver = ServerProxy('')
- id = pbserver.pastes.newPaste("python", code)
- return "" + id
+ post_data = json.dumps({
+ "description": opts.get('d', "Pasted from IPython"),
+ "public": True,
+ "files": {
+ "": {
+ "content": code
+ }
+ }
+ }).encode('utf-8')
+ response = urlopen("", post_data)
+ response_data = json.loads('utf-8'))
+ return response_data['html_url']
def magic_loadpy(self, arg_s):
"""Load a .py python script into the GUI console.
Something went wrong with that request. Please try again.