API Reference¶
Main API Reference¶
- pybase64.b64encode(s: Any, altchars: Optional[Any] = None) bytes [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: Any, altchars: Optional[Any] = None) str [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: Any, altchars: Optional[Any] = None, validate: bool = False) bytes [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: Any, altchars: Optional[Any] = None, validate: bool = False) bytearray [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: Any) bytes [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: Any) bytes [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: Any) bytes [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: Any) bytes [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 ‘/’.