Since simplejson is not part of CouchDB-python, nothing? You can
upgrade your simplejson version separately, if you want. Recent
simplejson versions should be relatively fast (not sure what version
you got there).
Cheers,
Dirkjan
It's the other way around (sniopet from client.py):
try:
import simplejson as json
except ImportError:
import json # Python 2.6
So it tries simplejson first, then falls back to json.
Cheers,
Dirkjan
couchdb-python only relies on simplejson when the python version is less than (I believe) 2.6. Above that it uses the built-in python modules for support. Whenever couchdb-python works on python3 we should get this boost automatically.
I evaluated a few different alternatives to simplejson last summer but found compatible problems with all of them.
On Thu, Jun 25, 2009 at 8:26 PM, Randall Leeds <randal...@gmail.com> wrote:
couchdb-python only relies on simplejson when the python version is less than (I believe) 2.6. Above that it uses the built-in python modules for support. Whenever couchdb-python works on python3 we should get this boost automatically.
Builtin module starting from 2.6 is simplejson. It's just renamed to json.
On Thu, Jun 25, 2009 at 11:09, Dirkjan Ochtman <dir...@ochtman.nl> wrote:Since simplejson is not part of CouchDB-python, nothing? You can
upgrade your simplejson version separately, if you want. Recent
simplejson versions should be relatively fast (not sure what version
you got there).
No. The rationale behind this order is that simplejson has a faster
release cycle than the stdlib, so if you have it installed, it's
likely to be a newer version (compared to the one bundled with Python).
Ideally, there'd be an explicit way to tell CouchDB-Python which JSON
module to use. If we had that, it'd be pretty easy to also add cjson
support. The simplest option would be to read from an environment
variable (or a module-level variable), but that's rather ugly, and
only works nicely when you don't have more than one application per-
process. Anything else would require accepting and passing through the
JSON module choice in all the various APIs, which is probably rather
tedious.
So that's why we only support simplejson right now, and hope it just
gets faster and faster :P
Cheers,
--
Christopher Lenz
cmlenz at gmx.de
http://www.cmlenz.net/
>>> import cjson
>>>
>>> import sys
>>> sys.modules['simplejson'] = cjson
>>>
>>> import simplejson
>>> simplejson
<module 'cjson' from
'/Users/anand/.python-eggs/python_cjson-1.0.6-py2.5-macosx-10.5-i386.egg-tmp/cjson.so'>
-Anand
I have a change ready in my local workspace that adds a couchdb.json
module, which is used as a thin abstraction layer between the actual
JSON module and the rest of couchdb-python. Instead of an environment
variable, it uses a module-level global to determine which library
gets used.
Example:
from couchdb import json
json.use(module='cjson')
Currently support modules are 'json' (stdlib), 'simplejson', and
'cjson'. The current behavior remains the default, i.e. try simplejson
first, and fall back to stdlib-json.
You can also plug in a different JSON encoding/decoding routines using
the same use() function:
from couchdb import json
json.use(encode=myencodefun, decode=mydecodefun)
I think this is pretty nice, and am only waiting for svn@googlecode to
come back to life to check it in.
Comments?
Okay it's checked in now:
<http://code.google.com/p/couchdb-python/source/browse/trunk/couchdb/json.py
Changed in r172. You can now specify the module either as a string or
by passing in the module object itself.
(Internally, it just looks for module.__name__ and works with that.
Otherwise we'd need to import all the supported modules up front to be
able to make the comparison and correctly map the encode/decode
functions, which would be too expensive IMHO.)
Thanks,
I don't really like this. I think it's counter-intuitive and awkward
that module= would work with simplejson but not cjson. What about some
random JSON module that had loads/dumps functions, but different
parameters? (We currently call dumps with allow_nan=False,
ensure_ascii=False)
I suppose it comes down to a matter of taste in this case, and the
difference isn't all that big ;)
Cheers,