This PEP proposes enablingUTF-8 mode by default.
With this change, Python consistently uses UTF-8 for default encoding offiles, stdio, and pipes.
UTF-8 becomes de facto standard text encoding.
Changing the default encoding to UTF-8 makes it easier for Python tointeroperate with them.
Additionally, many Python developers using Unix forget that the defaultencoding is platform dependent.They omit to specifyencoding="utf-8" when they read text files encodedin UTF-8 (e.g. JSON, TOML, Markdown, and Python source files).Inconsistent default encoding causes many bugs.
Python will enable UTF-8 mode by default from Python 3.15.
Users can still disable UTF-8 mode by settingPYTHONUTF8=0 or-Xutf8=0.
locale.getencoding()Since UTF-8 mode affectslocale.getpreferredencoding(False),we need an API to get locale encoding regardless of UTF-8 mode.
locale.getencoding() will be added for this purpose.It returns locale encoding too, but ignores UTF-8 mode.
Whenwarn_default_encoding option is specified,locale.getpreferredencoding() will emitEncodingWarning likeopen() (see alsoPEP 597).
This API was added in Python 3.11.
encoding="locale" optionPEP 597 added theencoding="locale" option to theTextIOWrapper.This option is used to specify the locale encoding explicitly.TextIOWrapper should use locale encoding when the option is specified,regardless of default text encoding.
ButTextIOWrapper uses"UTF-8" in UTF-8 mode even ifencoding="locale" is specified for now.This behavior is inconsistent with thePEP 597 motivation.It is because we didn’t expect making UTF-8 mode default when Pythonchanges its default text encoding.
This inconsistency should be fixed before making UTF-8 mode default.TextIOWrapper should use locale encoding whenencoding="locale" ispassed even in UTF-8 mode.
This issue was fixed in Python 3.11.
Most Unix systems use UTF-8 locale and Python enables UTF-8 mode when itslocale is C or POSIX.So this change mostly affects Windows users.
When a Python program depends on the default encoding, this change may causeUnicodeError, mojibake, or even silent data corruption.So this change should be announced loudly.
This is the guideline to fix this backward compatibility issue:
EncodingWarning (PEP 597) to find every places UTF-8 modeaffects.encoding option is omitted, consider usingencoding="utf-8"orencoding="locale".locale.getpreferredencoding() is used, consider using"utf-8" orlocale.getencoding().external_encodingto UTF-8 on Windows in Ruby 3.0 (2020).Both Ruby and Java have an option for backward compatibility.They don’t provide any warning likePEP 597’sEncodingWarningin Python for use of the default encoding.
Deprecating the use of the default encoding is considered.
But there are many cases that the default encoding is used for reading/writingonly ASCII text.Additionally, such warnings are not useful for non-cross platform applicationsrun on Unix.
So forcing users to specify theencoding everywhere is too painful.Emitting a lot ofDeprecationWarning will lead users ignore warnings.
PEP 387 requires adding a warning for backward incompatible changes.But it doesn’t require usingDeprecationWarning.So using optionalEncodingWarning doesn’t violate thePEP 387.
Java also rejected this idea inJEP 400.
PYTHONIOENCODING for PIPEsTo ease backward compatibility issue, usingPYTHONIOENCODING as thedefault encoding of PIPEs in thesubprocess module is considered.
With this idea, users can use legacy encoding forsubprocess.Popen(text=True) even in UTF-8 mode.
But this idea makes “default encoding” complicated.And this idea is also backward incompatible.
So this idea is rejected. Users can disable UTF-8 mode until they replacetext=True withencoding="utf-8" orencoding="locale".
For new users, this change reduces things that need to teach.Users don’t need to learn about text encoding in their first year.They should learn it when they need to use non-UTF-8 text files.
For existing users, see theBackward compatibility section.
This document is placed in the public domain or under theCC0-1.0-Universal license, whichever is more permissive.
Source:https://github.com/python/peps/blob/main/peps/pep-0686.rst
Last modified:2026-01-19 06:31:38 GMT