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.
 
 
 
 

201 line
9.1 KiB

  1. Metadata-Version: 2.1
  2. Name: ujson
  3. Version: 5.10.0
  4. Summary: Ultra fast JSON encoder and decoder for Python
  5. Home-page: https://github.com/ultrajson/ultrajson
  6. Download-URL: https://github.com/ultrajson/ultrajson
  7. Author: Jonas Tarnstrom
  8. Project-URL: Source, https://github.com/ultrajson/ultrajson
  9. Platform: any
  10. Classifier: Development Status :: 5 - Production/Stable
  11. Classifier: Intended Audience :: Developers
  12. Classifier: License :: OSI Approved :: BSD License
  13. Classifier: Programming Language :: C
  14. Classifier: Programming Language :: Python :: 3
  15. Classifier: Programming Language :: Python :: 3 :: Only
  16. Classifier: Programming Language :: Python :: 3.8
  17. Classifier: Programming Language :: Python :: 3.9
  18. Classifier: Programming Language :: Python :: 3.10
  19. Classifier: Programming Language :: Python :: 3.11
  20. Classifier: Programming Language :: Python :: 3.12
  21. Classifier: Programming Language :: Python :: 3.13
  22. Requires-Python: >=3.8
  23. Description-Content-Type: text/markdown
  24. License-File: LICENSE.txt
  25. # UltraJSON
  26. [![PyPI version](https://img.shields.io/pypi/v/ujson.svg?logo=pypi&logoColor=FFE873)](https://pypi.org/project/ujson)
  27. [![Supported Python versions](https://img.shields.io/pypi/pyversions/ujson.svg?logo=python&logoColor=FFE873)](https://pypi.org/project/ujson)
  28. [![PyPI downloads](https://img.shields.io/pypi/dm/ujson.svg)](https://pypistats.org/packages/ujson)
  29. [![GitHub Actions status](https://github.com/ultrajson/ultrajson/workflows/Test/badge.svg)](https://github.com/ultrajson/ultrajson/actions)
  30. [![codecov](https://codecov.io/gh/ultrajson/ultrajson/branch/main/graph/badge.svg)](https://codecov.io/gh/ultrajson/ultrajson)
  31. [![DOI](https://zenodo.org/badge/1418941.svg)](https://zenodo.org/badge/latestdoi/1418941)
  32. [![Code style: Black](https://img.shields.io/badge/code%20style-Black-000000.svg)](https://github.com/psf/black)
  33. UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for
  34. Python 3.8+.
  35. Install with pip:
  36. ```sh
  37. python -m pip install ujson
  38. ```
  39. ## Project status
  40. > [!WARNING]
  41. > UltraJSON's architecture is fundamentally ill-suited to making changes without
  42. > risk of introducing new security vulnerabilities. As a result, this library
  43. > has been put into a *maintenance-only* mode. Support for new Python versions
  44. > will be added and critical bugs and security issues will still be
  45. > fixed but all other changes will be rejected. Users are encouraged to migrate
  46. > to [orjson](https://pypi.org/project/orjson/) which is both much faster and
  47. > less likely to introduce a surprise buffer overflow vulnerability in the
  48. > future.
  49. ## Usage
  50. May be used as a drop in replacement for most other JSON parsers for Python:
  51. ```pycon
  52. >>> import ujson
  53. >>> ujson.dumps([{"key": "value"}, 81, True])
  54. '[{"key":"value"},81,true]'
  55. >>> ujson.loads("""[{"key": "value"}, 81, true]""")
  56. [{'key': 'value'}, 81, True]
  57. ```
  58. ### Encoder options
  59. #### encode_html_chars
  60. Used to enable special encoding of "unsafe" HTML characters into safer Unicode
  61. sequences. Default is `False`:
  62. ```pycon
  63. >>> ujson.dumps("<script>John&Doe", encode_html_chars=True)
  64. '"\\u003cscript\\u003eJohn\\u0026Doe"'
  65. ```
  66. #### ensure_ascii
  67. Limits output to ASCII and escapes all extended characters above 127. Default is `True`.
  68. If your end format supports UTF-8, setting this option to false is highly recommended to
  69. save space:
  70. ```pycon
  71. >>> ujson.dumps("åäö")
  72. '"\\u00e5\\u00e4\\u00f6"'
  73. >>> ujson.dumps("åäö", ensure_ascii=False)
  74. '"åäö"'
  75. ```
  76. #### escape_forward_slashes
  77. Controls whether forward slashes (`/`) are escaped. Default is `True`:
  78. ```pycon
  79. >>> ujson.dumps("https://example.com")
  80. '"https:\\/\\/example.com"'
  81. >>> ujson.dumps("https://example.com", escape_forward_slashes=False)
  82. '"https://example.com"'
  83. ```
  84. #### indent
  85. Controls whether indentation ("pretty output") is enabled. Default is `0` (disabled):
  86. ```pycon
  87. >>> ujson.dumps({"foo": "bar"})
  88. '{"foo":"bar"}'
  89. >>> print(ujson.dumps({"foo": "bar"}, indent=4))
  90. {
  91. "foo":"bar"
  92. }
  93. ```
  94. ## Benchmarks
  95. *UltraJSON* calls/sec compared to other popular JSON parsers with performance gain
  96. specified below each.
  97. ### Test machine
  98. Linux 5.15.0-1037-azure x86_64 #44-Ubuntu SMP Thu Apr 20 13:19:31 UTC 2023
  99. ### Versions
  100. - CPython 3.11.3 (main, Apr 6 2023, 07:55:46) [GCC 11.3.0]
  101. - ujson : 5.7.1.dev26
  102. - orjson : 3.9.0
  103. - simplejson : 3.19.1
  104. - json : 2.0.9
  105. | | ujson | orjson | simplejson | json |
  106. |-------------------------------------------------------------------------------|-----------:|-----------:|-----------:|-----------:|
  107. | Array with 256 doubles | | | | |
  108. | encode | 18,282 | 79,569 | 5,681 | 5,935 |
  109. | decode | 28,765 | 93,283 | 13,844 | 13,367 |
  110. | Array with 256 UTF-8 strings | | | | |
  111. | encode | 3,457 | 26,437 | 3,630 | 3,653 |
  112. | decode | 3,576 | 4,236 | 522 | 1,978 |
  113. | Array with 256 strings | | | | |
  114. | encode | 44,769 | 125,920 | 21,401 | 23,565 |
  115. | decode | 28,518 | 75,043 | 41,496 | 42,221 |
  116. | Medium complex object | | | | |
  117. | encode | 11,672 | 47,659 | 3,913 | 5,729 |
  118. | decode | 12,522 | 23,599 | 8,007 | 9,720 |
  119. | Array with 256 True values | | | | |
  120. | encode | 110,444 | 425,919 | 81,428 | 84,347 |
  121. | decode | 203,430 | 318,193 | 146,867 | 156,249 |
  122. | Array with 256 dict{string, int} pairs | | | | |
  123. | encode | 14,170 | 72,514 | 3,050 | 7,079 |
  124. | decode | 19,116 | 27,542 | 9,374 | 13,713 |
  125. | Dict with 256 arrays with 256 dict{string, int} pairs | | | | |
  126. | encode | 55 | 282 | 11 | 26 |
  127. | decode | 48 | 53 | 27 | 34 |
  128. | Dict with 256 arrays with 256 dict{string, int} pairs, outputting sorted keys | | | | |
  129. | encode | 42 | | 8 | 27 |
  130. | Complex object | | | | |
  131. | encode | 462 | | 397 | 444 |
  132. | decode | 480 | 618 | 177 | 310 |
  133. Above metrics are in call/sec, larger is better.
  134. ## Build options
  135. For those with particular needs, such as Linux distribution packagers, several
  136. build options are provided in the form of environment variables.
  137. ### Debugging symbols
  138. #### UJSON_BUILD_NO_STRIP
  139. By default, debugging symbols are stripped on Linux platforms. Setting this
  140. environment variable with a value of `1` or `True` disables this behavior.
  141. ### Using an external or system copy of the double-conversion library
  142. These two environment variables are typically used together, something like:
  143. ```sh
  144. export UJSON_BUILD_DC_INCLUDES='/usr/include/double-conversion'
  145. export UJSON_BUILD_DC_LIBS='-ldouble-conversion'
  146. ```
  147. Users planning to link against an external shared library should be aware of
  148. the ABI-compatibility requirements this introduces when upgrading system
  149. libraries or copying compiled wheels to other machines.
  150. #### UJSON_BUILD_DC_INCLUDES
  151. One or more directories, delimited by `os.pathsep` (same as the `PATH`
  152. environment variable), in which to look for `double-conversion` header files;
  153. the default is to use the bundled copy.
  154. #### UJSON_BUILD_DC_LIBS
  155. Compiler flags needed to link the `double-conversion` library; the default
  156. is to use the bundled copy.