Repository navigation
Support multiline output in binascii.b2a_base64() and base64.b64encode() #143214
Description
Activity
- addedtype-featureA feature request or enhancementA feature request or enhancementstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory3.15bugs and security fixesbugs and security fixes
on Dec 27, 2025 Usually I like parameters with short names because I don't need to wrap lines if I exceed the max line length. Ideally, I would have an explanatory name like "max_line_length", but I think
wrapcolormaxcolsis good. Note that the Unixbase64util uses--wrap=COLSfor wrapping the output whilexxduses-c colsfor wrapping. So including the notion of a "colunn" instead of of line/width seems better to me. Thus, I'm inclined to "colwrap=..." (instead of wrapcol), then "maxcols", and "width" for parity with textwrap (which may also be a strong argument for).This is similar to gh-141966;
wrapcolworks as a name for me. Happy for this issue to implement/ship. Ideally this should be usable for the cases inbase64,email.contentmanager,imaplib, andplistlib.Oh, I searched for base64 issues, but missed your issue at the top of the list due to my sight condition.
Yes, #143216 utilizes the new argument in all these modules.
Reacted by Cody Maloney- marked Add bytes_per_line parameter to binascii.b2a_base64 #141966 as a duplicate of this issue
on Dec 27, 2025 Oh, it is
binascii.b2a_hex()that have abytes_per_sepparameter with weird semantic. Anyway, it is not usable for Base 64 and other encodings which encode a byte in non-integer number of characters. Is is also not usable for Ascii 85 with variable characters-per-byte ratio. Control the number of characters per line in the output is more practical.Reacted by Cody Maloney- added a commit that references this issue
on Jan 14, 2026
Feature or enhancement
According to RFC 4648, section 3.1:
But many specifications use Base 64 separated on lines of fixed length. The stdlib code contains multiple functions that take the Base 64 data and split it on multiple lines. It is worth to add a special support of this in the base functions that encode to Base 64 -- to improve maintenability (there is a known bug in
email.base64mime.body_encode()), convenience and performance.I choose name
wrapcolfor the parameter because it is already used inbase64.a85encode(). Other (mostly private) functions that implement the Base 64 wrapping use different names:maxlinelen,maxlen,max_line_length. PR #102753 propose namewidthforbinascii.b2a_ascii85()(it is also used intextwrap). So there is no consistency or single dominant option, but I am open for suggestions.Linked PRs