Thursday, August 21, 2008

jsonpickle 0.1.0 released

Thanks to Adam for finding the bug that missed longs as a primitive type.

In addition to that quick bugfix, jsonpickle has undergone a major API change. At the core of this change is jsonpickle's new preference for python-cjson over simplejson. While python-cjson is not a requirement, if it is installed on the machine, jsonpickle will use python-cjson. python-cjson is faster for jsonpickle (see the benchmarks), but simplejson is still useful on Google's App Engine.

So the API change moves away from the load/loads/dump/dumps functions in the tradition of simplejson towards a simple encode/decode set of functions. If you need to save the output or read a file, you can do that on your own, then send that data into the encode/decode methods. While it may have been smart to deprecate these functions first, I want to get the API correct early on and prevent cruft.

The update example:

>>> import jsonpickle
>>> from jsonpickle.tests.classes import Thing

Create an object.
>>> obj = Thing('A String')
>>> print
A String

Use jsonpickle to transform the object into a JSON string.
>>> pickled = jsonpickle.encode(obj)
>>> print pickled
{"classname__": "Thing", "child": null, "name": "A String", "classmodule__": "jsonpickle.tests.classes"}

Use jsonpickle to recreate a Python object from a JSON string
>>> unpickled = jsonpickle.decode(pickled)
>>> print
A String

Grab the new version.

Thanks also go out to the Joose developers for integrating jsonpickle into their product!

Friday, August 8, 2008

Announcing stopwatch 0.3.0 and the 7 Oars code repository

The 7 Oars code repository is a centralized location for small python programs and modules from 7 Oars, instead of having multiple wikis and source control systems for relatively small projects.

The first module as part of the code repository is stopwatch. stopwatch is a very simple python module for measuring time. I typically use it to measure the execution time of specifc parts of code or data processing threads. For example:

>>> import stopwatch
>>> t = stopwatch.Timer() # immediately starts the clock
>>> t.elapsed # elapsed time in seconds
>>> t.elapsed
>>> str(t) # pretty print
1.8 sec
>>> for i in xrange(0, 10000)
>>> pass
>>> t.elapsed # still going
>>> t.stop() # stop the timer
>>> t.elapsed
>>> t.elapsed # it will not go any more


via PyPi:
easy_install -U stopwatch

via subversion:
svn checkout stopwatch