Unicode2LaTeX is a tiny Julia library for mapping Unicode characters to their corresponding LaTeX-internal form. While modern TeX engines have Unicode support, passing pure ASCII data is a safer option when programmatically generating content to be consumed by a TeX engine not under your control.
Simply use the Julia package manager:
Unicode2LaTeX exports a single function that maps strings and characters to their corresponding LaTeX-internal form:
unicode2latex('ö') # => "\\\"o"
unicode2latex("Kurt Gödel") # => "Kurt G\\\"odel"
Do note that ASCII characters are left in place, as TeX already knows how to interpret them.
To produce this library it was necessary to go deep down a rabbit hole of LaTeX internals. If you also want to find out what lurks in the depths of LaTeX input encoding and font output encoding, you may find the following documents useful: