Function: base64.decode

Decodes given Base64-encoded string to bytes.

The carriage return (\r) and newline (\n) characters in the inputare ignored.

Arguments

Arguments
data

string

The input to be decoded.

padding

boolean

Specifies whether the input should be expected to be aligned to a multiple of 4 bytes, using a padding character (default:true).

Returns

The decoded bytes.

Raised exceptions

Exceptions
ValueErrorIf characters outside of the Base64 alphabet are encountered, or ifpadding == true and the input is not aligned to a multiple of 4 bytes.

Examples

For more information, seeReturning bytes.

# Decode Base64-encoded string to bytes, then decode bytes to object-init:assign:-project:'${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}'-subscription:SUBSCRIPTION_ID-pullMessage:# pulls Pub/Sub messagecall:googleapis.pubsub.v1.projects.subscriptions.pullargs:subscription:'${"projects/"+project+"/subscriptions/"+subscription}'body:maxMessages:1result:m-outputMessage:return:'${json.decode(base64.decode(m.receivedMessages[0].message.data))}'

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.