PEP 741: Python Configuration C API (second version)

It’s now mostly optional, only the 2 “Locale” functions need it. If you avoid these functions, the preconfiguration is implicit and only done when Python is initialized at once by Py_InitializeFromInitConfig().

Py_PreInitializeFromInitConfig() must be called before you can call PyInitConfig_SetStrLocale(). Py_PreInitializeFromInitConfig() is responsible to configure the LC_CTYPE locale if you use PyInitConfig_CreatePython(). If you use PyInitConfig_CreateIsolated(), the LC_CTYPE locale is left unchanged: "configure_locale" option is 0 by default in the “isolated” configuration.

I don’t think so. The current implementation cannot set temporarily the LC_CTYPE locale just during a PyInitConfig_SetStrLocale() call and then restore the locale. It would lead to mojibake and other encoding issues. This code is complicated and fragile. Just use an isolate configuration to leave LC_CTYPE unchanged.

PEP 587 added the “Python Configuration” since there are use cases to write a “custom” Python which behaves like the regular Python, but with a different default configuration.

This feature was asked by @pitrou:


Oh sure, I will clarify these points in the doc in my next PEP update.

Some PEPs now have a header saying that it’s a “historical document” and that the implementation is now the reference. I added the list since it’s uneasy to parse PyConfig and PyPreConfig members from the documentation, and the format is different (PEP 741 uses strings).

Hum. The function made more sense in the first version of the PEP when PyInitConfig contained an “exit code”. I will remove the function, you can just use the other functions:

printf("ERROR: %s\n", PyInitConfig_GetError(config));
PyInitConfig_Free(config);
exit(1);