{"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,"last_verified":"2026-05-12T12:59:07.077Z","next_check":"2026-06-26T00:00:00.000Z","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,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"17.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"20.3M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.1,"disk_size":"12.2M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.1,"disk_size":"13M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"11.8M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.1,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"17.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.3,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}