fastsimdjson 0.10.0__cp315-cp315t-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ Version: 1.13.2
2
+ Arguments: ['C:\\Users\\runneradmin\\AppData\\Local\\Temp\\cibw-run-77ejzc4a\\cp315t-win_amd64\\build\\venv\\Scripts\\delvewheel', 'repair', '-w', 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\cibw-run-77ejzc4a\\cp315t-win_amd64\\repaired_wheel', '-v', 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\cibw-run-77ejzc4a\\cp315t-win_amd64\\built_wheel\\fastsimdjson-0.10.0-cp315-cp315t-win_amd64.whl']
@@ -0,0 +1,826 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastsimdjson
3
+ Version: 0.10.0
4
+ Summary: Fast JSON parsing for Python, built on simdjson
5
+ Author-email: Daniel Lemire <daniel@lemire.me>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/simdjson/fastpysimdjson
8
+ Project-URL: Repository, https://github.com/simdjson/fastpysimdjson
9
+ Project-URL: Issues, https://github.com/simdjson/fastpysimdjson/issues
10
+ Keywords: json,simdjson,parser,simd,performance
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: C++
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Python :: 3.15
21
+ Classifier: Programming Language :: Python :: Implementation :: CPython
22
+ Classifier: Topic :: Software Development :: Libraries
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ Provides-Extra: test
26
+ Requires-Dist: pytest; extra == "test"
27
+ Requires-Dist: msgpack; extra == "test"
28
+ Provides-Extra: bench
29
+ Requires-Dist: orjson; extra == "bench"
30
+ Requires-Dist: jiter; extra == "bench"
31
+ Requires-Dist: msgspec; extra == "bench"
32
+ Requires-Dist: pysimdjson; extra == "bench"
33
+ Requires-Dist: cysimdjson; extra == "bench"
34
+ Requires-Dist: pyarrow; extra == "bench"
35
+ Requires-Dist: polars; extra == "bench"
36
+ Requires-Dist: duckdb; extra == "bench"
37
+ Requires-Dist: msgpack; extra == "bench"
38
+ Requires-Dist: ormsgpack; extra == "bench"
39
+
40
+ # fastsimdjson
41
+
42
+ A Python binding for [simdjson](https://github.com/simdjson/simdjson) that
43
+ parses JSON into native Python objects (`dict`, `list`, `str`, `int`,
44
+ `float`, `bool`, `None`) and serializes them back. It is a drop-in
45
+ replacement for the `json` module's `loads`, `load`, `dumps` and `dump`, and
46
+ it can be over 3 times faster than the standard `json.loads` and
47
+ `json.dumps`. When you only need part of a document, its lazy `parse`
48
+ function is faster still. It also reads streams of documents (NDJSON, JSON
49
+ Lines), on many threads with free-threaded Python, and can extract only the
50
+ fields you need from each document. It writes JSON in two ways: `dumps` returns the same `str` as
51
+ `json.dumps`, and `dumpb` returns the same `bytes` as `orjson.dumps`, as fast
52
+ as orjson; `dumpb_many` writes NDJSON, on many threads with free-threaded
53
+ Python. `loads_arrow` and `dumpb_arrow` convert NDJSON to Apache Arrow
54
+ tables and back, for pyarrow, polars or DuckDB, on many threads with any
55
+ Python. `json_to_msgpack` and `msgpack_to_json` convert JSON to
56
+ [MessagePack](https://msgpack.org/) and back without building Python objects,
57
+ 3 to 4 times as fast as orjson with ormsgpack, on many threads with any
58
+ Python.
59
+
60
+ With pip:
61
+
62
+ ```sh
63
+ pip install fastsimdjson
64
+ ```
65
+
66
+ With uv:
67
+
68
+ ```sh
69
+ uv pip install fastsimdjson # in a uv project: uv add fastsimdjson
70
+ ```
71
+
72
+ Wheels are available for Linux, macOS and Windows, for Python 3.10 to 3.15,
73
+ including free-threaded Python 3.14 and 3.15.
74
+
75
+ ## Usage
76
+
77
+ ### `loads`: the whole document
78
+
79
+ ```python
80
+ import fastsimdjson
81
+ fastsimdjson.loads(b'{"a": [1, 2.5, "x", true, null]}')
82
+ # {'a': [1, 2.5, 'x', True, None]}
83
+ ```
84
+
85
+ `loads(data)` accepts `bytes`, `bytearray`, `memoryview` and `str`, and
86
+ returns the same value as `json.loads`, with the same types and key order.
87
+ Integers that do not fit in 64 bits become exact Python ints. `NaN`,
88
+ `Infinity` and `-Infinity` are accepted, in any capitalization.
89
+
90
+ Invalid input raises `fastsimdjson.JSONDecodeError`, a subclass of
91
+ `json.JSONDecodeError`. When simdjson rejects a document, the same input is
92
+ parsed with `json.loads`. If that succeeds, `loads` returns its value (this
93
+ is how a number that overflows a double becomes `inf`). If it raises
94
+ `JSONDecodeError`, the exception is re-raised with Python's message and byte
95
+ position. Any other exception from `json.loads` propagates.
96
+
97
+ ### `parse`: lazy views
98
+
99
+ When you need only part of a document, `parse` avoids building the rest.
100
+ It accepts the same inputs as `loads` and returns read-only views:
101
+ `fastsimdjson.Object` (a `Mapping`) and `fastsimdjson.Array` (a
102
+ `Sequence`). Values are converted when you access them; nested objects and
103
+ arrays are returned as views. A scalar root is returned as a plain value.
104
+
105
+ ```python
106
+ doc = fastsimdjson.parse(open("twitter.json", "rb").read())
107
+ ids = [(s["id"], s["user"]["screen_name"]) for s in doc["statuses"]]
108
+ doc.at_pointer("/statuses/0/user/name") # JSON Pointer (RFC 6901)
109
+ doc["search_metadata"].as_dict() # convert a subtree, like loads
110
+ ```
111
+
112
+ `Object` supports `obj[key]`, `get`, `in`, `len`, iteration over the keys,
113
+ `keys()`, `values()`, `items()` (iterators), `at_pointer` and `as_dict()`.
114
+ `Array` supports `arr[i]` (negative indexes and slices), `len`, iteration,
115
+ `at_pointer` and `as_list()`. Both work with `match` statements.
116
+
117
+ * A view keeps its document alive; the document owns its own buffers, so
118
+ it remains valid while other documents are parsed.
119
+ * A key lookup scans the object. With duplicate keys, lookups return the
120
+ first value, whereas `as_dict()` (like `json.loads`) keeps the last.
121
+ * Indexing an array walks it from the last index reached, so a loop over
122
+ `arr[i]` is linear; iteration is the fastest way to visit an array.
123
+ * Errors are handled as in `loads`. A document that simdjson rejects but
124
+ `json.loads` accepts (an overflowing number, an unpaired surrogate) is
125
+ returned as plain Python objects, as `loads` would return it.
126
+
127
+ ### `dumps` and `dump`: like `json.dumps`
128
+
129
+ ```python
130
+ fastsimdjson.dumps({"a": [1, 2.5, None]}) # '{"a": [1, 2.5, null]}'
131
+ fastsimdjson.dumps(obj, indent=2, sort_keys=True)
132
+ with open("out.json", "w", encoding="utf-8") as f:
133
+ fastsimdjson.dump(obj, f)
134
+ ```
135
+
136
+ `dumps(obj, **kw)` takes the arguments of `json.dumps` and returns the same
137
+ `str`, character for character, including the float format (`repr`), the
138
+ escapes and the default separators. `ensure_ascii`, `indent`, `separators`,
139
+ `sort_keys`, `allow_nan` and `default` are handled in C. Everything else is
140
+ passed to `json.dumps` itself, which produces the result or raises its usual
141
+ exception: a `cls` argument or other encoder options, `skipkeys`, a circular
142
+ reference, `NaN` with `allow_nan=False`, a key or a value that `json` cannot
143
+ serialize. `dump(obj, fp, **kw)` writes `dumps(obj, **kw)` to `fp`.
144
+
145
+ ### `dumpb`: like `orjson.dumps`
146
+
147
+ ```python
148
+ fastsimdjson.dumpb({"a": [1, 2.5, None]}) # b'{"a":[1,2.5,null]}'
149
+ fastsimdjson.dumpb(obj, option=fastsimdjson.OPT_INDENT_2 | fastsimdjson.OPT_SORT_KEYS)
150
+ fastsimdjson.dumpb({1, 2}, default=sorted) # b'[1,2]'
151
+ ```
152
+
153
+ `dumpb(obj, default=None, option=None)` has the arguments, the output and the
154
+ errors of `orjson.dumps` (orjson 3.12): `orjson.dumps(obj, ...)` can be
155
+ replaced by `fastsimdjson.dumpb(obj, ...)` for the types below. It returns
156
+ compact UTF-8 `bytes`, writes floats as orjson does (`1e-6`, `1e+16`, `NaN`
157
+ and infinities as `null`), and raises `TypeError` with orjson's messages:
158
+ integers beyond 64 bits, a dict key that is not a `str`, invalid UTF-8 (a lone
159
+ surrogate), nesting deeper than 254, a type it cannot serialize. `orjson.JSONEncodeError` is a subclass of `TypeError`, so
160
+ `except TypeError` catches the errors of both.
161
+
162
+ It serializes `str`, `int`, `float`, `bool`, `None`, `dict`, `list`, `tuple`,
163
+ enums, and subclasses of `str`, `int`, `dict` and `list`. Anything else goes
164
+ to `default`, as in orjson: its result is serialized in place of the object,
165
+ and an exception it raises becomes the `__cause__` of the `TypeError`. The
166
+ options are exported under orjson's names and values (`OPT_APPEND_NEWLINE`,
167
+ `OPT_INDENT_2`, `OPT_NON_STR_KEYS`, `OPT_PASSTHROUGH_SUBCLASS`,
168
+ `OPT_SORT_KEYS`, `OPT_STRICT_INTEGER`, ...). Unlike orjson, `dumpb` does not
169
+ serialize dataclasses, `datetime`, `date`, `time`, `UUID`, numpy arrays or
170
+ `orjson.Fragment` itself: they go to `default`, as if
171
+ `OPT_PASSTHROUGH_DATACLASS` and `OPT_PASSTHROUGH_DATETIME` were set, and the
172
+ options that concern only these types are accepted and have no effect.
173
+
174
+ ### `dumpb_many`: NDJSON, on several threads
175
+
176
+ ```python
177
+ data = fastsimdjson.dumpb_many(records) # b'{...}\n{...}\n'
178
+ data = fastsimdjson.dumpb_many(records, threads=16) # free-threaded Python
179
+ ```
180
+
181
+ `dumpb_many(records, default=None, option=None, *, threads=None)` returns
182
+ the records (a list, a tuple or any iterable) as NDJSON `bytes`: each record
183
+ as `dumpb` writes it, followed by a newline, so that the output reads back
184
+ with `loads_many(data, format="lines")`. `default` and `option` are those of
185
+ `dumpb`, except `OPT_INDENT_2`, which would spread a record over several
186
+ lines (`ValueError`); `OPT_APPEND_NEWLINE` changes nothing.
187
+
188
+ On free-threaded Python, `threads=N` writes chunks of records on N threads at
189
+ once (`threads=0` or `None`: one per processor), with the worker threads of
190
+ `map_many`. The output and the errors are those of one thread: when records
191
+ cannot be serialized, the error of the first of them is raised (`default` may
192
+ then have been called on later records, in other threads, and it must be
193
+ safe to call from several threads at once). With the GIL, the calling thread
194
+ does all the work. Like `dumpb`, `dumpb_many` does not crash when other
195
+ threads change the records meanwhile, but the output then reflects some of
196
+ the changes and not others.
197
+
198
+ ### Files
199
+
200
+ ```python
201
+ with open("data.json", "rb") as f:
202
+ doc = fastsimdjson.load(f) # like json.load: f.read(), then loads
203
+ doc = fastsimdjson.load_file("data.json")
204
+ view = fastsimdjson.parse_file("data.json") # lazy, like parse
205
+ ```
206
+
207
+ `load_file(path)` and `parse_file(path)` accept a `str`, `bytes` or
208
+ `os.PathLike` path and raise `OSError` (e.g. `FileNotFoundError`) when the
209
+ file cannot be read.
210
+
211
+ ### `loads_many` and `parse_many`: streams of documents
212
+
213
+ ```python
214
+ for record in fastsimdjson.loads_many(open("log.ndjson", "rb").read()):
215
+ ...
216
+ for view in fastsimdjson.parse_many(data): # lazy views, like parse
217
+ ...
218
+ ```
219
+
220
+ Both return an iterator over the documents of `data` (`bytes`, `bytearray`,
221
+ `memoryview` or `str`). The `format` keyword selects how documents are
222
+ separated:
223
+
224
+ | `format` | input |
225
+ |---|---|
226
+ | `"whitespace"` (default) | documents separated by white space, including NDJSON and JSON Lines |
227
+ | `"lines"` | one document per line (NDJSON, JSON Lines) |
228
+ | `"json_seq"` | RFC 7464 JSON text sequences (each document preceded by `\x1e`) |
229
+ | `"comma"` | documents separated by commas: `{...}, {...}` (simdjson also accepts white space between them) |
230
+ | `"array"` | the elements of one array: `[{...}, {...}]` |
231
+
232
+ simdjson parses the input in batches (`batch_size`, 1 MB by default); a
233
+ larger document is handled automatically. In every format, documents that
234
+ simdjson rejects are handled as in `loads`: a document that `json` accepts is
235
+ returned, otherwise `JSONDecodeError` reports `json`'s message and the
236
+ position in the whole input. A truncated last document is an error. The
237
+ views returned by `parse_many` remain valid after the iterator moves on.
238
+
239
+ ### Streams on several threads: `threads=N` and `map_many`
240
+
241
+ On free-threaded Python (3.14t and newer), a stream can be parsed by several
242
+ threads at once:
243
+
244
+ ```python
245
+ docs = fastsimdjson.loads_many(data, threads=16) # a list, in order
246
+ views = fastsimdjson.parse_many(data, threads=16) # a list of views
247
+ # fn runs in the threads too, on each document; its results, in order:
248
+ scores = fastsimdjson.map_many(score, data, threads=16)
249
+ ```
250
+
251
+ With `threads`, `loads_many` and `parse_many` return a list of all the
252
+ documents instead of an iterator. `map_many(fn, data, **kw)` returns
253
+ `[fn(doc) for doc in loads_many(data, **kw)]` (`parse_many` with
254
+ `lazy=True`), with `fn` called in the threads. `threads=0` (or `None`) uses
255
+ one thread per processor; small inputs use fewer threads (about one per
256
+ 512 KB). The input is cut into chunks at newlines (before each `\x1e` for
257
+ `json_seq`), so `threads` works with the formats `"whitespace"`, `"lines"`
258
+ and `"json_seq"`.
259
+
260
+ The results, and the exceptions, are those of one thread: when a chunk
261
+ contains an error or a document that only `json` accepts, the documents
262
+ before it are kept and the rest is parsed in the calling thread, as without
263
+ threads. An exception raised by `fn` is raised again, for the first document
264
+ where it happened; `fn` may then have been called on later documents, in
265
+ other threads, and it must be safe to call from several threads at once.
266
+
267
+ The worker threads are started by the first call that needs them and kept
268
+ for later calls (they wait, detached from the interpreter, between calls,
269
+ and stop at exit). `map_many` scales best: each document is built, used and
270
+ freed in the same thread, and only `fn`'s results come back. `loads_many` must return every
271
+ document, and the Python objects of all of them, to the calling thread.
272
+ With the GIL (the default build of Python), the calling thread does all the
273
+ work: `threads` has no effect on speed.
274
+
275
+ ### Only some fields: `fields=`
276
+
277
+ When you need a few values from each document, `fields` extracts them
278
+ without building the documents: only the values found become Python
279
+ objects.
280
+
281
+ ```python
282
+ events = fastsimdjson.loads_many(data, fields=["/type", "/payload/action"])
283
+ # (type, action) for each document
284
+
285
+ def count(t):
286
+ kind, action, language = t
287
+ ...
288
+ fastsimdjson.map_many(count, data, threads=64,
289
+ fields=["/type", "/payload/action",
290
+ "/payload/pull_request/base/repo/language"])
291
+ ```
292
+
293
+ `loads_many` and `map_many` accept `fields`: a JSON Pointer (RFC 6901), or a
294
+ list or tuple of them. Each document then becomes the value at the pointer,
295
+ or a tuple of the values at the pointers, in order. A value that is an
296
+ object or an array is built in full. A pointer that leads nowhere (a
297
+ missing key, an index past the end, or a step into a scalar) gives
298
+ `default`, `None` unless you pass another value; a JSON `null` gives `None`.
299
+ As with `at_pointer`, a key that appears twice in an object refers to its
300
+ first occurrence. `fields` cannot be combined with `lazy=True`.
301
+
302
+ On 7.6 GB of GitHub events, `map_many` with three fields ran at 2.8 GB/s on
303
+ one core of an Intel Xeon Gold 6548N, against 2.2 GB/s with lazy views
304
+ (`lazy=True`). With 64 threads, it ran at 78 GB/s (lazy views: 61 GB/s).
305
+
306
+ ### Arrow: `loads_arrow`, `load_arrow_file` and `dumpb_arrow`
307
+
308
+ ```python
309
+ import pyarrow as pa
310
+ table = pa.table(fastsimdjson.loads_arrow(data)) # inferring the schema
311
+ schema = pa.schema([("id", pa.int64()), ("name", pa.string())])
312
+ table = pa.table(fastsimdjson.load_arrow_file("log.ndjson", schema, threads=8))
313
+ frame = polars.DataFrame(fastsimdjson.loads_arrow(data, schema))
314
+ data = fastsimdjson.dumpb_arrow(table) # b'{"id":1,"name":"x"}\n...'
315
+ data = fastsimdjson.dumpb_arrow(frame, threads=8) # a polars.DataFrame
316
+ ```
317
+
318
+ `loads_arrow(data, schema=None, *, block_size=1048576,
319
+ error_on_unknown_fields=False, validate_skipped=True, threads=None)` reads
320
+ NDJSON (one object per record) into Arrow record batches. The input is
321
+ `bytes`, `bytearray`, `memoryview` or `str`, read in place.
322
+ `load_arrow_file(path, ...)` maps the file in memory and reads it the same way
323
+ (the file must not shrink meanwhile). Both return a `fastsimdjson.ArrowStream`,
324
+ which goes to any library that supports the [Arrow PyCapsule
325
+ interface](https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html),
326
+ without a copy: `pyarrow.table(s)`, `pyarrow.RecordBatchReader.from_stream(s)`,
327
+ `polars.DataFrame(s)`, `duckdb.from_arrow(s)`... Like a `RecordBatchReader`,
328
+ it hands over its batches once (`ValueError` afterwards); `pyarrow.schema(s)`
329
+ gives its schema at any time, and `s.num_rows` the number of records (`None`
330
+ once the batches are taken). fastsimdjson does not depend on pyarrow.
331
+
332
+ * The schema is a `pyarrow.Schema` (or any object with `__arrow_c_schema__`)
333
+ whose fields are booleans, 64-bit integers, unsigned 64-bit integers,
334
+ doubles, strings, structs and lists of these, or null. A field absent from a
335
+ record is null; a key absent from the schema is skipped, or an error with
336
+ `error_on_unknown_fields=True`. Skipped values are checked to be valid
337
+ JSON, unless `validate_skipped=False` (then only their structure is).
338
+ * Without a schema, it is inferred as pyarrow's JSON reader does: `null`,
339
+ `true`/`false`, integers that fit in 64 bits (`int64`), other numbers
340
+ (`double`), strings, objects (structs, with the union of their fields in
341
+ order of first appearance) and arrays (lists). A field of nulls takes the
342
+ type of its other values and integers become doubles next to other
343
+ numbers; other mixes of types raise `ValueError`. Strings stay strings (no
344
+ timestamps).
345
+ * A new batch starts every `block_size` bytes of input. With `threads=N`
346
+ (`threads=0` or `None`: one per processor), N threads read blocks of
347
+ `block_size` bytes, cut at line ends: a record must then fit on one line.
348
+ When that fails, the input is read again on one thread, so that the errors
349
+ (`ValueError`, with the record number and the field) are the same with any
350
+ number of threads.
351
+
352
+ `dumpb_arrow(data, *, write_nulls=True, threads=None)` writes Arrow data as
353
+ NDJSON `bytes`, one object per row: a `pyarrow.Table`, `RecordBatch`,
354
+ `RecordBatchReader` or `StructArray`, a `polars.DataFrame`, a DuckDB
355
+ relation, an `ArrowStream`, or any object with `__arrow_c_stream__` or
356
+ `__arrow_c_array__`. It writes integers of 8 to 64 bits, floats and doubles
357
+ (as `dumpb` writes them, NaN and infinities as `null`), booleans, strings
358
+ (including large strings and string views), structs and lists (including
359
+ large and fixed-size lists); other types raise `ValueError`. With
360
+ `write_nulls=False`, null fields are omitted. With `threads=N`, N threads
361
+ write ranges of rows into the result. The output reads back with
362
+ `loads_arrow`, and with `loads_many(data, format="lines")`.
363
+
364
+ These functions release the GIL and run their threads outside Python, with
365
+ or without free threading. They are built on
366
+ [simdjson_arrow](https://github.com/simdjson/simdjson_arrow), a C++ library
367
+ (vendored).
368
+
369
+ ### MessagePack: `json_to_msgpack` and `msgpack_to_json`
370
+
371
+ ```python
372
+ packed = fastsimdjson.json_to_msgpack(b'{"id": 1, "tags": ["a", "b"], "score": 2.5}')
373
+ # b'\x83\xa2id\x01\xa4tags\x92\xa1a\xa1b\xa5score\xcb@\x04\x00\x00\x00\x00\x00\x00'
374
+ msgpack.unpackb(packed) # {'id': 1, 'tags': ['a', 'b'], 'score': 2.5}
375
+ fastsimdjson.msgpack_to_json(packed) # b'{"id":1,"tags":["a","b"],"score":2.5}'
376
+ stream = fastsimdjson.json_to_msgpack(ndjson, ndjson=True, threads=8) # one value per document
377
+ lines = fastsimdjson.msgpack_to_json(stream, stream=True, threads=8) # NDJSON again
378
+ ```
379
+
380
+ `json_to_msgpack(data, *, ndjson=False, block_size=1048576, threads=None)`
381
+ converts JSON (`bytes`, `bytearray`, `memoryview` or `str`, read in place) to
382
+ MessagePack `bytes` in the most compact encoding: the same bytes as
383
+ `msgpack.packb(json.loads(data))` (but for duplicate keys, which
384
+ `json.loads` drops, and integers beyond 64 bits). Integers take the smallest integer encoding
385
+ (integers beyond 64 bits become doubles), other numbers are doubles, and
386
+ strings, arrays and objects take the smallest header for their size; keys keep
387
+ their order, duplicates too. With `ndjson=True`, the input holds documents
388
+ separated by whitespace (NDJSON, JSON Lines), and each becomes one MessagePack
389
+ value, one after the other.
390
+
391
+ `msgpack_to_json(data, *, stream=False, validate_utf8=True,
392
+ binary_as_base64=True, ext_as_null=False, block_size=1048576, threads=None)`
393
+ converts MessagePack (any bytes-like object) to compact JSON `bytes`. Floats
394
+ get the shortest representation that gives them back, as Python's `repr`
395
+ (`1.0`, not `1`; `1e-05`; NaN and infinities as `null`), binary values as base64 strings, map keys that are not strings as
396
+ strings (`"1"`, `"true"`, `"null"`); extension values (timestamps too) raise
397
+ `ValueError`, or become `null` with `ext_as_null=True`. Strings must be valid
398
+ UTF-8 (unless `validate_utf8=False`). With `stream=True`, the input holds a
399
+ sequence of values (what `json_to_msgpack(..., ndjson=True)` or several
400
+ `msgpack.packb` calls give), and each becomes one line of NDJSON.
401
+
402
+ * Invalid input raises `ValueError`: `"TAPE_ERROR: ... (document 12)"` for
403
+ JSON, `"truncated string (byte 1234)"` for MessagePack.
404
+ * With `threads=N` (`threads=0` or `None`: one per processor), NDJSON and
405
+ streams are converted on N threads, in blocks of about `block_size` bytes.
406
+ A JSON document must then fit on one line; when that fails, the input is
407
+ converted again on one thread, so that errors are the same with any number
408
+ of threads. Single documents use one thread.
409
+ * The functions release the GIL and run their threads outside Python, with or
410
+ without free threading, and write their result straight into the `bytes`
411
+ object (no copy). No Python object is made from the data.
412
+
413
+ They are built on
414
+ [simdjson_msgpack](https://github.com/simdjson/simdjson_msgpack), a C++ library
415
+ (vendored).
416
+
417
+ ### Threads and free-threaded Python
418
+
419
+ The module is marked free-threading compatible (`Py_MOD_GIL_NOT_USED` on
420
+ Python 3.13 and newer), so importing it on a free-threaded build does not
421
+ re-enable the GIL. It is tested with many threads parsing, serializing and
422
+ sharing views and stream iterators on free-threaded Python 3.14 and 3.15.
423
+
424
+ `bytes` and `str` inputs are read in place. A `bytearray` or `memoryview`
425
+ could be changed by another thread while we read it, so it is copied first:
426
+ always by `loads_many`, `parse_many` and `map_many` (the iterator outlives
427
+ the call) and by `loads_arrow`, `json_to_msgpack` and `msgpack_to_json`
428
+ (which release the GIL), and only on a free-threaded build by `loads` and
429
+ `parse`. Likewise, on a free-threaded build, `dumps` and `dumpb` hold
430
+ references to the items of the containers they serialize.
431
+
432
+ ### `release`
433
+
434
+ `release()` frees the simdjson parser and the string caches kept by the
435
+ calling thread. Views returned by `parse` remain valid.
436
+
437
+ ## Build and test
438
+
439
+ Python 3.10 or newer, and a C++17 compiler (clang, GCC or MSVC). The simdjson
440
+ 5.1.1 and simdutf 9.2.1 amalgamations, simdjson_arrow 0.1.1 (NDJSON to Arrow
441
+ and back: `simdjson_arrow.h` and `simdjson_arrow.cpp`) and simdjson_msgpack
442
+ 0.1.1 (JSON to MessagePack and back: `simdjson_msgpack.h` and
443
+ `simdjson_msgpack.cpp`), both under the Apache-2.0 license, are already in
444
+ `vendor/`. simdjson_arrow includes zmij 1.2 (shortest float formatting, MIT
445
+ license), which simdjson_msgpack, `dumps` and `dumpb` also use
446
+ (`vendor/zmij.h`).
447
+ The tests of the Arrow functions (`tests/test_arrow.py`) run when pyarrow is
448
+ installed (and polars, for one of them); otherwise they are skipped.
449
+
450
+ pip:
451
+
452
+ ```sh
453
+ python3 -m venv .venv
454
+ . .venv/bin/activate
455
+ python -m pip install -U pip setuptools
456
+ python -m pip install -e ".[test]"
457
+ pytest tests
458
+ ```
459
+
460
+ uv:
461
+
462
+ ```sh
463
+ uv venv
464
+ . .venv/bin/activate
465
+ uv pip install -e ".[test]"
466
+ pytest tests
467
+ ```
468
+
469
+ Either one builds the extension and makes `import fastsimdjson` work in the
470
+ virtualenv. uv uses the `setuptools` build requirement from `pyproject.toml`,
471
+ so it does not need a separate setuptools install for this path.
472
+
473
+ To compile the extension in the tree instead, install setuptools and pytest
474
+ into the same virtualenv, then:
475
+
476
+ ```sh
477
+ python -m pip install setuptools pytest
478
+ python setup.py build_ext --inplace
479
+ PYTHONPATH=src python -m pytest tests
480
+ ```
481
+
482
+ ```sh
483
+ uv pip install setuptools pytest
484
+ python setup.py build_ext --inplace
485
+ PYTHONPATH=src python -m pytest tests
486
+ ```
487
+
488
+ Recent setuptools copies the `.so` next to `src/fastsimdjson.cpp`, which is
489
+ why `PYTHONPATH=src` is required for the in-place build.
490
+
491
+ `tests/test_loads.py` compares `loads` with `json.loads` on types and key
492
+ order; `tests/test_lazy.py` checks the views returned by `parse` the same way,
493
+ `tests/test_dumps.py` compares `dumps` with `json.dumps` and `dumpb` with
494
+ orjson (output and exceptions; the orjson comparisons are skipped when orjson
495
+ is not installed, and recorded orjson results are checked either way), and
496
+ `tests/test_stream.py` and `tests/test_files.py` cover streams and files. It
497
+ covers scalars, integers past 64 bits, UTF-8 strings at every length from 0 to
498
+ 199, the key cache, random documents, rejected input, deep
499
+ nesting, padding at a page boundary, a saturated array count, reference
500
+ counts, and release of a parser that has grown past 64 MB. The corpus test
501
+ is skipped until simdjson-data is checked out beside the project:
502
+
503
+ ```sh
504
+ git clone --depth 1 https://github.com/simdjson/simdjson-data.git
505
+ pytest tests
506
+ # or: JSONDIR=/path/to/jsonexamples pytest tests
507
+ ```
508
+
509
+ The suite builds an ~80 MB document and a list of 16,777,221 integers, so
510
+ give it some RAM.
511
+
512
+ The benchmark scripts need simdjson-data and the `bench` extra (orjson,
513
+ jiter, msgspec, pysimdjson, cysimdjson). `bench.py` times `loads` against
514
+ `json.loads`, orjson and jiter, `bench_lazy.py` times `parse` against pysimdjson and
515
+ cysimdjson, `bench_dumps.py` times `dumps` against `json.dumps` and `dumpb`
516
+ against orjson and msgspec, and `bench_many.py` times `loads_many`.
517
+
518
+ pip:
519
+
520
+ ```sh
521
+ python -m pip install -e ".[bench]"
522
+ python bench.py
523
+ python bench_lazy.py
524
+ python bench_dumps.py
525
+ python bench_many.py
526
+ ```
527
+
528
+ uv:
529
+
530
+ ```sh
531
+ uv pip install -e ".[bench]"
532
+ python bench.py
533
+ python bench_lazy.py
534
+ python bench_dumps.py
535
+ python bench_many.py
536
+ ```
537
+
538
+ ## Benchmarks
539
+
540
+ Intel Xeon Gold 6548N (Emerald Rapids), one core, Python 3.14.6,
541
+ fastsimdjson 0.3.0 (simdjson 5.0.2), the 22 files of
542
+ [simdjson-data](https://github.com/simdjson/simdjson-data). The scripts are in
543
+ this repository and in
544
+ [the blog repository](https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/tree/master/2026/09/pysimdjson).
545
+
546
+ ### Whole documents
547
+
548
+ Each parser produces the whole document as Python objects. Speed is the
549
+ geometric mean over the 22 files (higher is better).
550
+
551
+ <picture>
552
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_loads_dark.png">
553
+ <img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_loads.png" width="80%" alt="Parsing JSON in Python: fastsimdjson loads 0.78 GB/s, orjson 0.60, msgspec 0.53, jiter 0.48, jiter without its string cache 0.44, pysimdjson 0.44, cysimdjson 0.43, ujson 0.37, python-rapidjson 0.24, simplejson 0.23, json 0.22">
554
+ </picture>
555
+
556
+ | parser | GB/s | vs `json.loads` |
557
+ |---|---:|---:|
558
+ | json (standard library) | 0.22 | 1.00× |
559
+ | simplejson 4.2.0 | 0.23 | 1.05× |
560
+ | python-rapidjson 1.25 | 0.24 | 1.10× |
561
+ | ujson 6.0.0 | 0.37 | 1.66× |
562
+ | cysimdjson 26.27 | 0.43 | 1.96× |
563
+ | pysimdjson 7.0.2 | 0.44 | 1.98× |
564
+ | jiter 0.17.0 (no string cache) | 0.44 | 2.00× |
565
+ | jiter 0.17.0 (string cache, the default) | 0.48 | 2.21× |
566
+ | msgspec 0.22.0 | 0.53 | 2.42× |
567
+ | orjson 3.12.0 | 0.60 | 2.74× |
568
+ | **fastsimdjson `loads`** | **0.78** | **3.53×** |
569
+
570
+ fastsimdjson is the fastest on 21 of the 22 files, and ties with orjson on
571
+ `numbers.json`, an array of floating-point numbers (within 2%). On numbers,
572
+ both spend most of their time creating Python floats, which costs the same in
573
+ both: simdjson parses the numbers of these files 15% to 30% faster than
574
+ orjson's parser (yyjson), but that is a small part of the total. Part of the
575
+ gain comes from pausing the garbage collector while the objects are built.
576
+ Timing each call on its own, fastsimdjson's lead over orjson is 1.33× with
577
+ the collector enabled and 1.22× with it disabled (geometric means); without
578
+ the collector, `canada.json`, `mesh.json` and `numbers.json` are ties. yyjson 4.0.6 is left out: it
579
+ returns wrong strings for non-ASCII text. jiter (the parser of pydantic)
580
+ caches strings by default; turning the cache off (`cache_mode=False`) makes it
581
+ slower here.
582
+
583
+ Parsing is no longer the bottleneck. simdjson alone parses these files at
584
+ 3.1 GB/s. It accounts for about a third of the time of `loads`; the rest goes
585
+ into creating Python objects. Freeing those objects later costs about a sixth
586
+ of the total. Even if parsing took no time at all, `loads` would be less than
587
+ 1.5 times faster.
588
+
589
+ ### Parts of documents with `parse`
590
+
591
+ If you only need a few values, `parse` creates only those. Extracting the id
592
+ and the screen name of the 100 statuses of `twitter.json`:
593
+
594
+ <picture>
595
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_parse_dark.png">
596
+ <img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_parse.png" width="80%" alt="Reading part of twitter.json: fastsimdjson parse 158 µs, pysimdjson 179, cysimdjson 229, msgspec 336, fastsimdjson loads 861, orjson 1009, jiter 1281, jiter without its string cache 1592, json 3922">
597
+ </picture>
598
+
599
+ | method | µs |
600
+ |---|---:|
601
+ | `json.loads` | 3922 |
602
+ | jiter (no string cache) | 1592 |
603
+ | jiter (string cache) | 1281 |
604
+ | orjson | 1009 |
605
+ | fastsimdjson `loads` | 861 |
606
+ | msgspec (typed `Struct`) | 336 |
607
+ | cysimdjson (lazy) | 229 |
608
+ | pysimdjson (lazy) | 179 |
609
+ | **fastsimdjson `parse`** | **158** |
610
+
611
+ Here `parse` is about 25 times faster than `json.loads` and 5.5 times faster
612
+ than `loads`. Most of its time is the simdjson parse itself.
613
+
614
+ ### `dumps` against `json.dumps`
615
+
616
+ <picture>
617
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_dumps_dark.png">
618
+ <img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_dumps.png" width="80%" alt="Writing JSON as str: fastsimdjson dumps 4.63 times faster than json.dumps">
619
+ </picture>
620
+
621
+ `dumps` returns exactly the `str` of `json.dumps` and is 4.6 times faster
622
+ (geometric mean over the 22 files; from 3.1 times on `citm_catalog.json` to
623
+ 12 times on `numbers.json`).
624
+
625
+ ### `dumpb` against orjson and msgspec
626
+
627
+ `dumpb`, `orjson.dumps` and `msgspec.json.encode` produce compact UTF-8
628
+ `bytes`; `dumpb` and orjson produce identical bytes on every file. With the
629
+ standard library, the same compact bytes come from
630
+ `json.dumps(obj, separators=(",", ":"), ensure_ascii=False).encode()`.
631
+ Microseconds:
632
+
633
+ <picture>
634
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_dumpb_dark.png">
635
+ <img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_dumpb.png" width="80%" alt="Writing JSON as bytes, speed relative to json.dumps(...).encode(): fastsimdjson dumpb 10.09x, orjson 9.69x, msgspec 6.03x">
636
+ </picture>
637
+
638
+ | file | `json.dumps(...).encode()` | fastsimdjson `dumpb` | orjson | msgspec |
639
+ |---|---:|---:|---:|---:|
640
+ | twitter | 1827 | 202 | 204 | 330 |
641
+ | citm_catalog | 2921 | 432 | 432 | 499 |
642
+ | github_events | 177 | 17 | 19 | 31 |
643
+ | gsoc-2018 | 15386 | 595 | 554 | 1462 |
644
+ | update-center | 2482 | 254 | 232 | 477 |
645
+ | canada | 38101 | 2432 | 2936 | 3640 |
646
+ | mesh | 8726 | 785 | 999 | 1370 |
647
+ | numbers | 2530 | 178 | 200 | 332 |
648
+
649
+ `dumpb` and orjson are on par: over the 22 files, `dumpb` is 4% faster
650
+ (geometric mean), from 10% slower on text-heavy or tiny files
651
+ (`gsoc-2018.json`, `update-center.json`, `repeat.json`) to 27% faster on files
652
+ full of numbers. Both are 1.7
653
+ times faster than msgspec and 10 times faster than `json`. The comparison was
654
+ run on a processor with AVX-512, which `dumpb` and orjson both use to escape
655
+ strings; other x64 processors use SSE2 and ARM processors NEON.
656
+
657
+ ### Writing NDJSON with `dumpb_many`
658
+
659
+ The 593,945 events of two hours of [GH Archive](https://www.gharchive.org/)
660
+ (1.87 GB of NDJSON), written back as NDJSON from Python objects. With the
661
+ GIL (Python 3.14.6), one thread: `orjson.dumps` on each record, joined, runs
662
+ at 0.94 GB/s, `dumpb` on each record at 1.07 GB/s, and `dumpb_many` at
663
+ 1.41 GB/s. On free-threaded Python 3.14.6t, GB/s:
664
+
665
+ | threads | 1 | 8 | 32 | 64 |
666
+ |---|---:|---:|---:|---:|
667
+ | `dumpb_many(records, threads=N)` | 1.3 | 6.0 | 11 | 12 |
668
+
669
+ ### NDJSON to Arrow and back
670
+
671
+ Two files: 4 million flat records (611 MB, 9 scalar fields), and 304,929 GH
672
+ Archive events (886 MB), read with a schema of 6 of their fields (two of them
673
+ structs; the rest of each event is skipped), or inferring the schema. Reading
674
+ gives a `pyarrow.Table` (`pyarrow.table(fastsimdjson.loads_arrow(data,
675
+ schema, threads=N))`); the time includes the import into pyarrow. Writing
676
+ starts from that table: fastsimdjson `dumpb_arrow`, polars `write_ndjson` and
677
+ DuckDB `COPY ... TO` (on tmpfs). Python 3.13, pyarrow 26.0, polars 2.1, DuckDB
678
+ 2.0, simdjson 5.1.0, Intel Xeon Gold 6548N (up to 32 threads on the 32 cores
679
+ of one socket; 64 threads on both sockets).
680
+
681
+ <picture>
682
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_read_1_dark.png">
683
+ <img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_read_1.png" width="80%" alt="Reading NDJSON into a pyarrow.Table on one thread: flat, fastsimdjson 0.70 GB/s, pyarrow 0.18, polars 0.27; GH Archive, fastsimdjson 1.95, pyarrow 0.45, polars 0.53; flat with an inferred schema, fastsimdjson 0.72, pyarrow 0.17, polars 0.08">
684
+ </picture>
685
+
686
+ <picture>
687
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_read_32_dark.png">
688
+ <img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_read_32.png" width="80%" alt="Reading NDJSON into a pyarrow.Table on 32 threads: flat, fastsimdjson 13.9 GB/s, pyarrow 5.1, polars 4.0; GH Archive, fastsimdjson 28.4, pyarrow 12.1, polars 3.8; flat with an inferred schema, fastsimdjson 13.3, pyarrow 4.8, polars 0.12">
689
+ </picture>
690
+
691
+ <picture>
692
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_write_1_dark.png">
693
+ <img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_write_1.png" width="80%" alt="Writing a pyarrow.Table as NDJSON on one thread: flat, fastsimdjson 0.96 GB/s, polars 0.46, DuckDB 0.30; GH Archive, fastsimdjson 1.07, polars 0.47, DuckDB 0.31">
694
+ </picture>
695
+
696
+ <picture>
697
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_write_32_dark.png">
698
+ <img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_arrow_write_32.png" width="80%" alt="Writing a pyarrow.Table as NDJSON on 32 threads: flat, fastsimdjson 7.8 GB/s, polars 1.3, DuckDB 2.8; GH Archive, fastsimdjson 4.7, polars 1.1, DuckDB 0.79">
699
+ </picture>
700
+
701
+ All the numbers, in GB/s:
702
+
703
+ | | threads | 1 | 8 | 32 | 64 |
704
+ |---|---|---:|---:|---:|---:|
705
+ | flat, read | fastsimdjson `loads_arrow` | **0.70** | **5.3** | **13.9** | **16.2** |
706
+ | | pyarrow `read_json` | 0.18 | 1.4 | 5.1 | 7.7 |
707
+ | | polars `read_ndjson` | 0.27 | 2.0 | 4.0 | 2.8 |
708
+ | flat, read, inferring the schema | fastsimdjson `loads_arrow` | **0.72** | **5.2** | **13.3** | **12.7** |
709
+ | | pyarrow `read_json` | 0.17 | 1.3 | 4.8 | 6.6 |
710
+ | | polars `read_ndjson` | 0.08 | 0.12 | 0.12 | 0.12 |
711
+ | GH Archive, read | fastsimdjson `loads_arrow` | **1.95** | **12.9** | **28.4** | **25.3** |
712
+ | | pyarrow `read_json` | 0.45 | 3.5 | 12.1 | 15.4 |
713
+ | | polars `read_ndjson` | 0.53 | 3.9 | 3.8 | 3.0 |
714
+ | flat, write | fastsimdjson `dumpb_arrow` | **0.96** | **3.9** | **7.8** | **12.6** |
715
+ | | polars | 0.46 | 1.1 | 1.3 | 1.6 |
716
+ | | DuckDB | 0.30 | 1.8 | 2.8 | 2.3 |
717
+ | GH Archive, write | fastsimdjson `dumpb_arrow` | **1.07** | **2.9** | **4.7** | **4.5** |
718
+ | | polars | 0.47 | 0.78 | 1.1 | 0.91 |
719
+ | | DuckDB | 0.31 | 0.95 | 0.79 | 0.66 |
720
+
721
+ `load_arrow_file` on the same files, from the page cache, reads at 0.67 and
722
+ 1.6 GB/s on one thread, 9.8 and 14.8 GB/s on 32 threads. The benchmark is
723
+ `THREADS=N python bench_arrow.py flat.ndjson:flat gharchive.ndjson:gh
724
+ flat.ndjson:infer`; `path:infer` times any NDJSON file without a schema. The
725
+ flat file comes from
726
+ [simdjson_arrow's `benchmarks/gendata.py`](https://github.com/simdjson/simdjson_arrow/blob/main/benchmarks/gendata.py)
727
+ and the events from GH Archive
728
+ (`curl -sSfL https://data.gharchive.org/2024-03-13-12.json.gz | gunzip > gharchive.ndjson`).
729
+ The charts come from `python doc/make_charts.py arrow`.
730
+
731
+ ### JSON to MessagePack and back
732
+
733
+ From JSON bytes to MessagePack bytes, and back, against the usual ways in
734
+ Python, which decode into Python objects, then encode them:
735
+ `ormsgpack.packb(orjson.loads(s))`, `msgspec.msgpack.encode(msgspec.json.decode(s))`
736
+ and so on. The 22 files of simdjson-data, geometric means of the speeds, in
737
+ GB/s of JSON (read when writing MessagePack, written when writing JSON).
738
+ Python 3.14, msgpack 1.2, orjson 3.13, ormsgpack 1.13, msgspec 0.22, Intel
739
+ Xeon Gold 6338 (Ice Lake), one core.
740
+
741
+ <picture>
742
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_encode_dark.png">
743
+ <img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_encode.png" width="80%" alt="JSON to MessagePack in Python, geometric mean over the 22 files of simdjson-data: fastsimdjson json_to_msgpack 1.37 GB/s, orjson with ormsgpack 0.35, msgspec 0.34, fastsimdjson loads with msgpack 0.28, orjson with msgpack 0.25, json with msgpack 0.13">
744
+ </picture>
745
+
746
+ <picture>
747
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_decode_dark.png">
748
+ <img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_decode.png" width="80%" alt="MessagePack to JSON in Python, geometric mean over the 22 files of simdjson-data: fastsimdjson msgpack_to_json 0.94 GB/s, ormsgpack with orjson 0.27, msgspec 0.25, msgpack with orjson 0.20, msgpack with fastsimdjson dumpb 0.20, msgpack with json 0.07">
749
+ </picture>
750
+
751
+ Streams: the 304,929 events of an hour of GH Archive (886 MB of NDJSON), with
752
+ `json_to_msgpack(data, ndjson=True, threads=N)` and
753
+ `msgpack_to_json(packed, stream=True, threads=N)`, against orjson with
754
+ ormsgpack (each document) and `msgpack.Unpacker` with orjson (each value), on
755
+ one thread (one thread per core of one socket up to 32 threads, then both
756
+ sockets):
757
+
758
+ <picture>
759
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_ndjson_dark.png">
760
+ <img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_msgpack_ndjson.png" width="80%" alt="GH Archive NDJSON to MessagePack: fastsimdjson 15.0 GB/s on 64 threads, 10.8 on 32, 6.8 on 8, 1.18 on one thread, orjson with ormsgpack 0.29 on one thread; MessagePack to NDJSON: fastsimdjson 5.0 GB/s on 8 threads, 1.05 on one thread, msgpack with orjson 0.20">
761
+ </picture>
762
+
763
+ | threads | 1 | 2 | 4 | 8 | 16 | 32 | 64 |
764
+ |---|---:|---:|---:|---:|---:|---:|---:|
765
+ | NDJSON to MessagePack | 1.18 | 1.88 | 4.2 | 6.8 | 8.6 | 10.8 | 15.0 |
766
+ | MessagePack to NDJSON | 1.05 | 1.67 | 3.3 | 5.0 | 3.4 | 4.2 | 3.5 |
767
+
768
+ MessagePack to NDJSON stops scaling at about eight threads: one thread must
769
+ find where the values end (MessagePack has no line ends) before the others
770
+ can convert them. The benchmark is `python bench_msgpack.py` (the files of
771
+ `JSONDIR`, by default `simdjson-data/jsonexamples`) and
772
+ `python bench_msgpack.py --ndjson gharchive.ndjson 1 8 32`; the charts come
773
+ from `python doc/make_charts.py msgpack`.
774
+
775
+ ### Streams with `loads_many`
776
+
777
+ 20 MB of NDJSON (5268 objects and arrays, one per line), made from the same
778
+ files; best of three runs:
779
+
780
+ <picture>
781
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_ndjson_dark.png">
782
+ <img src="https://raw.githubusercontent.com/simdjson/fastpysimdjson/main/doc/perf_ndjson.png" width="80%" alt="Reading NDJSON: fastsimdjson parse_many 0.94 GB/s, loads_many 0.38, msgspec decode_lines 0.37, fastsimdjson loads per line 0.33, msgspec decode per line 0.27, orjson per line 0.26, jiter per line 0.22, jiter without its string cache per line 0.20, json per line 0.12">
783
+ </picture>
784
+
785
+ | method | ms | GB/s |
786
+ |---|---:|---:|
787
+ | `json.loads` on each line | 169 | 0.12 |
788
+ | jiter on each line (no string cache) | 98 | 0.20 |
789
+ | jiter on each line (string cache) | 90 | 0.22 |
790
+ | orjson on each line | 77 | 0.26 |
791
+ | msgspec `decode` on each line | 74 | 0.27 |
792
+ | fastsimdjson `loads` on each line | 60 | 0.33 |
793
+ | msgspec `decode_lines` | 53 | 0.37 |
794
+ | fastsimdjson `loads_many` | 52 | 0.38 |
795
+ | fastsimdjson `parse_many` (views only) | 21 | 0.94 |
796
+
797
+ msgspec's `decode_lines` and `loads_many` are on par (`loads_many` is about 2%
798
+ faster). `parse_many` only creates the views; reading values from them adds to
799
+ its time.
800
+
801
+ ### Streams on several threads
802
+
803
+ 300 MB of NDJSON (146,624 records: tweets, GitHub events, citm performances,
804
+ gsoc and update-center entries), free-threaded Python 3.14.6, collector
805
+ disabled (see below), Intel Xeon Gold 6548N (64 cores); GB/s:
806
+
807
+ | threads | 1 | 2 | 4 | 8 | 16 | 32 | 64 |
808
+ |---|---:|---:|---:|---:|---:|---:|---:|
809
+ | `map_many(len, data, threads=N)` | 1.03 | 1.78 | 3.66 | 6.82 | 13.0 | 23.7 | **28.8** |
810
+ | `parse_many(data, threads=N)` | 2.00 | 2.84 | 5.28 | 9.26 | 16.1 | 22.7 | 25.8 |
811
+ | `loads_many(data, threads=N)` | 0.90 | 1.44 | 2.79 | 4.99 | 8.98 | 13.3 | 15.4 |
812
+
813
+ `map_many` is 28 times faster on 64 threads than on one (up to 38 GB/s when
814
+ nothing else runs in the process). `loads_many` builds every document for
815
+ the calling thread and is 17 times faster. With the collector enabled,
816
+ Python collects after the call returns: it examines the millions of objects
817
+ just created, which takes about 0.1 s here, with or without threads.
818
+
819
+ ## Limitations
820
+
821
+ * The simdjson parser and the key and string caches are thread-local.
822
+ `release()` frees the parser and the cached strings retained by the calling
823
+ thread, and they are freed when a Python thread exits. A parser that grows
824
+ past 64 MB is freed on its own at the end of that call; its caches stay.
825
+ * Subinterpreters are not supported: the module keeps per-process state (its
826
+ types, and per-thread parsers and string caches).
@@ -0,0 +1,7 @@
1
+ fastsimdjson.cp315t-win_amd64.pyd,sha256=rFoAT1owlg8Qu1PfwtLxlP4BMHNVYH9o5Aj9_gYdMxo,1462784
2
+ fastsimdjson-0.10.0.data/platlib/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll,sha256=pMIim9wqKmMKzcCVtNhgCOXD47x3cxdDVPPaT1vrnN4,575056
3
+ fastsimdjson-0.10.0.dist-info/DELVEWHEEL,sha256=h2ipt01r6SsDS_9gmfDmzr41caXWIezkPUFOzqSciVA,416
4
+ fastsimdjson-0.10.0.dist-info/METADATA,sha256=pOmTXIxtQQCNtCMHq26U8Z-YPXbVcVLf3jDV_RM7CTQ,42856
5
+ fastsimdjson-0.10.0.dist-info/RECORD,,
6
+ fastsimdjson-0.10.0.dist-info/top_level.txt,sha256=Jlm9cb3c2dfwwmf2rdX3Y7He8ty1I1eV52HBR4ZC2Mw,13
7
+ fastsimdjson-0.10.0.dist-info/WHEEL,sha256=mvJjE69WCrzBjiLWdJ-JUdj6FpMtRsa9bkCiTJU-QZU,102
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: false
4
+ Tag: cp315-cp315t-win_amd64
5
+
@@ -0,0 +1 @@
1
+ fastsimdjson
Binary file