Aiohttp: support for ujson as json parser

Created on 28 Mar 2017  路  7Comments  路  Source: aio-libs/aiohttp

By default aiohttp.Session uses standard json, which is slow.

Allowing ujson via

try:
    import ujson as json
except ImportError:
    import json

will reduce json processing time, if ujson is installed.

outdated

Most helpful comment

You can do this with two lines:

import ujson
aiohttp.ClientSession(json_serialize=ujson.dumps)

All 7 comments

You can do this with two lines:

import ujson
aiohttp.ClientSession(json_serialize=ujson.dumps)

Yep, just mine suggestion is for support it out of box without direct parser set.

Why not rapidjson instead? It's faster.

But my point is that we cannot and shouldn't care about all the JSON implementations, but provide an easy way to use the one you like as default. And there is a support for that.

ASFAICS, usjon API is not compatible with stdlib json, for instance it serializes basically everything
in contrast to json where you need to pass default callback to serialize custom objects.
"Explicit is better than implicit" remember? )
Shadowing json with such a "try-import" might lead to random errors when one installation has usjon installed and other similar does not.

Accepted concern. Closing.

added son_serialize info to client.rst

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a [new issue] for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that [new issue].

Was this page helpful?
0 / 5 - 0 ratings