@@ -6,23 +6,33 @@ variables are commonly used to store "secrets" such as Wi-Fi passwords and API
66keys. This method *does not * make them secure. It only separates them from the
77code.
88
9- CircuitPython supports these by parsing a subset of the `toml <https://toml.io/ >`_ file format internally.
9+ CircuitPython uses a file called ``settings.toml `` at the drive root (no
10+ folder) as the environment. User code can access the values from the file
11+ using `os.getenv() `. It is recommended to save any values used repeatedly in a
12+ variable because `os.getenv() ` will parse the ``settings.toml `` file contents
13+ on every access.
1014
11- Here is a simple example:
15+ CircuitPython only supports a subset of the full toml specification, see below
16+ for more details. The subset is very "Python-like", which is a key reason we
17+ selected the format.
1218
13- .. code-block :: bash
19+ Due to technical limitations it probably also accepts some files that are
20+ not valid TOML files; bugs of this nature are subject to change (i.e., be
21+ fixed) without the usual deprecation period for incompatible changes.
1422
15- KEY1=" value1"
16- # Comment
17- KEY2=" value2\ncontains a newline"
23+ File format example:
1824
19- [SECTION] # Only values in the "root table" are parsed
20- SECTION_VALUE = ... # so this value cannot be seen by getenv
25+ .. code-block ::
26+
27+ str_key="Hello world" # with trailing comment
28+ int_key = 7
29+ unicode_key="👨"
30+ unicode_key2="\\U0001f468" # same as above
31+ escape_codes="supported, including \\r\\n\\"\\\\"
32+ # comment
33+ [subtable]
34+ subvalue="cannot retrieve this using _environ or getenv"
2135
22- CircuitPython uses the ``settings.toml `` at the drive root (no folder) as the environment.
23- User code can access the values from the file using `os.getenv() `. It is
24- recommended to save any values used repeatedly in a variable because `os.getenv() `
25- will parse the ``settings.toml `` file contents on every access.
2636
2737 Details of the toml language subset
2838-----------------------------------
@@ -36,6 +46,8 @@ Details of the toml language subset
3646* Duplicate keys are not diagnosed.
3747* Comments are supported
3848* Only values from the "root table" can be retrieved
49+ * due to technical limitations, the content of multi-line
50+ strings can erroneously be parsed as a value.
3951
4052CircuitPython behavior
4153----------------------
0 commit comments