API Reference¶
Main API Reference¶
-
pybase64.
b64encode
(s, altchars=None)[source]¶ Encode bytes using the standard Base64 alphabet.
Argument
s
is a bytes-like object to encode.Optional
altchars
must be a byte string of length 2 which specifies an alternative alphabet for the ‘+’ and ‘/’ characters. This allows an application to e.g. generate url or filesystem safe Base64 strings.The result is returned as a
bytes
object.
-
pybase64.
b64encode_as_string
(s, altchars=None)[source]¶ Encode bytes using the standard Base64 alphabet.
Argument
s
is a bytes-like object to encode.Optional
altchars
must be a byte string of length 2 which specifies an alternative alphabet for the ‘+’ and ‘/’ characters. This allows an application to e.g. generate url or filesystem safe Base64 strings.The result is returned as a
str
object.
-
pybase64.
b64decode
(s, altchars=None, validate=False)[source]¶ Decode bytes encoded with the standard Base64 alphabet.
Argument
s
is a bytes-like object or ASCII string to decode.Optional
altchars
must be a bytes-like object or ASCII string of length 2 which specifies the alternative alphabet used instead of the ‘+’ and ‘/’ characters.If
validate
isFalse
(the default), characters that are neither in the normal base-64 alphabet nor the alternative alphabet are discarded prior to the padding check. Ifvalidate
isTrue
, these non-alphabet characters in the input result in abinascii.Error
.The result is returned as a
bytes
object.A
binascii.Error
is raised ifs
is incorrectly padded.
-
pybase64.
b64decode_as_bytearray
(s, altchars=None, validate=False)[source]¶ Decode bytes encoded with the standard Base64 alphabet.
Argument
s
is a bytes-like object or ASCII string to decode.Optional
altchars
must be a bytes-like object or ASCII string of length 2 which specifies the alternative alphabet used instead of the ‘+’ and ‘/’ characters.If
validate
isFalse
(the default), characters that are neither in the normal base-64 alphabet nor the alternative alphabet are discarded prior to the padding check. Ifvalidate
isTrue
, these non-alphabet characters in the input result in abinascii.Error
.The result is returned as a
bytearray
object.A
binascii.Error
is raised ifs
is incorrectly padded.
Helpers API Reference¶
-
pybase64.
standard_b64encode
(s)[source]¶ Encode bytes using the standard Base64 alphabet.
Argument
s
is a bytes-like object to encode.The result is returned as a
bytes
object.
-
pybase64.
standard_b64decode
(s)[source]¶ Decode bytes encoded with the standard Base64 alphabet.
Argument
s
is a bytes-like object or ASCII string to decode.The result is returned as a
bytes
object.A
binascii.Error
is raised if the input is incorrectly padded.Characters that are not in the standard alphabet are discarded prior to the padding check.
-
pybase64.
urlsafe_b64encode
(s)[source]¶ Encode bytes using the URL- and filesystem-safe Base64 alphabet.
Argument
s
is a bytes-like object to encode.The result is returned as a
bytes
object.The alphabet uses ‘-‘ instead of ‘+’ and ‘_’ instead of ‘/’.
-
pybase64.
urlsafe_b64decode
(s)[source]¶ Decode bytes using the URL- and filesystem-safe Base64 alphabet.
Argument
s
is a bytes-like object or ASCII string to decode.The result is returned as a
bytes
object.A
binascii.Error
is raised if the input is incorrectly padded.Characters that are not in the URL-safe base-64 alphabet, and are not a plus ‘+’ or slash ‘/’, are discarded prior to the padding check.
The alphabet uses ‘-‘ instead of ‘+’ and ‘_’ instead of ‘/’.
Legacy API Reference¶
-
pybase64.
encodebytes
(s)[source]¶ Encode bytes into a bytes object with newlines (b’ ‘) inserted after every 76 bytes of output, and ensuring that there is a trailing newline, as per RFC 2045 (MIME).
Argument
s
is a bytes-like object to encode.The result is returned as a
bytes
object.