{"id":13460333,"url":"https://github.com/samuelcolvin/rtoml","last_synced_at":"2025-05-14T19:09:47.486Z","repository":{"id":36946149,"uuid":"232429600","full_name":"samuelcolvin/rtoml","owner":"samuelcolvin","description":"A fast TOML library for python implemented in rust.","archived":false,"fork":false,"pushed_at":"2025-04-02T13:24:19.000Z","size":197,"stargazers_count":351,"open_issues_count":12,"forks_count":29,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-13T13:38:27.672Z","etag":null,"topics":["deserialization","parser","python","rust","toml"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/rtoml/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samuelcolvin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-01-07T22:30:25.000Z","updated_at":"2025-04-09T14:49:59.000Z","dependencies_parsed_at":"2022-07-11T14:22:56.241Z","dependency_job_id":"5cfd1054-01cc-410f-8d30-02d3ef0380e2","html_url":"https://github.com/samuelcolvin/rtoml","commit_stats":{"total_commits":99,"total_committers":16,"mean_commits":6.1875,"dds":0.202020202020202,"last_synced_commit":"a957d04c4a32de00a5901a9dd78df559b7cd901e"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samuelcolvin%2Frtoml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samuelcolvin%2Frtoml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samuelcolvin%2Frtoml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samuelcolvin%2Frtoml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samuelcolvin","download_url":"https://codeload.github.com/samuelcolvin/rtoml/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254209859,"owners_count":22032897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deserialization","parser","python","rust","toml"],"created_at":"2024-07-31T10:00:39.888Z","updated_at":"2025-05-14T19:09:46.194Z","avatar_url":"https://github.com/samuelcolvin.png","language":"Python","funding_links":[],"categories":["Python","语言资源库","Data Serialization","Utilities"],"sub_categories":["rust"],"readme":"# rtoml\n\n[![Actions Status](https://github.com/samuelcolvin/rtoml/workflows/CI/badge.svg)](https://github.com/samuelcolvin/rtoml/actions?query=event%3Apush+branch%3Amain+workflow%3ACI)\n[![Coverage](https://codecov.io/gh/samuelcolvin/rtoml/branch/main/graph/badge.svg)](https://codecov.io/gh/samuelcolvin/rtoml)\n[![pypi](https://img.shields.io/pypi/v/rtoml.svg)](https://pypi.python.org/pypi/rtoml)\n[![versions](https://img.shields.io/pypi/pyversions/rtoml.svg)](https://github.com/samuelcolvin/rtoml)\n[![license](https://img.shields.io/github/license/samuelcolvin/rtoml.svg)](https://github.com/samuelcolvin/rtoml/blob/main/LICENSE)\n\n\nA better TOML library for python implemented in rust.\n\n## Why Use rtoml\n\n* Correctness: rtoml is based on the widely used and very stable [toml-rs](https://github.com/alexcrichton/toml-rs)\nlibrary, it passes all the [standard TOML tests](https://github.com/BurntSushi/toml-test) as well as having 100%\ncoverage on python code. Other TOML libraries for python I tried all failed to parse some valid TOML.\n* Performance: see [github.com/pwwang/toml-bench](https://github.com/pwwang/toml-bench) -\n  rtoml is the fastest Python TOML libraries at the time of writing.\n* `None`-value handling: rtoml has flexible support for `None` values, instead of simply ignoring them.\n\n## Install\n\nRequires `python\u003e=3.9`, binaries are available from PyPI for Linux, macOS and Windows,\nsee [here](https://pypi.org/project/rtoml/#files).\n\n```bash\npip install rtoml\n```\n\nIf no binary is available on pypi for you system configuration; you'll need rust stable\ninstalled before you can install rtoml.\n\n## Usage\n\n#### load\n```python\ndef load(toml: Union[str, Path, TextIO], *, none_value: Optional[str] = None) -\u003e Dict[str, Any]: ...\n```\n\nParse TOML via a string or file and return a python dictionary.\n\n* `toml`: a `str`, `Path` or file object from `open()`.\n* `none_value`: controlling which value in `toml` is loaded as `None` in python. By default, `none_value` is `None`, which means nothing is loaded as `None`\n\n#### loads\n```python\ndef loads(toml: str, *, none_value: Optional[str] = None) -\u003e Dict[str, Any]: ...\n```\n\nParse a TOML string and return a python dictionary. (provided to match the interface of `json` and similar libraries)\n\n* `toml`: a `str` containing TOML.\n* `none_value`: controlling which value in `toml` is loaded as `None` in python. By default, `none_value` is `None`, which means nothing is loaded as `None`\n\n#### dumps\n```python\ndef dumps(obj: Any, *, pretty: bool = False, none_value: Optional[str] = \"null\") -\u003e str: ...\n```\n\nSerialize a python object to TOML.\n\n* `obj`: a python object to be serialized.\n* `pretty`: if `True` the output has a more \"pretty\" format.\n* `none_value`: controlling how `None` values in `obj` are serialized. `none_value=None` means `None` values are ignored.\n\n#### dump\n```python\ndef dump(\n    obj: Any, file: Union[Path, TextIO], *, pretty: bool = False, none_value: Optional[str] = \"null\"\n) -\u003e int: ...\n```\n\nSerialize a python object to TOML and write it to a file.\n\n* `obj`: a python object to be serialized.\n* `file`: a `Path` or file object from `open()`.\n* `pretty`: if `True` the output has a more \"pretty\" format.\n* `none_value`: controlling how `None` values in `obj` are serialized. `none_value=None` means `None` values are ignored.\n\n### Examples\n\n```py\nfrom datetime import datetime, timezone, timedelta\nimport rtoml\n\nobj = {\n    'title': 'TOML Example',\n    'owner': {\n        'dob': datetime(1979, 5, 27, 7, 32, tzinfo=timezone(timedelta(hours=-8))),\n        'name': 'Tom Preston-Werner',\n    },\n    'database': {\n        'connection_max': 5000,\n        'enabled': True,\n        'ports': [8001, 8001, 8002],\n        'server': '192.168.1.1',\n    },\n}\n\nloaded_obj = rtoml.load(\"\"\"\\\n# This is a TOML document.\n\ntitle = \"TOML Example\"\n\n[owner]\nname = \"Tom Preston-Werner\"\ndob = 1979-05-27T07:32:00-08:00 # First class dates\n\n[database]\nserver = \"192.168.1.1\"\nports = [8001, 8001, 8002]\nconnection_max = 5000\nenabled = true\n\"\"\")\n\nassert loaded_obj == obj\n\nassert rtoml.dumps(obj) == \"\"\"\\\ntitle = \"TOML Example\"\n\n[owner]\ndob = 1979-05-27T07:32:00-08:00\nname = \"Tom Preston-Werner\"\n\n[database]\nconnection_max = 5000\nenabled = true\nserver = \"192.168.1.1\"\nports = [8001, 8001, 8002]\n\"\"\"\n```\n\nAn example of `None`-value handling:\n\n```python\nobj = {\n    'a': None,\n    'b': 1,\n    'c': [1, 2, None, 3],\n}\n\n# Ignore None values\nassert rtoml.dumps(obj, none_value=None) == \"\"\"\\\nb = 1\nc = [1, 2, 3]\n\"\"\"\n\n# Serialize None values as '@None'\nassert rtoml.dumps(obj, none_value='@None') == \"\"\"\\\na = \"@None\"\nb = 1\nc = [1, 2, \"@None\", 3]\n\"\"\"\n\n# Deserialize '@None' back to None\nassert rtoml.load(\"\"\"\\\na = \"@None\"\nb = 1\nc = [1, 2, \"@None\", 3]\n\"\"\", none_value='@None') == obj\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamuelcolvin%2Frtoml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamuelcolvin%2Frtoml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamuelcolvin%2Frtoml/lists"}