Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1 | :mod:`base64` --- Base16, Base32, Base64, Base85 Data Encodings |
| 2 | =============================================================== |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 3 | |
| 4 | .. module:: base64 |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 5 | :synopsis: RFC 3548: Base16, Base32, Base64 Data Encodings; |
| 6 | Base85 and Ascii85 |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 7 | |
| 8 | |
| 9 | .. index:: |
| 10 | pair: base64; encoding |
| 11 | single: MIME; base64 encoding |
| 12 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 13 | This module provides functions for encoding binary data to printable |
| 14 | ASCII characters and decoding such encodings back to binary data. |
| 15 | It provides encoding and decoding functions for the encodings specified in |
Serhiy Storchaka | 56a6d85 | 2014-12-01 18:28:43 +0200 | [diff] [blame] | 16 | :rfc:`3548`, which defines the Base16, Base32, and Base64 algorithms, |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 17 | and for the de-facto standard Ascii85 and Base85 encodings. |
| 18 | |
| 19 | The :rfc:`3548` encodings are suitable for encoding binary data so that it can |
R. David Murray | 7cefc30 | 2010-10-17 23:12:16 +0000 | [diff] [blame] | 20 | safely sent by email, used as parts of URLs, or included as part of an HTTP |
| 21 | POST request. The encoding algorithm is not the same as the |
| 22 | :program:`uuencode` program. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 23 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 24 | There are two interfaces provided by this module. The modern interface |
| 25 | supports encoding :term:`bytes-like objects <bytes-like object>` to ASCII |
| 26 | :class:`bytes`, and decoding :term:`bytes-like objects <bytes-like object>` or |
| 27 | strings containing ASCII to :class:`bytes`. All three :rfc:`3548` defined |
| 28 | alphabets (normal, URL-safe, and filesystem-safe) are supported. |
| 29 | |
| 30 | The legacy interface does not support decoding from strings, but it does |
| 31 | provide functions for encoding and decoding to and from :term:`file objects |
| 32 | <file object>`. It only supports the Base64 standard alphabet, and it adds |
| 33 | newlines every 76 characters as per :rfc:`2045`. Note that if you are looking |
| 34 | for :rfc:`2045` support you probably want to be looking at the :mod:`email` |
| 35 | package instead. |
| 36 | |
Antoine Pitrou | ea6b4d5 | 2012-02-20 19:30:23 +0100 | [diff] [blame] | 37 | |
| 38 | .. versionchanged:: 3.3 |
| 39 | ASCII-only Unicode strings are now accepted by the decoding functions of |
| 40 | the modern interface. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 41 | |
Nick Coghlan | fdf239a | 2013-10-03 00:43:22 +1000 | [diff] [blame] | 42 | .. versionchanged:: 3.4 |
| 43 | Any :term:`bytes-like object`\ s are now accepted by all |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 44 | encoding and decoding functions in this module. Ascii85/Base85 support added. |
Nick Coghlan | fdf239a | 2013-10-03 00:43:22 +1000 | [diff] [blame] | 45 | |
Georg Brandl | e6bcc91 | 2008-05-12 18:05:20 +0000 | [diff] [blame] | 46 | The modern interface provides: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 47 | |
Georg Brandl | b868a66 | 2009-04-02 02:56:10 +0000 | [diff] [blame] | 48 | .. function:: b64encode(s, altchars=None) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 49 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 50 | Encode the :term:`bytes-like object` *s* using Base64 and return the encoded |
| 51 | :class:`bytes`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 52 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 53 | Optional *altchars* must be a :term:`bytes-like object` of at least |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 54 | length 2 (additional characters are ignored) which specifies an alternative |
| 55 | alphabet for the ``+`` and ``/`` characters. This allows an application to e.g. |
| 56 | generate URL or filesystem safe Base64 strings. The default is ``None``, for |
| 57 | which the standard Base64 alphabet is used. |
| 58 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 59 | |
R. David Murray | 6495136 | 2010-11-11 20:09:20 +0000 | [diff] [blame] | 60 | .. function:: b64decode(s, altchars=None, validate=False) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 61 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 62 | Decode the Base64 encoded :term:`bytes-like object` or ASCII string |
| 63 | *s* and return the decoded :class:`bytes`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 64 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 65 | Optional *altchars* must be a :term:`bytes-like object` or ASCII string of |
R. David Murray | 7cefc30 | 2010-10-17 23:12:16 +0000 | [diff] [blame] | 66 | at least length 2 (additional characters are ignored) which specifies the |
| 67 | alternative alphabet used instead of the ``+`` and ``/`` characters. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 68 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 69 | A :exc:`binascii.Error` exception is raised |
Éric Araujo | 941afed | 2011-09-01 02:47:34 +0200 | [diff] [blame] | 70 | if *s* is incorrectly padded. |
R. David Murray | 6495136 | 2010-11-11 20:09:20 +0000 | [diff] [blame] | 71 | |
| 72 | If *validate* is ``False`` (the default), non-base64-alphabet characters are |
| 73 | discarded prior to the padding check. If *validate* is ``True``, |
| 74 | non-base64-alphabet characters in the input result in a |
| 75 | :exc:`binascii.Error`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 76 | |
| 77 | |
| 78 | .. function:: standard_b64encode(s) |
| 79 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 80 | Encode :term:`bytes-like object` *s* using the standard Base64 alphabet |
| 81 | and return the encoded :class:`bytes`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 82 | |
| 83 | |
| 84 | .. function:: standard_b64decode(s) |
| 85 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 86 | Decode :term:`bytes-like object` or ASCII string *s* using the standard |
| 87 | Base64 alphabet and return the decoded :class:`bytes`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 88 | |
| 89 | |
| 90 | .. function:: urlsafe_b64encode(s) |
| 91 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 92 | Encode :term:`bytes-like object` *s* using a URL-safe alphabet, which |
| 93 | substitutes ``-`` instead of ``+`` and ``_`` instead of ``/`` in the |
| 94 | standard Base64 alphabet, and return the encoded :class:`bytes`. The result |
Benjamin Peterson | d75fcb4 | 2009-02-19 04:22:03 +0000 | [diff] [blame] | 95 | can still contain ``=``. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 96 | |
| 97 | |
| 98 | .. function:: urlsafe_b64decode(s) |
| 99 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 100 | Decode :term:`bytes-like object` or ASCII string *s* using a URL-safe |
| 101 | alphabet, which substitutes ``-`` instead of ``+`` and ``_`` instead of |
| 102 | ``/`` in the standard Base64 alphabet, and return the decoded |
| 103 | :class:`bytes`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 104 | |
| 105 | |
| 106 | .. function:: b32encode(s) |
| 107 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 108 | Encode the :term:`bytes-like object` *s* using Base32 and return the |
| 109 | encoded :class:`bytes`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 110 | |
| 111 | |
Georg Brandl | b868a66 | 2009-04-02 02:56:10 +0000 | [diff] [blame] | 112 | .. function:: b32decode(s, casefold=False, map01=None) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 113 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 114 | Decode the Base32 encoded :term:`bytes-like object` or ASCII string *s* and |
| 115 | return the decoded :class:`bytes`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 116 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 117 | Optional *casefold* is a flag specifying |
R. David Murray | 7cefc30 | 2010-10-17 23:12:16 +0000 | [diff] [blame] | 118 | whether a lowercase alphabet is acceptable as input. For security purposes, |
| 119 | the default is ``False``. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 120 | |
| 121 | :rfc:`3548` allows for optional mapping of the digit 0 (zero) to the letter O |
| 122 | (oh), and for optional mapping of the digit 1 (one) to either the letter I (eye) |
| 123 | or letter L (el). The optional argument *map01* when not ``None``, specifies |
| 124 | which letter the digit 1 should be mapped to (when *map01* is not ``None``, the |
| 125 | digit 0 is always mapped to the letter O). For security purposes the default is |
| 126 | ``None``, so that 0 and 1 are not allowed in the input. |
| 127 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 128 | A :exc:`binascii.Error` is raised if *s* is |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 129 | incorrectly padded or if there are non-alphabet characters present in the |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 130 | input. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 131 | |
| 132 | |
| 133 | .. function:: b16encode(s) |
| 134 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 135 | Encode the :term:`bytes-like object` *s* using Base16 and return the |
| 136 | encoded :class:`bytes`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 137 | |
| 138 | |
Georg Brandl | b868a66 | 2009-04-02 02:56:10 +0000 | [diff] [blame] | 139 | .. function:: b16decode(s, casefold=False) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 140 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 141 | Decode the Base16 encoded :term:`bytes-like object` or ASCII string *s* and |
| 142 | return the decoded :class:`bytes`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 143 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 144 | Optional *casefold* is a flag specifying whether a |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 145 | lowercase alphabet is acceptable as input. For security purposes, the default |
| 146 | is ``False``. |
| 147 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 148 | A :exc:`TypeError` is raised if *s* is |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 149 | incorrectly padded or if there are non-alphabet characters present in the |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 150 | input. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 151 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 152 | |
Antoine Pitrou | 6dd0d46 | 2013-11-17 23:52:25 +0100 | [diff] [blame] | 153 | .. function:: a85encode(s, *, foldspaces=False, wrapcol=0, pad=False, adobe=False) |
| 154 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 155 | Encode the :term:`bytes-like object` *s* using Ascii85 and return the |
| 156 | encoded :class:`bytes`. |
Antoine Pitrou | 6dd0d46 | 2013-11-17 23:52:25 +0100 | [diff] [blame] | 157 | |
| 158 | *foldspaces* is an optional flag that uses the special short sequence 'y' |
| 159 | instead of 4 consecutive spaces (ASCII 0x20) as supported by 'btoa'. This |
| 160 | feature is not supported by the "standard" Ascii85 encoding. |
| 161 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 162 | *wrapcol* controls whether the output should have newline (``b'\n'``) |
Antoine Pitrou | 6dd0d46 | 2013-11-17 23:52:25 +0100 | [diff] [blame] | 163 | characters added to it. If this is non-zero, each output line will be |
| 164 | at most this many characters long. |
| 165 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 166 | *pad* controls whether the input is padded to a multiple of 4 |
Antoine Pitrou | 6dd0d46 | 2013-11-17 23:52:25 +0100 | [diff] [blame] | 167 | before encoding. Note that the ``btoa`` implementation always pads. |
| 168 | |
| 169 | *adobe* controls whether the encoded byte sequence is framed with ``<~`` |
| 170 | and ``~>``, which is used by the Adobe implementation. |
| 171 | |
| 172 | .. versionadded:: 3.4 |
| 173 | |
| 174 | |
Serhiy Storchaka | bf7b9ed | 2015-11-23 16:43:05 +0200 | [diff] [blame] | 175 | .. function:: a85decode(s, *, foldspaces=False, adobe=False, ignorechars=b' \\t\\n\\r\\v') |
Antoine Pitrou | 6dd0d46 | 2013-11-17 23:52:25 +0100 | [diff] [blame] | 176 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 177 | Decode the Ascii85 encoded :term:`bytes-like object` or ASCII string *s* and |
| 178 | return the decoded :class:`bytes`. |
Antoine Pitrou | 6dd0d46 | 2013-11-17 23:52:25 +0100 | [diff] [blame] | 179 | |
| 180 | *foldspaces* is a flag that specifies whether the 'y' short sequence |
| 181 | should be accepted as shorthand for 4 consecutive spaces (ASCII 0x20). |
| 182 | This feature is not supported by the "standard" Ascii85 encoding. |
| 183 | |
| 184 | *adobe* controls whether the input sequence is in Adobe Ascii85 format |
| 185 | (i.e. is framed with <~ and ~>). |
| 186 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 187 | *ignorechars* should be a :term:`bytes-like object` or ASCII string |
| 188 | containing characters to ignore |
Antoine Pitrou | 6dd0d46 | 2013-11-17 23:52:25 +0100 | [diff] [blame] | 189 | from the input. This should only contain whitespace characters, and by |
| 190 | default contains all whitespace characters in ASCII. |
| 191 | |
| 192 | .. versionadded:: 3.4 |
| 193 | |
| 194 | |
| 195 | .. function:: b85encode(s, pad=False) |
| 196 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 197 | Encode the :term:`bytes-like object` *s* using base85 (as used in e.g. |
| 198 | git-style binary diffs) and return the encoded :class:`bytes`. |
Antoine Pitrou | 6dd0d46 | 2013-11-17 23:52:25 +0100 | [diff] [blame] | 199 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 200 | If *pad* is true, the input is padded with ``b'\0'`` so its length is a |
| 201 | multiple of 4 bytes before encoding. |
Antoine Pitrou | 6dd0d46 | 2013-11-17 23:52:25 +0100 | [diff] [blame] | 202 | |
| 203 | .. versionadded:: 3.4 |
| 204 | |
| 205 | |
| 206 | .. function:: b85decode(b) |
| 207 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 208 | Decode the base85-encoded :term:`bytes-like object` or ASCII string *b* and |
| 209 | return the decoded :class:`bytes`. Padding is implicitly removed, if |
Antoine Pitrou | 6dd0d46 | 2013-11-17 23:52:25 +0100 | [diff] [blame] | 210 | necessary. |
| 211 | |
| 212 | .. versionadded:: 3.4 |
| 213 | |
| 214 | |
| 215 | .. note:: |
| 216 | Both Base85 and Ascii85 have an expansion factor of 5 to 4 (5 Base85 or |
| 217 | Ascii85 characters can encode 4 binary bytes), while the better-known |
| 218 | Base64 has an expansion factor of 6 to 4. They are therefore more |
| 219 | efficient when space expensive. They differ by details such as the |
| 220 | character map used for encoding. |
| 221 | |
| 222 | |
Georg Brandl | b54d801 | 2009-06-04 09:11:51 +0000 | [diff] [blame] | 223 | The legacy interface: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 224 | |
| 225 | .. function:: decode(input, output) |
| 226 | |
Georg Brandl | b54d801 | 2009-06-04 09:11:51 +0000 | [diff] [blame] | 227 | Decode the contents of the binary *input* file and write the resulting binary |
Antoine Pitrou | 11cb961 | 2010-09-15 11:11:28 +0000 | [diff] [blame] | 228 | data to the *output* file. *input* and *output* must be :term:`file objects |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 229 | <file object>`. *input* will be read until ``input.readline()`` returns an |
| 230 | empty bytes object. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 231 | |
| 232 | |
Georg Brandl | b54d801 | 2009-06-04 09:11:51 +0000 | [diff] [blame] | 233 | .. function:: decodebytes(s) |
| 234 | decodestring(s) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 235 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 236 | Decode the :term:`bytes-like object` *s*, which must contain one or more |
| 237 | lines of base64 encoded data, and return the decoded :class:`bytes`. |
Georg Brandl | b54d801 | 2009-06-04 09:11:51 +0000 | [diff] [blame] | 238 | ``decodestring`` is a deprecated alias. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 239 | |
R David Murray | 75fd225 | 2012-08-17 20:55:21 -0400 | [diff] [blame] | 240 | .. versionadded:: 3.1 |
| 241 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 242 | |
| 243 | .. function:: encode(input, output) |
| 244 | |
Georg Brandl | b54d801 | 2009-06-04 09:11:51 +0000 | [diff] [blame] | 245 | Encode the contents of the binary *input* file and write the resulting base64 |
Antoine Pitrou | 11cb961 | 2010-09-15 11:11:28 +0000 | [diff] [blame] | 246 | encoded data to the *output* file. *input* and *output* must be :term:`file |
| 247 | objects <file object>`. *input* will be read until ``input.read()`` returns |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 248 | an empty bytes object. :func:`encode` inserts a newline character (``b'\n'``) |
| 249 | after every 76 bytes of the output, as well as ensuring that the output |
| 250 | always ends with a newline, as per :rfc:`2045` (MIME). |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 251 | |
| 252 | |
Georg Brandl | b54d801 | 2009-06-04 09:11:51 +0000 | [diff] [blame] | 253 | .. function:: encodebytes(s) |
| 254 | encodestring(s) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 255 | |
R David Murray | a198645 | 2015-12-23 21:17:17 -0500 | [diff] [blame] | 256 | Encode the :term:`bytes-like object` *s*, which can contain arbitrary binary |
| 257 | data, and return :class:`bytes` containing the base64-encoded data, with newlines |
| 258 | (``b'\n'``) inserted after every 76 bytes of output, and ensuring that |
| 259 | there is a trailing newline, as per :rfc:`2045` (MIME). |
| 260 | |
Georg Brandl | b54d801 | 2009-06-04 09:11:51 +0000 | [diff] [blame] | 261 | ``encodestring`` is a deprecated alias. |
| 262 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 263 | |
Christian Heimes | fe337bf | 2008-03-23 21:54:12 +0000 | [diff] [blame] | 264 | An example usage of the module: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 265 | |
| 266 | >>> import base64 |
Georg Brandl | 134c35b | 2010-10-17 11:36:28 +0000 | [diff] [blame] | 267 | >>> encoded = base64.b64encode(b'data to be encoded') |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 268 | >>> encoded |
Georg Brandl | 38d54f7 | 2009-01-18 10:43:58 +0000 | [diff] [blame] | 269 | b'ZGF0YSB0byBiZSBlbmNvZGVk' |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 270 | >>> data = base64.b64decode(encoded) |
| 271 | >>> data |
Georg Brandl | 134c35b | 2010-10-17 11:36:28 +0000 | [diff] [blame] | 272 | b'data to be encoded' |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 273 | |
| 274 | |
| 275 | .. seealso:: |
| 276 | |
| 277 | Module :mod:`binascii` |
| 278 | Support module containing ASCII-to-binary and binary-to-ASCII conversions. |
| 279 | |
| 280 | :rfc:`1521` - MIME (Multipurpose Internet Mail Extensions) Part One: Mechanisms for Specifying and Describing the Format of Internet Message Bodies |
| 281 | Section 5.2, "Base64 Content-Transfer-Encoding," provides the definition of the |
| 282 | base64 encoding. |
| 283 | |