lodgeitlib – programmatic access to the lodgeit

Platforms: Unix, Windows

A convenient client library for the Lodgeit pastebin software.

Paste retrival and creation


An instance of Lodgeit for http://paste.pocoo.org.


An instance of Lodgeit for http://bpaste.net


Deprecated alias for pocoo_pastebin


a list of Lodgeit objects for all known lodgeit pastebins

class lodgeitlib.Lodgeit(pastebin_url, service_url=None, caching=True)

Client access to Lodgeit pastebins.

This class uses the JSON RPC service to retrieve or create pastes in pastebins, which are based on the Lodgeit software.

It performs internal caching, if caching is True. If caching is enabled, pastes, which are fetched by id, are first looked up in an internal cache.


get_last_paste() and get_recent_pastes() are not cached, because there is no way to determine the age of a paste from the cache.

The list of available languages (see languages) is fetched, when it’s first needed, and cached for any later access, even if caching is False. You may however use reset_languages() to reset this cache.

This class is not thread-safe, at least not if caching is enabled. Multiple threads should not access this pastebin without proper synchronisation.


The url of the pastebin web interface. Used as base url to create paste urls. Consider this read only.


The url of the JSON-RPC service of this pastebin. Consider this read only.


The hostname of this paste as string.


Whether paste caching is enabled or not.

new_paste(code, language, parent=None, filename='', mimetype='', private=False)

Create a new paste.

code is a unicode string with the code to be pasted. language is a string with the programming or markup language, the code is written in (used for server-side highlighting). parent is the parent paste, either a string or integer with a paste ID or URL, or as Paste object. filename and mimetype a strings providing the name of the file, the paste contents were read from, and the mimetype of the paste contents. private is a boolean inidicating, whether the paste should be private or not.

Pastes can have a parent paste. This is part of the “paste reply” functionality of the Lodgeit, which is described in detail under Advanced features.

Private pastes (private is True) do not get a nummeric id, but only a random hash, and do not appear in the list of all pastes.

Return the id of the created paste as integer (public pastes) or as string (private pastes). Raise UnsupportedLanguageError, if language is not supported (e.g. not contained in languages).


Retrieve the paste with the given ID or URL.

id_or_url is a string or integer containing a paste ID or a paste URL.

The retrieved paste is cached, if caching is True.

Return the Paste object for id or None, if there is no such paste.


Retrieve the last paste and return it as Paste object.

The return value of this method is never cached.


Retrieve the most recent pastes.

amount is an integer specifying how many of the most recent pastes should be retrieved. This method is never cached.

Return a list of Paste objects.


Extract a paste id from the given url.

url is a string containing the url of a paste.

Return the paste id as string, or raise ValueError, if a valid id could not be found in the given url.


The languages supported by the paste bin as a mapping from the language identifier to a descriptive name of this language.


True, if the internal language cache is filled, False otherwise.


Clear the internal language cache.

exception lodgeitlib.UnsupportedLanguageError

Inidicate an unsupported language.

Paste data

class lodgeitlib.Paste

A namedtuple for a single paste.


The lodgeit instance, by which this paste was fetched.


The id of this paste as integer.


The pasted code as unicode string.


The datetime of publication of the paste.


The programming language, the paste was written in, as unicode string.


The id of the parent paste as integer, or None, if this paste has no parent.


The relative url of this paste. This url is relative to the url of the lodgeit, that fetched this paste.


The complete url of this paste as string.


The descriptive name of the language of this paste as string.


Fetch the parent paste of this paste.

Return the parent paste as Paste instance, or None, if this paste has no parent.

Usage example

>>> from lodgeitlib import pocoo_pastebin
>>> code = u'print "Hello „World“"'
>>> paste_id = pocoo_pastebin.new_paste(code, 'python', private=True)
>>> paste_id
>>> paste = pocoo_pastebin.get_paste_by_id(paste_id)
>>> print paste.code
print "Hello „World“"
>>> paste.language_desc
>>> paste.parent_id
>>> paste.get_parent()
>>> paste.url
>>> pocoo_pastebin.id_from_url(paste.url)

Table Of Contents

Previous topic

lodgeitlib – Easy pastebin access

Next topic


This Page