tomllib entered the standard library in Python 3.11 (October 2022) as a read-only TOML parser. tomllib.load() accepts only a binary file object. Passing a text-mode handle raises TypeError: File must be opened in binary mode, e.g. use open('foo.toml', 'rb').
The rule exists because TOML is defined as UTF-8 and the parser wants to control decoding itself rather than inherit the platform's locale.getpreferredencoding(), which on Windows is still commonly cp1252. Reading a pyproject.toml containing non-ASCII author names in text mode would decode differently per machine.
Use with open(path, "rb") as f: data = tomllib.load(f), or tomllib.loads(text) when you already hold a str. There is no writer: tomllib cannot serialise, so emitting TOML still needs a third-party package such as tomli-w or tomlkit. For libraries supporting 3.10 and earlier, the standard shim is to try importing tomllib and fall back to the tomli package, which has the identical API.