{"id":308,"library":"tomli","title":"Tomli","description":"Tomli is a Python library for parsing TOML (Tom's Obvious, Minimal Language) files, fully compatible with TOML v1.0.0. As of version 2.4.1, it provides a backport of the standard library's `tomllib` module introduced in Python 3.11, ensuring compatibility for earlier Python versions. The library is actively maintained, with regular updates to enhance functionality and maintain compatibility.","status":"active","version":"2.4.1","language":"python","source_language":"en","source_url":"https://github.com/hukkin/tomli","tags":["TOML","parser","configuration","Python"],"install":[{"cmd":"pip install tomli","lang":"bash","label":"Install Tomli via pip"}],"dependencies":[],"imports":[{"note":"Directly importing the function avoids unnecessary namespace usage.","wrong":"import tomli\nload = tomli.load","symbol":"load","correct":"from tomli import load"},{"note":"Direct import is more concise and aligns with common Python practices.","wrong":"import tomli\nloads = tomli.loads","symbol":"loads","correct":"from tomli import loads"}],"quickstart":{"code":"import tomli\n\nwith open('config.toml', 'rb') as f:\n    config = tomli.load(f)\n\nprint(config)","lang":"python","description":"This example demonstrates how to parse a TOML file named 'config.toml' and print its contents as a Python dictionary."},"warnings":[{"fix":"Use the 'tomli-w' library for writing TOML files.","message":"Tomli is read-only; it does not support writing TOML files.","severity":"breaking","affected_versions":"All versions"},{"fix":"Ensure files are opened with the 'rb' mode when using tomli.load().","message":"Tomli requires file objects to be opened in binary mode ('rb').","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware that parsing and re-serializing a TOML file will lose comments and original formatting.","message":"Tomli does not preserve comments or formatting in TOML files.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that the required TOML file (e.g., 'config.toml') exists in the working directory or at the specified path before running the application.","message":"The TOML configuration file expected by the script was not found.","severity":"breaking","affected_versions":"All versions"},{"fix":"Verify that the TOML file exists at the specified path relative to the script's execution. Provide the correct file path or ensure the file is present.","message":"The specified TOML configuration file was not found. Ensure the file path is correct and the file exists in the expected location.","severity":"breaking","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'2.4.1':24 '3.11':39 'activ':49 'backport':28 'compat':17,41,59 'configur':62 'earlier':43 'enhanc':55 'ensur':40 'file':15 'fulli':16 'function':56 'introduc':36 'languag':14 'librari':6,32,47 'maintain':50,58 'minim':13 'modul':35 'obvious':12 'pars':8 'parser':61 'provid':26 'python':5,38,44,63 'regular':52 'standard':31 'tom':1,2,10 'toml':9,19,60 'tomllib':34 'updat':53 'v1.0.0':20 'version':23,45","created_at":"2026-03-28T08:21:20.473127+00:00","updated_at":"2026-04-16T23:01:36.070171+00:00","problems":[{"fix":"pip install tomli","cause":"The 'tomli' package has not been installed in your Python environment.","error":"ModuleNotFoundError: No module named 'tomli'"},{"fix":"Verify the existence and correct path of your TOML file, ensuring it's accessible to the script, e.g., 'path/to/your/config.toml'.","cause":"The TOML file specified for loading does not exist at the given path or the path is incorrect relative to where the script is executed.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'config.toml'"},{"fix":"Escape literal backslashes using `\\\\` (e.g., change `\\s` to `\\\\s`) or use a literal string; only specific escape sequences are allowed in TOML basic strings.","cause":"The TOML file contains an unrecognized escape sequence within a basic string (e.g., '\\s', '\\v'), which violates TOML's string literal rules.","error":"tomli.TOMLDecodeError: Invalid escape sequence: '\\s'"},{"fix":"Review your TOML file and ensure all keys within any given table are unique; rename or remove duplicate key definitions.","cause":"The TOML file attempts to define the same key more than once within the same table, which is disallowed by the TOML specification.","error":"tomli.TOMLDecodeError: Key 'my_key' has already been defined"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":0,"quickstart_tag":"stale","pypi_latest":"2.4.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/hukkin/tomli","docs":null,"changelog":"https://github.com/hukkin/tomli/blob/master/CHANGELOG.md","pypi":"https://pypi.org/project/tomli/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}