json2xml 5.4.0__tar.gz → 6.0.0__tar.gz
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.
- {json2xml-5.4.0 → json2xml-6.0.0}/CONTRIBUTING.rst +66 -10
- {json2xml-5.4.0 → json2xml-6.0.0}/HISTORY.rst +42 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/PKG-INFO +167 -1
- {json2xml-5.4.0 → json2xml-6.0.0}/README.rst +166 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/json2xml/__init__.py +1 -1
- {json2xml-5.4.0 → json2xml-6.0.0}/json2xml/cli.py +1 -1
- {json2xml-5.4.0 → json2xml-6.0.0}/json2xml/dicttoxml.py +1 -1
- json2xml-6.0.0/json2xml/dicttoxml_fast.py +165 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/json2xml.egg-info/PKG-INFO +167 -1
- {json2xml-5.4.0 → json2xml-6.0.0}/json2xml.egg-info/SOURCES.txt +2 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/pyproject.toml +6 -1
- json2xml-6.0.0/tests/test_rust_dicttoxml.py +606 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/AUTHORS.rst +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/LICENSE +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/MANIFEST.in +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/docs/Makefile +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/docs/authors.rst +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/docs/benchmarks.rst +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/docs/conf.py +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/docs/contributing.rst +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/docs/history.rst +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/docs/index.rst +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/docs/installation.rst +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/docs/json2xml.rst +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/docs/make.bat +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/docs/modules.rst +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/docs/readme.rst +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/docs/usage.rst +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/json2xml/json2xml.py +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/json2xml/utils.py +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/json2xml.egg-info/dependency_links.txt +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/json2xml.egg-info/entry_points.txt +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/json2xml.egg-info/requires.txt +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/json2xml.egg-info/top_level.txt +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/requirements.in +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/setup.cfg +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/setup.py +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/tests/__init__.py +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/tests/conftest.py +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/tests/test_cli.py +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/tests/test_dict2xml.py +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/tests/test_json2xml.py +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/tests/test_missing_coverage.py +0 -0
- {json2xml-5.4.0 → json2xml-6.0.0}/tests/test_utils.py +0 -0
|
@@ -64,11 +64,13 @@ Ready to contribute? Here's how to set up `json2xml` for local development.
|
|
|
64
64
|
|
|
65
65
|
$ git clone git@github.com:your_name_here/json2xml.git
|
|
66
66
|
|
|
67
|
-
3. Install your local copy
|
|
67
|
+
3. Install your local copy using uv (recommended) or pip::
|
|
68
68
|
|
|
69
|
-
$ mkvirtualenv json2xml
|
|
70
69
|
$ cd json2xml/
|
|
71
|
-
$
|
|
70
|
+
$ uv venv
|
|
71
|
+
$ source .venv/bin/activate
|
|
72
|
+
$ uv pip install -r requirements-dev.txt
|
|
73
|
+
$ uv pip install -e .
|
|
72
74
|
|
|
73
75
|
4. Create a branch for local development::
|
|
74
76
|
|
|
@@ -76,14 +78,15 @@ Ready to contribute? Here's how to set up `json2xml` for local development.
|
|
|
76
78
|
|
|
77
79
|
Now you can make your changes locally.
|
|
78
80
|
|
|
79
|
-
5. When you're done making changes, check that your changes pass
|
|
80
|
-
tests
|
|
81
|
+
5. When you're done making changes, check that your changes pass linting and the
|
|
82
|
+
tests::
|
|
81
83
|
|
|
82
|
-
$
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
$ make check-all # Runs lint, typecheck, and tests
|
|
85
|
+
|
|
86
|
+
# Or individually:
|
|
87
|
+
$ ruff check json2xml tests
|
|
88
|
+
$ mypy json2xml tests
|
|
89
|
+
$ pytest tests/
|
|
87
90
|
|
|
88
91
|
6. Commit your changes and push your branch to GitHub::
|
|
89
92
|
|
|
@@ -93,6 +96,59 @@ Ready to contribute? Here's how to set up `json2xml` for local development.
|
|
|
93
96
|
|
|
94
97
|
7. Submit a pull request through the GitHub website.
|
|
95
98
|
|
|
99
|
+
Rust Extension Development
|
|
100
|
+
--------------------------
|
|
101
|
+
|
|
102
|
+
The ``json2xml-rs`` Rust extension provides ~29x faster performance. If you want to contribute to the Rust extension:
|
|
103
|
+
|
|
104
|
+
**Prerequisites**
|
|
105
|
+
|
|
106
|
+
Install Rust and maturin::
|
|
107
|
+
|
|
108
|
+
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
|
109
|
+
$ uv pip install maturin
|
|
110
|
+
|
|
111
|
+
**Building the Extension**
|
|
112
|
+
|
|
113
|
+
::
|
|
114
|
+
|
|
115
|
+
# Build and install in development mode
|
|
116
|
+
$ cd rust
|
|
117
|
+
$ uv pip install -e .
|
|
118
|
+
|
|
119
|
+
# Or using maturin directly
|
|
120
|
+
$ maturin develop --release
|
|
121
|
+
|
|
122
|
+
**Running Rust Tests**
|
|
123
|
+
|
|
124
|
+
::
|
|
125
|
+
|
|
126
|
+
$ pytest tests/test_rust_dicttoxml.py -v
|
|
127
|
+
|
|
128
|
+
**Running Benchmarks**
|
|
129
|
+
|
|
130
|
+
::
|
|
131
|
+
|
|
132
|
+
$ python benchmark_rust.py
|
|
133
|
+
|
|
134
|
+
**Rust Code Structure**
|
|
135
|
+
|
|
136
|
+
The Rust code is located in ``rust/src/lib.rs`` and includes:
|
|
137
|
+
|
|
138
|
+
- ``escape_xml()`` - XML character escaping
|
|
139
|
+
- ``wrap_cdata()`` - CDATA section wrapping
|
|
140
|
+
- ``convert_dict()`` - Dictionary to XML conversion
|
|
141
|
+
- ``convert_list()`` - List to XML conversion
|
|
142
|
+
- ``dicttoxml()`` - Main entry point exposed to Python
|
|
143
|
+
|
|
144
|
+
When making changes to the Rust code:
|
|
145
|
+
|
|
146
|
+
1. Ensure all existing tests pass
|
|
147
|
+
2. Add tests for new functionality
|
|
148
|
+
3. Run ``cargo fmt`` to format Rust code
|
|
149
|
+
4. Run ``cargo clippy`` for linting
|
|
150
|
+
5. Verify Python compatibility tests pass
|
|
151
|
+
|
|
96
152
|
Pull Request Guidelines
|
|
97
153
|
-----------------------
|
|
98
154
|
|
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
History
|
|
2
2
|
=======
|
|
3
3
|
|
|
4
|
+
6.0.0 / 2026-01-16
|
|
5
|
+
==================
|
|
6
|
+
|
|
7
|
+
**Major Release: Native Rust Extension for 29x Faster Performance**
|
|
8
|
+
|
|
9
|
+
This release introduces an optional native Rust extension built with PyO3 that provides
|
|
10
|
+
approximately 29x faster JSON to XML conversion compared to pure Python.
|
|
11
|
+
|
|
12
|
+
New Features:
|
|
13
|
+
|
|
14
|
+
* feat: add optional Rust extension (json2xml-rs) for ~29x faster performance
|
|
15
|
+
* feat: add dicttoxml_fast module with automatic backend selection
|
|
16
|
+
* feat: seamless fallback to pure Python when Rust extension is not installed
|
|
17
|
+
* feat: pre-built wheels for Linux (x86_64, aarch64), macOS (Intel, Apple Silicon), Windows
|
|
18
|
+
|
|
19
|
+
Performance Improvements:
|
|
20
|
+
|
|
21
|
+
* Small JSON (47 bytes): 33x faster
|
|
22
|
+
* Medium JSON (3.2KB): 28x faster
|
|
23
|
+
* Large JSON (32KB): 30x faster
|
|
24
|
+
* Very Large JSON (323KB): 29x faster
|
|
25
|
+
|
|
26
|
+
New Files:
|
|
27
|
+
|
|
28
|
+
* rust/ - PyO3 Rust extension source code
|
|
29
|
+
* json2xml/dicttoxml_fast.py - Auto-selecting wrapper module
|
|
30
|
+
* tests/test_rust_dicttoxml.py - 65 comprehensive tests for Rust extension
|
|
31
|
+
* benchmark_rust.py - Performance comparison script
|
|
32
|
+
* .github/workflows/build-rust-wheels.yml - CI for building wheels
|
|
33
|
+
* .github/workflows/rust-ci.yml - CI for Rust code quality
|
|
34
|
+
|
|
35
|
+
Installation:
|
|
36
|
+
|
|
37
|
+
* Pure Python: pip install json2xml
|
|
38
|
+
* With Rust acceleration: pip install json2xml-rs (then import from dicttoxml_fast)
|
|
39
|
+
|
|
40
|
+
Documentation:
|
|
41
|
+
|
|
42
|
+
* Updated README with Rust extension usage and benchmarks
|
|
43
|
+
* Updated CONTRIBUTING with Rust development guide
|
|
44
|
+
|
|
45
|
+
|
|
4
46
|
5.4.0 / 2026-01-15
|
|
5
47
|
==================
|
|
6
48
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: json2xml
|
|
3
|
-
Version:
|
|
3
|
+
Version: 6.0.0
|
|
4
4
|
Summary: Simple Python Library to convert JSON to XML
|
|
5
5
|
Author-email: Vinit Kumar <mail@vinitkumar.me>
|
|
6
6
|
License: Apache Software License 2.0
|
|
@@ -33,6 +33,10 @@ Provides-Extra: test
|
|
|
33
33
|
Requires-Dist: pytest>=8.4.1; extra == "test"
|
|
34
34
|
Dynamic: license-file
|
|
35
35
|
|
|
36
|
+
.. image:: ./json2xml-hero.png
|
|
37
|
+
:alt: json2xml hero
|
|
38
|
+
|
|
39
|
+
|
|
36
40
|
========
|
|
37
41
|
json2xml
|
|
38
42
|
========
|
|
@@ -74,6 +78,22 @@ Installation
|
|
|
74
78
|
|
|
75
79
|
pip install json2xml
|
|
76
80
|
|
|
81
|
+
**With Native Rust Acceleration (29x faster)**
|
|
82
|
+
|
|
83
|
+
For maximum performance, install the optional Rust extension:
|
|
84
|
+
|
|
85
|
+
.. code-block:: console
|
|
86
|
+
|
|
87
|
+
# Install json2xml with Rust acceleration (when published)
|
|
88
|
+
pip install json2xml[fast]
|
|
89
|
+
|
|
90
|
+
# Or install the Rust extension separately
|
|
91
|
+
pip install json2xml-rs
|
|
92
|
+
|
|
93
|
+
The Rust extension provides **29x faster** conversion compared to pure Python. It's automatically used when available, with seamless fallback to pure Python.
|
|
94
|
+
|
|
95
|
+
*Note: The ``json2xml-rs`` package will be available on PyPI after the first Rust release.*
|
|
96
|
+
|
|
77
97
|
**As a CLI Tool**
|
|
78
98
|
|
|
79
99
|
The library includes a command-line tool ``json2xml-py`` that gets installed automatically:
|
|
@@ -316,6 +336,43 @@ Using tools directly:
|
|
|
316
336
|
ruff check json2xml tests
|
|
317
337
|
mypy json2xml tests
|
|
318
338
|
|
|
339
|
+
**Rust Extension Development**
|
|
340
|
+
|
|
341
|
+
The optional Rust extension (``json2xml-rs``) provides 29x faster performance. To develop or build the Rust extension:
|
|
342
|
+
|
|
343
|
+
Prerequisites:
|
|
344
|
+
|
|
345
|
+
.. code-block:: console
|
|
346
|
+
|
|
347
|
+
# Install Rust (if not already installed)
|
|
348
|
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
|
349
|
+
|
|
350
|
+
# Install maturin (Rust-Python build tool)
|
|
351
|
+
uv pip install maturin
|
|
352
|
+
|
|
353
|
+
Building the extension:
|
|
354
|
+
|
|
355
|
+
.. code-block:: console
|
|
356
|
+
|
|
357
|
+
# Development build (installs in current environment)
|
|
358
|
+
cd rust
|
|
359
|
+
uv pip install -e .
|
|
360
|
+
|
|
361
|
+
# Or using maturin directly
|
|
362
|
+
maturin develop --release
|
|
363
|
+
|
|
364
|
+
# Production wheel build
|
|
365
|
+
maturin build --release
|
|
366
|
+
|
|
367
|
+
Running Rust benchmarks:
|
|
368
|
+
|
|
369
|
+
.. code-block:: console
|
|
370
|
+
|
|
371
|
+
# After building the extension
|
|
372
|
+
python benchmark_rust.py
|
|
373
|
+
|
|
374
|
+
The Rust code is in ``rust/src/lib.rs`` and uses PyO3 for Python bindings.
|
|
375
|
+
|
|
319
376
|
|
|
320
377
|
CLI Usage
|
|
321
378
|
^^^^^^^^^
|
|
@@ -388,6 +445,115 @@ A Go port of this library is available at `json2xml-go <https://github.com/vinit
|
|
|
388
445
|
The Go version provides the same features and a native compiled binary for maximum performance.
|
|
389
446
|
|
|
390
447
|
|
|
448
|
+
Rust Extension (PyO3)
|
|
449
|
+
^^^^^^^^^^^^^^^^^^^^^
|
|
450
|
+
|
|
451
|
+
For users who need maximum performance within Python, json2xml includes an optional native Rust extension built with PyO3:
|
|
452
|
+
|
|
453
|
+
.. code-block:: console
|
|
454
|
+
|
|
455
|
+
pip install json2xml[fast]
|
|
456
|
+
|
|
457
|
+
**Rust vs Pure Python Performance:**
|
|
458
|
+
|
|
459
|
+
.. list-table::
|
|
460
|
+
:header-rows: 1
|
|
461
|
+
:widths: 30 20 20 15
|
|
462
|
+
|
|
463
|
+
* - Test Case
|
|
464
|
+
- Pure Python
|
|
465
|
+
- Rust Extension
|
|
466
|
+
- Speedup
|
|
467
|
+
* - **Small JSON** (47 bytes)
|
|
468
|
+
- 41µs
|
|
469
|
+
- 1.3µs
|
|
470
|
+
- **33x**
|
|
471
|
+
* - **Medium JSON** (3.2 KB)
|
|
472
|
+
- 2.1ms
|
|
473
|
+
- 76µs
|
|
474
|
+
- **28x**
|
|
475
|
+
* - **Large JSON** (32 KB)
|
|
476
|
+
- 21.5ms
|
|
477
|
+
- 727µs
|
|
478
|
+
- **30x**
|
|
479
|
+
* - **Very Large JSON** (323 KB)
|
|
480
|
+
- 215ms
|
|
481
|
+
- 7.4ms
|
|
482
|
+
- **29x**
|
|
483
|
+
|
|
484
|
+
**Usage with Rust Extension:**
|
|
485
|
+
|
|
486
|
+
.. code-block:: python
|
|
487
|
+
|
|
488
|
+
# Automatic backend selection (recommended)
|
|
489
|
+
from json2xml.dicttoxml_fast import dicttoxml, get_backend
|
|
490
|
+
|
|
491
|
+
print(f"Using backend: {get_backend()}") # 'rust' or 'python'
|
|
492
|
+
|
|
493
|
+
data = {"name": "John", "age": 30}
|
|
494
|
+
xml_bytes = dicttoxml(data)
|
|
495
|
+
|
|
496
|
+
The ``dicttoxml_fast`` module automatically uses the Rust backend when available and falls back to pure Python for unsupported features (like ``xpath_format``, ``xml_namespaces``, or custom ``item_func``).
|
|
497
|
+
|
|
498
|
+
**Platform Support:**
|
|
499
|
+
|
|
500
|
+
Pre-built wheels are available for:
|
|
501
|
+
|
|
502
|
+
- Linux (x86_64, aarch64)
|
|
503
|
+
- macOS (x86_64, arm64/Apple Silicon)
|
|
504
|
+
- Windows (x86_64)
|
|
505
|
+
|
|
506
|
+
For other platforms, the pure Python version is used automatically.
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
Performance Benchmarks
|
|
510
|
+
^^^^^^^^^^^^^^^^^^^^^^
|
|
511
|
+
|
|
512
|
+
Comprehensive benchmarks comparing Python, Go, and Zig implementations:
|
|
513
|
+
|
|
514
|
+
.. list-table::
|
|
515
|
+
:header-rows: 1
|
|
516
|
+
:widths: 25 20 15 15
|
|
517
|
+
|
|
518
|
+
* - Test Case
|
|
519
|
+
- Python (CPython)
|
|
520
|
+
- Go
|
|
521
|
+
- Zig
|
|
522
|
+
* - **Small JSON** (47 bytes)
|
|
523
|
+
- 68.88ms
|
|
524
|
+
- 7.13ms
|
|
525
|
+
- 2.65ms
|
|
526
|
+
* - **Medium JSON** (2.6 KB)
|
|
527
|
+
- 73.40ms
|
|
528
|
+
- 4.85ms
|
|
529
|
+
- 2.13ms
|
|
530
|
+
* - **Large JSON** (323 KB)
|
|
531
|
+
- 420.06ms
|
|
532
|
+
- 68.88ms
|
|
533
|
+
- 5.90ms
|
|
534
|
+
* - **Very Large JSON** (1.6 MB)
|
|
535
|
+
- 2.08s
|
|
536
|
+
- 288.75ms
|
|
537
|
+
- 20.62ms
|
|
538
|
+
|
|
539
|
+
**Recommendation by Use Case:**
|
|
540
|
+
|
|
541
|
+
- **Python integration / scripting**: Use this library (json2xml)
|
|
542
|
+
- **CLI tool / moderate performance**: Use `json2xml-go <https://github.com/vinitkumar/json2xml-go>`_
|
|
543
|
+
- **Maximum performance / large files**: Use `json2xml-zig <https://github.com/vinitkumar/json2xml-zig>`_
|
|
544
|
+
|
|
545
|
+
For detailed benchmarks, see `BENCHMARKS.md <https://github.com/vinitkumar/json2xml/blob/master/BENCHMARKS.md>`_.
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
Other Implementations
|
|
549
|
+
^^^^^^^^^^^^^^^^^^^^^
|
|
550
|
+
|
|
551
|
+
This library is also available in other languages:
|
|
552
|
+
|
|
553
|
+
- **Go**: `json2xml-go <https://github.com/vinitkumar/json2xml-go>`_ - 7x faster, native compiled binary
|
|
554
|
+
- **Zig**: `json2xml-zig <https://github.com/vinitkumar/json2xml-zig>`_ - 85x faster, maximum performance
|
|
555
|
+
|
|
556
|
+
|
|
391
557
|
Help and Support to maintain this project
|
|
392
558
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
393
559
|
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
.. image:: ./json2xml-hero.png
|
|
2
|
+
:alt: json2xml hero
|
|
3
|
+
|
|
4
|
+
|
|
1
5
|
========
|
|
2
6
|
json2xml
|
|
3
7
|
========
|
|
@@ -39,6 +43,22 @@ Installation
|
|
|
39
43
|
|
|
40
44
|
pip install json2xml
|
|
41
45
|
|
|
46
|
+
**With Native Rust Acceleration (29x faster)**
|
|
47
|
+
|
|
48
|
+
For maximum performance, install the optional Rust extension:
|
|
49
|
+
|
|
50
|
+
.. code-block:: console
|
|
51
|
+
|
|
52
|
+
# Install json2xml with Rust acceleration (when published)
|
|
53
|
+
pip install json2xml[fast]
|
|
54
|
+
|
|
55
|
+
# Or install the Rust extension separately
|
|
56
|
+
pip install json2xml-rs
|
|
57
|
+
|
|
58
|
+
The Rust extension provides **29x faster** conversion compared to pure Python. It's automatically used when available, with seamless fallback to pure Python.
|
|
59
|
+
|
|
60
|
+
*Note: The ``json2xml-rs`` package will be available on PyPI after the first Rust release.*
|
|
61
|
+
|
|
42
62
|
**As a CLI Tool**
|
|
43
63
|
|
|
44
64
|
The library includes a command-line tool ``json2xml-py`` that gets installed automatically:
|
|
@@ -281,6 +301,43 @@ Using tools directly:
|
|
|
281
301
|
ruff check json2xml tests
|
|
282
302
|
mypy json2xml tests
|
|
283
303
|
|
|
304
|
+
**Rust Extension Development**
|
|
305
|
+
|
|
306
|
+
The optional Rust extension (``json2xml-rs``) provides 29x faster performance. To develop or build the Rust extension:
|
|
307
|
+
|
|
308
|
+
Prerequisites:
|
|
309
|
+
|
|
310
|
+
.. code-block:: console
|
|
311
|
+
|
|
312
|
+
# Install Rust (if not already installed)
|
|
313
|
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
|
314
|
+
|
|
315
|
+
# Install maturin (Rust-Python build tool)
|
|
316
|
+
uv pip install maturin
|
|
317
|
+
|
|
318
|
+
Building the extension:
|
|
319
|
+
|
|
320
|
+
.. code-block:: console
|
|
321
|
+
|
|
322
|
+
# Development build (installs in current environment)
|
|
323
|
+
cd rust
|
|
324
|
+
uv pip install -e .
|
|
325
|
+
|
|
326
|
+
# Or using maturin directly
|
|
327
|
+
maturin develop --release
|
|
328
|
+
|
|
329
|
+
# Production wheel build
|
|
330
|
+
maturin build --release
|
|
331
|
+
|
|
332
|
+
Running Rust benchmarks:
|
|
333
|
+
|
|
334
|
+
.. code-block:: console
|
|
335
|
+
|
|
336
|
+
# After building the extension
|
|
337
|
+
python benchmark_rust.py
|
|
338
|
+
|
|
339
|
+
The Rust code is in ``rust/src/lib.rs`` and uses PyO3 for Python bindings.
|
|
340
|
+
|
|
284
341
|
|
|
285
342
|
CLI Usage
|
|
286
343
|
^^^^^^^^^
|
|
@@ -353,6 +410,115 @@ A Go port of this library is available at `json2xml-go <https://github.com/vinit
|
|
|
353
410
|
The Go version provides the same features and a native compiled binary for maximum performance.
|
|
354
411
|
|
|
355
412
|
|
|
413
|
+
Rust Extension (PyO3)
|
|
414
|
+
^^^^^^^^^^^^^^^^^^^^^
|
|
415
|
+
|
|
416
|
+
For users who need maximum performance within Python, json2xml includes an optional native Rust extension built with PyO3:
|
|
417
|
+
|
|
418
|
+
.. code-block:: console
|
|
419
|
+
|
|
420
|
+
pip install json2xml[fast]
|
|
421
|
+
|
|
422
|
+
**Rust vs Pure Python Performance:**
|
|
423
|
+
|
|
424
|
+
.. list-table::
|
|
425
|
+
:header-rows: 1
|
|
426
|
+
:widths: 30 20 20 15
|
|
427
|
+
|
|
428
|
+
* - Test Case
|
|
429
|
+
- Pure Python
|
|
430
|
+
- Rust Extension
|
|
431
|
+
- Speedup
|
|
432
|
+
* - **Small JSON** (47 bytes)
|
|
433
|
+
- 41µs
|
|
434
|
+
- 1.3µs
|
|
435
|
+
- **33x**
|
|
436
|
+
* - **Medium JSON** (3.2 KB)
|
|
437
|
+
- 2.1ms
|
|
438
|
+
- 76µs
|
|
439
|
+
- **28x**
|
|
440
|
+
* - **Large JSON** (32 KB)
|
|
441
|
+
- 21.5ms
|
|
442
|
+
- 727µs
|
|
443
|
+
- **30x**
|
|
444
|
+
* - **Very Large JSON** (323 KB)
|
|
445
|
+
- 215ms
|
|
446
|
+
- 7.4ms
|
|
447
|
+
- **29x**
|
|
448
|
+
|
|
449
|
+
**Usage with Rust Extension:**
|
|
450
|
+
|
|
451
|
+
.. code-block:: python
|
|
452
|
+
|
|
453
|
+
# Automatic backend selection (recommended)
|
|
454
|
+
from json2xml.dicttoxml_fast import dicttoxml, get_backend
|
|
455
|
+
|
|
456
|
+
print(f"Using backend: {get_backend()}") # 'rust' or 'python'
|
|
457
|
+
|
|
458
|
+
data = {"name": "John", "age": 30}
|
|
459
|
+
xml_bytes = dicttoxml(data)
|
|
460
|
+
|
|
461
|
+
The ``dicttoxml_fast`` module automatically uses the Rust backend when available and falls back to pure Python for unsupported features (like ``xpath_format``, ``xml_namespaces``, or custom ``item_func``).
|
|
462
|
+
|
|
463
|
+
**Platform Support:**
|
|
464
|
+
|
|
465
|
+
Pre-built wheels are available for:
|
|
466
|
+
|
|
467
|
+
- Linux (x86_64, aarch64)
|
|
468
|
+
- macOS (x86_64, arm64/Apple Silicon)
|
|
469
|
+
- Windows (x86_64)
|
|
470
|
+
|
|
471
|
+
For other platforms, the pure Python version is used automatically.
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
Performance Benchmarks
|
|
475
|
+
^^^^^^^^^^^^^^^^^^^^^^
|
|
476
|
+
|
|
477
|
+
Comprehensive benchmarks comparing Python, Go, and Zig implementations:
|
|
478
|
+
|
|
479
|
+
.. list-table::
|
|
480
|
+
:header-rows: 1
|
|
481
|
+
:widths: 25 20 15 15
|
|
482
|
+
|
|
483
|
+
* - Test Case
|
|
484
|
+
- Python (CPython)
|
|
485
|
+
- Go
|
|
486
|
+
- Zig
|
|
487
|
+
* - **Small JSON** (47 bytes)
|
|
488
|
+
- 68.88ms
|
|
489
|
+
- 7.13ms
|
|
490
|
+
- 2.65ms
|
|
491
|
+
* - **Medium JSON** (2.6 KB)
|
|
492
|
+
- 73.40ms
|
|
493
|
+
- 4.85ms
|
|
494
|
+
- 2.13ms
|
|
495
|
+
* - **Large JSON** (323 KB)
|
|
496
|
+
- 420.06ms
|
|
497
|
+
- 68.88ms
|
|
498
|
+
- 5.90ms
|
|
499
|
+
* - **Very Large JSON** (1.6 MB)
|
|
500
|
+
- 2.08s
|
|
501
|
+
- 288.75ms
|
|
502
|
+
- 20.62ms
|
|
503
|
+
|
|
504
|
+
**Recommendation by Use Case:**
|
|
505
|
+
|
|
506
|
+
- **Python integration / scripting**: Use this library (json2xml)
|
|
507
|
+
- **CLI tool / moderate performance**: Use `json2xml-go <https://github.com/vinitkumar/json2xml-go>`_
|
|
508
|
+
- **Maximum performance / large files**: Use `json2xml-zig <https://github.com/vinitkumar/json2xml-zig>`_
|
|
509
|
+
|
|
510
|
+
For detailed benchmarks, see `BENCHMARKS.md <https://github.com/vinitkumar/json2xml/blob/master/BENCHMARKS.md>`_.
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
Other Implementations
|
|
514
|
+
^^^^^^^^^^^^^^^^^^^^^
|
|
515
|
+
|
|
516
|
+
This library is also available in other languages:
|
|
517
|
+
|
|
518
|
+
- **Go**: `json2xml-go <https://github.com/vinitkumar/json2xml-go>`_ - 7x faster, native compiled binary
|
|
519
|
+
- **Zig**: `json2xml-zig <https://github.com/vinitkumar/json2xml-zig>`_ - 85x faster, maximum performance
|
|
520
|
+
|
|
521
|
+
|
|
356
522
|
Help and Support to maintain this project
|
|
357
523
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
358
524
|
|