rtyler / py-yajl

py-yajl provides Python bindings for the Yajl JSON encoder/decoder library
http://rtyler.github.com/py-yajl
74 stars 18 forks source link

Iterate over a stream of json objects + support new yajl version + bug fixes #33

Open iainb opened 13 years ago

iainb commented 13 years ago

Note: I've aimed to keep backwards API compatibility but I've made some additions, how these new additions actually work are open to discussion.

I think that this patch aims to address issues:

The main improvement is that you can now write something like:

import yajl
import sys

for i in yajl.Decoder(allow_multiple_values=True,stream=sys.stdin):
    print i

Which will let you iterate over a stream of json objects read from the processes std input channel. It's not too slow either, on my core2duo a yajl based producer / consumer connected via a unix pipe with a very basic object can process about 100,000 json objects/sec.

I don't think the iterator method will handle non blocking sockets very well at the moment, it may not handle them at all - I've not tested it yet. If the file object is in blocking mode the iterator handles that fine.

I've also fixed a number of bugs relating to memory management (including issue #32) along the way.

Summary of changes.

The unit tests still pass and the current version also supports python 3. Though I really should write some more unit tests for the new features and some documentation to accompany them.

rtyler commented 10 years ago

@iainb I was reminded again of this pull request, would you like me to transfer ownership of the yajl module on pypi over to you?