Python reader for Rusty Object Notation
Project description
disclaimer
i can't guarantee the quality of this software, don't rely on it for anything serious
(also parts of it were made with (or by) gen-AI)
probably better use it if you want to hack on it, and fork/submit PRs
what
a quick thing built with the goal to work with RON (Rust Object Notation) files in pure python
https://github.com/ron-rs/ron/issues/306
why
because I wanted to write some scripts against RON files, and couldn't find anything usable, so I threw some code together with gemini and ANTLR4
installation
PyPI link: https://pypi.org/project/ron-python/
pip install ron-python
Or with modern alternative
uv add ron-python
Or, if you want a development version, feel free to use something like that
uv add git+https://github.com/juliancoffee/ron-py
(I'd recomment to pin it to a specific commit though)
how to use
Stable docs: https://juliancoffee.github.io/ron-py/latest/ron.html
Main branch docs: https://juliancoffee.github.io/ron-py/dev/ron.html
There's FromRonMixin which gives you from_ron method.
from dataclasses import dataclass
from ron import FromRonMixin
@dataclass
class Click(FromRonMixin):
x: int
y: int
obj = Click.from_ron("Click(x: 10, y: 20)")
assert isinstance(res1, Click)
assert res1.x == 10
Or there's more low-level API if that's your thing.
from ron import parse_ron
from ron.models import RonStruct
def test_struct_as_key():
data = r"""
{
UserID(123): "Admin",
UserID(456): "Guest"
}
"""
# yes, you can just parse it to raw object
obj = parse_ron(data)
# type-narrow it
raw_map = obj.expect_map()
assert len(raw_map.entries) == 2
keys = list(raw_map.entries.keys())
target_key = keys[0]
# or compare to internal types
# sneak peek, we also have spans (only for struct field values though, as of now)
# use `parse_ron(src, with_spans=True)`
assert target_key == RonStruct("UserID", (123,), spans=None)
assert raw_map.entries[target_key] == "Admin"
Alternatively, there's __getitem__ implementation, which loses some type strictness, but is super convenient.
def test_deep_chaining_nested_structures():
ron_str = """
Player(
stats: { "attributes": [10, 15] },
inventory: [ Item(name: "Sword") ]
)
"""
obj = parse_ron(ron_str)
# use a struct like you'd use dict
strength = obj["stats"]["attributes"][0]
assert strength.expect_int() == 10
# can be infinitely nested, until you jump out with `expect_*` method
weapon = obj["inventory"][0]["name"]
assert weapon.expect_str() == "Sword"
def test_unit_struct_lookup():
obj = parse_ron('{ King: "Crown" }')
# or even go bonkers and do this
assert obj["King"].expect_str() == "Crown"
Check out tests and main.py in the root for more (and, potentially, more up-to-date examples).
limitations
doesn't support extensions, yet
contributions
PRs are probably welcome, I don't expect much in terms of the protocol, just use common sense
we even have CI now :D
notable mentions
- https://pypi.org/project/python-ron/ & https://github.com/cswinter/pyron
I couldn't install it, and it relies on ron-rs, which doesn't have good support for untyped data. Last I checked, it didn't support many datatype kinds (https://github.com/ron-rs/ron/issues/122). - https://github.com/jasonjmcghee/ron-lsp just because it's cool as heck
- https://github.com/whiteand/ron-js javascript implementation
- https://github.com/chriskilding/jackson-dataformat-ron Java Jackson implementation
- https://github.com/sorairolake/ron-wasm and wasm bindings, which probably suffer from the same problem as python bindings
- https://github.com/ron-rs/ron2 ron rewrite to fix the current issues by relying less on serde
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ron_python-0.0.3.tar.gz.
File metadata
- Download URL: ron_python-0.0.3.tar.gz
- Upload date:
- Size: 53.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebd8cd07cf3c9eef0cd5f09570b576ef298f54eff43fd28a3da8eeb302bafcac
|
|
| MD5 |
bdfaffdda44f6863607f7b90973b4a07
|
|
| BLAKE2b-256 |
a5c1c3167f6f5b9fb4006ba8d9d97785254edd83dbf28fda5ad205f8264c0b1a
|
Provenance
The following attestation bundles were made for ron_python-0.0.3.tar.gz:
Publisher:
pypi.yml on juliancoffee/ron-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ron_python-0.0.3.tar.gz -
Subject digest:
ebd8cd07cf3c9eef0cd5f09570b576ef298f54eff43fd28a3da8eeb302bafcac - Sigstore transparency entry: 953590539
- Sigstore integration time:
-
Permalink:
juliancoffee/ron-py@4afd778b35fd2cf936f6cf712daa9ffb12296939 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/juliancoffee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@4afd778b35fd2cf936f6cf712daa9ffb12296939 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ron_python-0.0.3-py3-none-any.whl.
File metadata
- Download URL: ron_python-0.0.3-py3-none-any.whl
- Upload date:
- Size: 28.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47389e6c72a58b64dd338fa280c1f61d0170c55016731de2abcd79ec2003b0c9
|
|
| MD5 |
b61875ca7119cef312054728a8d0aac4
|
|
| BLAKE2b-256 |
70f54e9681f34b8bd826178f9e212a45c6176538bcb33d7560cdc838e695164c
|
Provenance
The following attestation bundles were made for ron_python-0.0.3-py3-none-any.whl:
Publisher:
pypi.yml on juliancoffee/ron-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ron_python-0.0.3-py3-none-any.whl -
Subject digest:
47389e6c72a58b64dd338fa280c1f61d0170c55016731de2abcd79ec2003b0c9 - Sigstore transparency entry: 953590541
- Sigstore integration time:
-
Permalink:
juliancoffee/ron-py@4afd778b35fd2cf936f6cf712daa9ffb12296939 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/juliancoffee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@4afd778b35fd2cf936f6cf712daa9ffb12296939 -
Trigger Event:
push
-
Statement type: