You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
18 KiB

4 years ago
  1. Metadata-Version: 2.1
  2. Name: ujson
  3. Version: 1.35
  4. Summary: Ultra fast JSON encoder and decoder for Python
  5. Home-page: http://www.esn.me
  6. Author: Jonas Tarnstrom
  7. Author-email: jonas.tarnstrom@esn.me
  8. License: BSD License
  9. Download-URL: http://github.com/esnme/ultrajson
  10. Platform: any
  11. Classifier: Development Status :: 5 - Production/Stable
  12. Classifier: Intended Audience :: Developers
  13. Classifier: License :: OSI Approved :: BSD License
  14. Classifier: Programming Language :: C
  15. Classifier: Programming Language :: Python :: 2.4
  16. Classifier: Programming Language :: Python :: 2.5
  17. Classifier: Programming Language :: Python :: 2.6
  18. Classifier: Programming Language :: Python :: 2.7
  19. Classifier: Programming Language :: Python :: 3
  20. Classifier: Programming Language :: Python :: 3.2
  21. UltraJSON
  22. =============
  23. .. image:: https://travis-ci.org/esnme/ultrajson.svg?branch=master
  24. :target: https://travis-ci.org/esnme/ultrajson
  25. UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for Python 2.5+ and 3.
  26. For a more painless day to day C/C++ JSON decoder experience please checkout ujson4c_, based on UltraJSON.
  27. .. _ujson4c: http://github.com/esnme/ujson4c/
  28. | Please checkout the rest of the projects in the Ultra series:
  29. | http://github.com/esnme/ultramemcache
  30. | http://github.com/esnme/ultramysql
  31. To install it just run Pip as usual::
  32. $ pip install ujson
  33. ============
  34. Usage
  35. ============
  36. May be used as a drop in replacement for most other JSON parsers for Python::
  37. >>> import ujson
  38. >>> ujson.dumps([{"key": "value"}, 81, True])
  39. '[{"key":"value"},81,true]'
  40. >>> ujson.loads("""[{"key": "value"}, 81, true]""")
  41. [{u'key': u'value'}, 81, True]
  42. ~~~~~~~~~~~~~~~
  43. Encoder options
  44. ~~~~~~~~~~~~~~~
  45. encode_html_chars
  46. -----------------
  47. Used to enable special encoding of "unsafe" HTML characters into safer Unicode sequences. Default is false::
  48. >>> ujson.dumps("<script>John&Doe", encode_html_chars=True)
  49. '"\\u003cscript\\u003eJohn\\u0026Doe"'
  50. ensure_ascii
  51. -------------
  52. Limits output to ASCII and escapes all extended characters above 127. Default is true. If your end format supports UTF-8 setting this option to false is highly recommended to save space::
  53. >>> ujson.dumps(u"\xe5\xe4\xf6")
  54. '"\\u00e5\\u00e4\\u00f6"'
  55. >>> ujson.dumps(u"\xe5\xe4\xf6", ensure_ascii=False)
  56. '"\xc3\xa5\xc3\xa4\xc3\xb6"'
  57. double_precision
  58. ----------------
  59. Controls how many decimals to encode for double or decimal values. Default is 9::
  60. >>> ujson.dumps(math.pi)
  61. '3.1415926536'
  62. >>> ujson.dumps(math.pi, double_precision=1)
  63. '3.1'
  64. >>> ujson.dumps(math.pi, double_precision=0)
  65. '3'
  66. >>> ujson.dumps(math.pi, double_precision=4)
  67. '3.1416'
  68. escape_forward_slashes
  69. ----------------------
  70. Controls whether forward slashes (``/``) are escaped. Default is True::
  71. >>> ujson.dumps("http://esn.me")
  72. '"http:\/\/esn.me"'
  73. >>> ujson.dumps("http://esn.me", escape_forward_slashes=False)
  74. '"http://esn.me"'
  75. indent
  76. ----------------------
  77. Controls whether indention ("pretty output") is enabled. Default is 0 (disabled)::
  78. >>> ujson.dumps({"foo": "bar"})
  79. '{"foo":"bar"}'
  80. >>> ujson.dumps({"foo": "bar"}, indent=4)
  81. {
  82. "foo":"bar"
  83. }
  84. ~~~~~~~~~~~~~~~~
  85. Decoders options
  86. ~~~~~~~~~~~~~~~~
  87. precise_float
  88. -------------
  89. Set to enable usage of higher precision (strtod) function when decoding string to double values. Default is to use fast but less precise builtin functionality::
  90. >>> ujson.loads("4.56")
  91. 4.5600000000000005
  92. >>> ujson.loads("4.56", precise_float=True)
  93. 4.5599999999999996
  94. ~~~~~~~~~~~~~
  95. Test machine:
  96. ~~~~~~~~~~~~~
  97. Linux 3.13.0-66-generic x86_64 #108-Ubuntu SMP Wed Oct 7 15:20:27 UTC 2015
  98. ~~~~~~~~~
  99. Versions:
  100. ~~~~~~~~~
  101. - CPython 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2]
  102. - blist : 1.3.6
  103. - simplejson: 3.8.1
  104. - ujson : 1.34 (0c52200eb4e2d97e548a765d5f089858c41967b0)
  105. - yajl : 0.3.5
  106. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  107. | | ujson | yajl | simplejson | json |
  108. +===============================================================================+============+============+============+============+
  109. | Array with 256 doubles | | | | |
  110. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  111. | encode | 3508.19 | 5742.00 | 3232.38 | 3309.09 |
  112. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  113. | decode | 25103.37 | 11257.83 | 11696.26 | 11871.04 |
  114. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  115. | Array with 256 UTF-8 strings | | | | |
  116. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  117. | encode | 3189.71 | 2717.14 | 2006.38 | 2961.72 |
  118. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  119. | decode | 1354.94 | 630.54 | 356.35 | 344.05 |
  120. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  121. | Array with 256 strings | | | | |
  122. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  123. | encode | 18127.47 | 12537.39 | 12541.23 | 20001.00 |
  124. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  125. | decode | 23264.70 | 12788.85 | 25427.88 | 9352.36 |
  126. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  127. | Medium complex object | | | | |
  128. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  129. | encode | 10519.38 | 5021.29 | 3686.86 | 4643.47 |
  130. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  131. | decode | 9676.53 | 5326.79 | 8515.77 | 3017.30 |
  132. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  133. | Array with 256 True values | | | | |
  134. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  135. | encode | 105998.03 | 102067.28 | 44758.51 | 60424.80 |
  136. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  137. | decode | 163869.96 | 78341.57 | 110859.36 | 115013.90 |
  138. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  139. | Array with 256 dict{string, int} pairs | | | | |
  140. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  141. | encode | 13471.32 | 12109.09 | 3876.40 | 8833.92 |
  142. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  143. | decode | 16890.63 | 8946.07 | 12218.55 | 3350.72 |
  144. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  145. | Dict with 256 arrays with 256 dict{string, int} pairs | | | | |
  146. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  147. | encode | 50.25 | 46.45 | 13.82 | 29.28 |
  148. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  149. | decode | 33.27 | 22.10 | 27.91 | 10.43 |
  150. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  151. | Dict with 256 arrays with 256 dict{string, int} pairs, outputting sorted keys | | | | |
  152. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  153. | encode | 27.19 | | 7.75 | 2.39 |
  154. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  155. | Complex object | | | | |
  156. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  157. | encode | 577.98 | | 387.81 | 470.02 |
  158. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  159. | decode | 496.73 | 234.44 | 151.00 | 145.16 |
  160. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  161. ~~~~~~~~~
  162. Versions:
  163. ~~~~~~~~~
  164. - CPython 3.4.3 (default, Oct 14 2015, 20:28:29) [GCC 4.8.4]
  165. - blist : 1.3.6
  166. - simplejson: 3.8.1
  167. - ujson : 1.34 (0c52200eb4e2d97e548a765d5f089858c41967b0)
  168. - yajl : 0.3.5
  169. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  170. | | ujson | yajl | simplejson | json |
  171. +===============================================================================+============+============+============+============+
  172. | Array with 256 doubles | | | | |
  173. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  174. | encode | 3477.15 | 5732.24 | 3016.76 | 3071.99 |
  175. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  176. | decode | 23625.20 | 9731.45 | 9501.57 | 9901.92 |
  177. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  178. | Array with 256 UTF-8 strings | | | | |
  179. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  180. | encode | 1995.89 | 2151.61 | 1771.98 | 1817.20 |
  181. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  182. | decode | 1425.04 | 625.38 | 327.14 | 305.95 |
  183. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  184. | Array with 256 strings | | | | |
  185. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  186. | encode | 25461.75 | 12188.64 | 13054.76 | 14429.81 |
  187. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  188. | decode | 21981.31 | 17014.22 | 23869.48 | 22483.58 |
  189. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  190. | Medium complex object | | | | |
  191. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  192. | encode | 10821.46 | 4837.04 | 3114.04 | 4254.46 |
  193. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  194. | decode | 7887.77 | 5126.67 | 4934.60 | 6204.97 |
  195. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  196. | Array with 256 True values | | | | |
  197. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  198. | encode | 100452.86 | 94639.42 | 46657.63 | 60358.63 |
  199. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  200. | decode | 148312.69 | 75485.90 | 88434.91 | 116395.51 |
  201. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  202. | Array with 256 dict{string, int} pairs | | | | |
  203. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  204. | encode | 11698.13 | 8886.96 | 3043.69 | 6302.35 |
  205. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  206. | decode | 10686.40 | 7061.77 | 5646.80 | 7702.29 |
  207. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  208. | Dict with 256 arrays with 256 dict{string, int} pairs | | | | |
  209. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  210. | encode | 44.26 | 34.43 | 10.40 | 21.97 |
  211. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  212. | decode | 28.46 | 23.95 | 18.70 | 22.83 |
  213. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  214. | Dict with 256 arrays with 256 dict{string, int} pairs, outputting sorted keys | | | | |
  215. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  216. | encode | 33.60 | | 6.94 | 22.34 |
  217. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  218. | Complex object | | | | |
  219. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  220. | encode | 432.30 | | 351.47 | 379.34 |
  221. +-------------------------------------------------------------------------------+------------+------------+------------+------------+
  222. | decode | 434.40 | 221.97 | 149.57 | 147.79 |
  223. +-------------------------------------------------------------------------------+------------+------------+------------+------------+