Repository navigation
json -> ujson. - #336
json -> ujson.#336ttezel wants to merge 1 commit into
Conversation
|
Hi, In API-Hour plugin for aiohttp, I use ujson if available: https://github.com/Eyepea/API-Hour/blob/master/api_hour/plugins/aiohttp/__init__.py#L4 Nevertheless, the usage of ujson should be optional, because you can have issues to install ujson, json is included in Python. |
|
-1 Second, Windows users have to install it additionally. Third, it brings completely different from stdlib json behaviour for happy debugging hours: I'm +1 to make JSON library configurable at project-wide level, however. For instance, couchdb-python has a solution to manage custom json lib on fly. Then users will pick the implementation their like without passing additional parameters and patching the aiohttp. |
|
@kxepal: Personally, I'm not a big fan to use global environment variable, this type of mechanism shot my foot several types on production because if you've forgotten this variable for X reasons, you have different behaviour between your VMs of prod, preprod, staging and dev: It's a nightmare to track this type of bugs. The developer has tested with another library than on production. I'm more partisan to declare that explicitly by the developer, because you'll have a stacktrace directly at the startup of the daemon if the library used by the developer is missed. Moreover, if in the same application you need to use another lib, because ujson can't transform data, you'll be happy to change that on runtime. I'd already have this issue with ujson, it isn't the silver bullet to replace json: you don't have always the same behaviour between both libraries. With @asvetlov, during PyCON sprint code, we made something like that for Nevertheless, we may not need that, we should only add a parameter to |
|
@GMLudo If you references to couchdb-python implementation, then environ variable is only one of the way to switch json module. It's also provides functional like However, I don't propose to take it as is, but to borrow the underlying idea. That idea is about to some proxy json module that is able to manage exact implementation behind it. How this would be implemented for aiohttp - that's a second sort question. |
|
I'm with @kxepal |
|
@kxepal: Thanks for the tip, I thought it was possible to choose Python library only via global environment. |
|
-1 for dependency, but I like @kxepal approach |
There are various benchmarks that show ujson beats json in performance. I wrote a very simple one here and posted the results there, it also showed ujson outperforming json. The tradeoff here is that ujson does not support
indentandsort_keysfunctionality (for pretty-printing) but I think aiohttp should not worry about that since users can pretty-print if they want.