API Reference¶
Main API Reference¶
- pybase64.b64encode(s: Buffer, altchars: str | Buffer | None = None, *, padded: bool = True, wrapcol: int = 0) bytes[source]¶
Encode bytes using the standard Base64 alphabet.
Argument
sis a bytes-like object to encode.Optional
altcharsmust 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.Optional
paddedspecifies whether to pad the encoded data with the ‘=’ character to a size multiple of 4.Optional
wrapcolspecifies after how many characters the output should be split with a newline character (b'\n'). The value is rounded down to the nearest multiple of 4. Ifwrapcolis 0 (the default), no newlines are added.The result is returned as a
bytesobject.
- pybase64.b64encode_as_string(s: Buffer, altchars: str | Buffer | None = None, *, padded: bool = True, wrapcol: int = 0) str[source]¶
Encode bytes using the standard Base64 alphabet.
Argument
sis a bytes-like object to encode.Optional
altcharsmust 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.Optional
paddedspecifies whether to pad the encoded data with the ‘=’ character to a size multiple of 4.Optional
wrapcolspecifies after how many characters the output should be split with a newline character ('\n'). The value is rounded down to the nearest multiple of 4. Ifwrapcolis 0 (the default), no newlines are added.The result is returned as a
strobject.
- pybase64.b64decode(s: str | Buffer, altchars: str | Buffer | None = None, validate: bool | Literal[_Unspecified.UNSPECIFIED] = _Unspecified.UNSPECIFIED, *, padded: bool = True, ignorechars: Buffer | Literal[_Unspecified.UNSPECIFIED] = _Unspecified.UNSPECIFIED, canonical: bool = False) bytes[source]¶
Decode bytes encoded with the standard Base64 alphabet.
Argument
sis a bytes-like object or ASCII string to decode.Optional
altcharsmust be a bytes-like object or ASCII string of length 2 which specifies the alternative alphabet used instead of the ‘+’ and ‘/’ characters.If
ignorecharsis specified, it should be a bytes-like object containing characters to ignore from the input whenvalidateisTrue. Ifignorecharscontains the pad character'=', the pad characters presented before the end of the encoded data and the excess pad characters will be ignored. The default value ofvalidateisTrueifignorecharsis specified,Falseotherwise.If
validateisFalse, characters that are neither in the normal base-64 alphabet nor the alternative alphabet are discarded prior to the padding check. IfvalidateisTrue, these non-alphabet characters in the input result in abinascii.Error.If
paddedisFalse, padding in the input is not required or not allowed whenvalidateisTrueandignorecharsdoes not contain the pad character'='.If
canonicalisTrue, non-zero padding bits are rejected.The result is returned as a
bytesobject.A
binascii.Erroris raised ifsis incorrectly padded.
- pybase64.b64decode_as_bytearray(s: str | Buffer, altchars: str | Buffer | None = None, validate: bool | Literal[_Unspecified.UNSPECIFIED] = _Unspecified.UNSPECIFIED, *, padded: bool = True, ignorechars: Buffer | Literal[_Unspecified.UNSPECIFIED] = _Unspecified.UNSPECIFIED, canonical: bool = False) bytearray[source]¶
Decode bytes encoded with the standard Base64 alphabet.
Argument
sis a bytes-like object or ASCII string to decode.Optional
altcharsmust be a bytes-like object or ASCII string of length 2 which specifies the alternative alphabet used instead of the ‘+’ and ‘/’ characters.If
ignorecharsis specified, it should be a bytes-like object containing characters to ignore from the input whenvalidateisTrue. Ifignorecharscontains the pad character'=', the pad characters presented before the end of the encoded data and the excess pad characters will be ignored. The default value ofvalidateisTrueifignorecharsis specified,Falseotherwise.If
validateisFalse, characters that are neither in the normal base-64 alphabet nor the alternative alphabet are discarded prior to the padding check. IfvalidateisTrue, these non-alphabet characters in the input result in abinascii.Error.If
paddedisFalse, padding in the input is not required or not allowed whenvalidateisTrueandignorecharsdoes not contain the pad character'='.If
canonicalisTrue, non-zero padding bits are rejected.The result is returned as a
bytearrayobject.A
binascii.Erroris raised ifsis incorrectly padded.
Helpers API Reference¶
- pybase64.standard_b64encode(s: Buffer) bytes[source]¶
Encode bytes using the standard Base64 alphabet.
Argument
sis a bytes-like object to encode.The result is returned as a
bytesobject.
- pybase64.standard_b64decode(s: str | Buffer) bytes[source]¶
Decode bytes encoded with the standard Base64 alphabet.
Argument
sis a bytes-like object or ASCII string to decode.The result is returned as a
bytesobject.A
binascii.Erroris 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: Buffer, *, padded: bool = True) bytes[source]¶
Encode bytes using the URL- and filesystem-safe Base64 alphabet.
Argument
sis a bytes-like object to encode.The result is returned as a
bytesobject.The alphabet uses ‘-’ instead of ‘+’ and ‘_’ instead of ‘/’.
The result can still contain
=ifpaddedis true (default).
- pybase64.urlsafe_b64decode(s: str | Buffer, *, padded: bool = False) bytes[source]¶
Decode bytes using the URL- and filesystem-safe Base64 alphabet.
Argument
sis a bytes-like object or ASCII string to decode.The result is returned as a
bytesobject.If
paddedisFalse, padding in the input is not required. Otherwise, abinascii.Erroris 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 ‘/’.