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 is False (the default), characters that are neither in the normal base-64 alphabet nor the alternative alphabet are discarded prior to the padding check. If validate is True, these non-alphabet characters in the input result in a binascii.Error.

The result is returned as a bytes object.

A binascii.Error is raised if s 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 is False (the default), characters that are neither in the normal base-64 alphabet nor the alternative alphabet are discarded prior to the padding check. If validate is True, these non-alphabet characters in the input result in a binascii.Error.

The result is returned as a bytearray object.

A binascii.Error is raised if s 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 ‘/’.

Legacy API Reference

pybase64.encodebytes(s: Any) bytes[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.

Information API Reference

pybase64.get_version() str[source]

Returns pybase64 version as a str object.

The result reports if the C extension is used or not. e.g. 1.0.0 (C extension active - AVX2)

pybase64.get_license_text() str[source]

Returns pybase64 license information as a str object.

The result includes libbase64 license information as well.