o3json5


Nameo3json5 JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryA fast JSON5 parser for Python, written in Rust 🦀
upload_time2024-12-30 03:21:21
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords json json5 parser rust fast
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # O3JSON5

A fast JSON5 parser for Python, written in Rust 🦀

## Features

- Full JSON5 support (comments, trailing commas, unquoted keys, etc.)
- Simple, Pythonic API
- Fast performance (up to 100x faster than pure Python implementations)
- Type hints included

Heavy-lifting done by https://github.com/callum-oakley/json5-rs in Rust.

## Installation

```bash
pip install o3json5 # or use uv, pdm, poetry, etc. your favorite package manager
```

## Quick Start

```python
import o3json5

# Parse JSON5 with comments and modern features
json5_str = '''{ 
    // Comments are supported!
    name: 'O3JSON5',
    features: [
        'Fast',
        'Simple',
        'Reliable',
    ],
    performance: {
        isFast: true,
        speedRatio: .95, // Decimal points can start with .
    },
}'''

data = o3json5.loads(json5_str)
print(f"Name: {data['name']}")
```

## Benchmarks

O3JSON5 is significantly faster than pure Python JSON5 implementations, approaching native JSON speeds. Click below for detailed benchmarks.

<details>
<summary>View detailed benchmark results</summary>

```
> python examples/bench.py
Generating test data and running benchmarks...


Benchmarking with approximate 10,000 bytes of data
------------------------------------------------------------
Actual file size: 4,459 bytes
      json: 0.04ms ± 0.01ms
     json5: 40.28ms ± 1.03ms
   o3json5: 0.35ms ± 0.18ms


Benchmarking with approximate 100,000 bytes of data
------------------------------------------------------------
Actual file size: 43,416 bytes
      json: 0.28ms ± 0.02ms
     json5: 383.36ms ± 3.38ms
   o3json5: 2.72ms ± 0.11ms


Benchmarking with approximate 1,000,000 bytes of data
------------------------------------------------------------
Actual file size: 435,373 bytes
      json: 2.94ms ± 0.13ms
     json5: 3870.65ms ± 28.20ms
   o3json5: 28.32ms ± 0.10ms
```

</details>

Note: micro-benchmarks don't say much, and we are already doing JSON5 -> Rust in-memory data structures -> Python in-memory data structures -- while the performance can be further improved, for most use cases, the performance is already good enough.

## Reference

### Functions

- `loads(s: Union[str, bytes, bytearray]) -> Any`
  - Parses a JSON5 string or bytes-like object
  - Raises `DecodeError` if input is invalid JSON5
  - Raises `TypeError` if input type is not supported

- `load(fp: Union[str, Path, TextIO]) -> Any`
  - Parses JSON5 from a file path or file-like object
  - Accepts string path, Path object, or file-like object
  - Raises `DecodeError`, `TypeError`, or `OSError`

### Exceptions

- `DecodeError`
  - Subclass of `ValueError`
  - Raised when JSON5 parsing fails
  - Contains error message with details


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "o3json5",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "json, json5, parser, rust, fast",
    "author": null,
    "author_email": "RuneBlaze <liubaqiao@gmail.com>",
    "download_url": null,
    "platform": null,
    "description": "# O3JSON5\n\nA fast JSON5 parser for Python, written in Rust \ud83e\udd80\n\n## Features\n\n- Full JSON5 support (comments, trailing commas, unquoted keys, etc.)\n- Simple, Pythonic API\n- Fast performance (up to 100x faster than pure Python implementations)\n- Type hints included\n\nHeavy-lifting done by https://github.com/callum-oakley/json5-rs in Rust.\n\n## Installation\n\n```bash\npip install o3json5 # or use uv, pdm, poetry, etc. your favorite package manager\n```\n\n## Quick Start\n\n```python\nimport o3json5\n\n# Parse JSON5 with comments and modern features\njson5_str = '''{ \n    // Comments are supported!\n    name: 'O3JSON5',\n    features: [\n        'Fast',\n        'Simple',\n        'Reliable',\n    ],\n    performance: {\n        isFast: true,\n        speedRatio: .95, // Decimal points can start with .\n    },\n}'''\n\ndata = o3json5.loads(json5_str)\nprint(f\"Name: {data['name']}\")\n```\n\n## Benchmarks\n\nO3JSON5 is significantly faster than pure Python JSON5 implementations, approaching native JSON speeds. Click below for detailed benchmarks.\n\n<details>\n<summary>View detailed benchmark results</summary>\n\n```\n> python examples/bench.py\nGenerating test data and running benchmarks...\n\n\nBenchmarking with approximate 10,000 bytes of data\n------------------------------------------------------------\nActual file size: 4,459 bytes\n      json: 0.04ms \u00b1 0.01ms\n     json5: 40.28ms \u00b1 1.03ms\n   o3json5: 0.35ms \u00b1 0.18ms\n\n\nBenchmarking with approximate 100,000 bytes of data\n------------------------------------------------------------\nActual file size: 43,416 bytes\n      json: 0.28ms \u00b1 0.02ms\n     json5: 383.36ms \u00b1 3.38ms\n   o3json5: 2.72ms \u00b1 0.11ms\n\n\nBenchmarking with approximate 1,000,000 bytes of data\n------------------------------------------------------------\nActual file size: 435,373 bytes\n      json: 2.94ms \u00b1 0.13ms\n     json5: 3870.65ms \u00b1 28.20ms\n   o3json5: 28.32ms \u00b1 0.10ms\n```\n\n</details>\n\nNote: micro-benchmarks don't say much, and we are already doing JSON5 -> Rust in-memory data structures -> Python in-memory data structures -- while the performance can be further improved, for most use cases, the performance is already good enough.\n\n## Reference\n\n### Functions\n\n- `loads(s: Union[str, bytes, bytearray]) -> Any`\n  - Parses a JSON5 string or bytes-like object\n  - Raises `DecodeError` if input is invalid JSON5\n  - Raises `TypeError` if input type is not supported\n\n- `load(fp: Union[str, Path, TextIO]) -> Any`\n  - Parses JSON5 from a file path or file-like object\n  - Accepts string path, Path object, or file-like object\n  - Raises `DecodeError`, `TypeError`, or `OSError`\n\n### Exceptions\n\n- `DecodeError`\n  - Subclass of `ValueError`\n  - Raised when JSON5 parsing fails\n  - Contains error message with details\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A fast JSON5 parser for Python, written in Rust \ud83e\udd80",
    "version": "0.1.0",
    "project_urls": {
        "Documentation": "https://github.com/RuneBlaze/o3json5#readme",
        "Homepage": "https://github.com/RuneBlaze/o3json5"
    },
    "split_keywords": [
        "json",
        " json5",
        " parser",
        " rust",
        " fast"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5984faad64ff84fe6fbade8eb11361f72c16ffa5a7734f9ffb556e56d027c963",
                "md5": "d9ac3aff8daa332422a080e6ebd90b0c",
                "sha256": "ad75c25ef50dc8d8dafb10f1f5b0aa245b37fa328497d6cf90443754d499f189"
            },
            "downloads": -1,
            "filename": "o3json5-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl",
            "has_sig": false,
            "md5_digest": "d9ac3aff8daa332422a080e6ebd90b0c",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 313029,
            "upload_time": "2024-12-30T03:21:21",
            "upload_time_iso_8601": "2024-12-30T03:21:21.948920Z",
            "url": "https://files.pythonhosted.org/packages/59/84/faad64ff84fe6fbade8eb11361f72c16ffa5a7734f9ffb556e56d027c963/o3json5-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "818064b1c88f4fdcca778ceafc161ffc932f058d672a093f2e4bfac8fe5afff8",
                "md5": "6d106bc64556eba4f39227ee81faa562",
                "sha256": "e6274b82cf03e074c4a5b1cf541a5f3d0dad9e17165b746a59f28c3342cede3b"
            },
            "downloads": -1,
            "filename": "o3json5-0.1.0-cp38-abi3-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "6d106bc64556eba4f39227ee81faa562",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 303650,
            "upload_time": "2024-12-30T03:21:23",
            "upload_time_iso_8601": "2024-12-30T03:21:23.330986Z",
            "url": "https://files.pythonhosted.org/packages/81/80/64b1c88f4fdcca778ceafc161ffc932f058d672a093f2e4bfac8fe5afff8/o3json5-0.1.0-cp38-abi3-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-30 03:21:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "RuneBlaze",
    "github_project": "o3json5#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "o3json5"
}
        
Elapsed time: 0.42583s