This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

MethodPickle (methodpickle) is a quick library that allows simple pickling and unpickling of function and method invocation. Function & method module loading is handled automatically, and methods can be specified by name as well.

The ability to pickle a method invocation allows for queueing and delayed execution of arbitrary code. This is useful for parallelization, logging, queueing, etc.


Steve Lacy <>
Twitter: @sklacy

Features & Usage

Please see the unit tests in for some more verbose examples, but I’ll go through a quick example here.:

from methodpickle.defer import defer

# These are the functions that we're going to defer
def some_function(x, y):
    return x*x + y*y

# methodpickle supports deferring execution of classmethods as well, so
# here's a simple class with a method:
def some_class(object):
    def __init__(self, x):
        self._x = x

    def calc(self, y):
        return (self._x * self._x + y * y)

if __name__ == '__main__':

    # the defer function takes a method and it's arguments, and turns it
    # into a pickleable object.
    storable_func = defer(some_function, 5, 4)

    # So, we pickle that guy into a string.
    method_str = pickle.dumps(storable_func)

    # You can now take method_str and do whatever you like with it.  Write
    # it to a database, send it to another process, put it in your logs,
    # whatever.

    # Then, you can unpickle the stored method invocation, and run it,
    # like this:
    recovered_func = pickle.loads()
    assert( == 5*5 + 4*4)

    # methodpickle also supports pickling of classmethods.  Note that your
    # class must support pickling and the methods should have no side
    # effects.

    i = some_class(2)
    storable_classmethod = defer(i, 3)

    classmethod_str = storable_method.dumps()
    recovered_classmethod = pickle.loads(classmethod_str)
    assert( == 2*2 + 3*3)

For convenience, there’s also a decorator form of the defer function, called deferred. Again, see the implementation or for more details.


  • All arguments to functions must themselves be pickle-able. This
    includes ‘self’ for class method invocations
  • Functions and classes must be at the module level. Inner classes and
    inner functions don’t have an easy-to-discover import path, so all the deferred functions should be at the top level of your module. I’d suggest putting them all in the same file (say,
  • All method arguments are deepcopied at the time of the deferral. Thus,
    if you pass a very large datastructure to the deferral methods, it may have a performance impact. In addition, if you pass a mutable datastructur (dict, list, etc.) then subsequent modifications will have no effect.
  • Watch out for double invocation of functions & methods. This is both
    a feature and a caveat. Once you pickle a function call, that value could be unpickled and run more than once. Watch out for anything that has unexpected side effects!
Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
methodpickle-0.1.0.linux-x86_64.tar.gz (7.4 kB) Copy SHA256 Checksum SHA256 any Dumb Binary Feb 12, 2011

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting