firebase_admin.messaging module

Firebase Cloud Messaging module.

Exceptions

QuotaExceededError

exceptionfirebase_admin.messaging.QuotaExceededError(message,cause=None,http_response=None)

Bases:ResourceExhaustedError

Sending limit exceeded for the message target.

SenderIdMismatchError

exceptionfirebase_admin.messaging.SenderIdMismatchError(message,cause=None,http_response=None)

Bases:PermissionDeniedError

The authenticated sender ID is different from the sender ID for the registration token.

ThirdPartyAuthError

exceptionfirebase_admin.messaging.ThirdPartyAuthError(message,cause=None,http_response=None)

Bases:UnauthenticatedError

APNs certificate or web push auth key was invalid or missing.

UnregisteredError

exceptionfirebase_admin.messaging.UnregisteredError(message,cause=None,http_response=None)

Bases:NotFoundError

App instance was unregistered from FCM.

This usually means that the token used is no longer valid and a new one must be used.

Classes

APNSConfig

classfirebase_admin.messaging.APNSConfig(headers=None,payload=None,fcm_options=None,live_activity_token=None)

Bases:object

APNS-specific options that can be included in a message.

Refer toAPNS Documentation for more information.

Parameters:
  • headers – A dictionary of headers (optional).

  • payload – Amessaging.APNSPayload to be included in the message (optional).

  • fcm_options – Amessaging.APNSFCMOptions instance to be included in the message(optional).

  • live_activity_token – A live activity token string (optional).

APNSFCMOptions

classfirebase_admin.messaging.APNSFCMOptions(analytics_label=None,image=None)

Bases:object

Options for features provided by the FCM SDK for iOS.

Parameters:
  • analytics_label – contains additional options for features provided by the FCM iOS SDK(optional).

  • image – contains the URL of an image that is going to be displayed in a notification(optional).

APNSPayload

classfirebase_admin.messaging.APNSPayload(aps,**kwargs)

Bases:object

Payload of an APNS message.

Parameters:
  • aps – Amessaging.Aps instance to be included in the payload.

  • **kwargs – Arbitrary keyword arguments to be included as custom fields in the payload(optional).

AndroidConfig

classfirebase_admin.messaging.AndroidConfig(collapse_key=None,priority=None,ttl=None,restricted_package_name=None,data=None,notification=None,fcm_options=None,direct_boot_ok=None)

Bases:object

Android-specific options that can be included in a message.

Parameters:
  • collapse_key – Collapse key string for the message (optional). This is an identifier for agroup of messages that can be collapsed, so that only the last message is sent whendelivery can be resumed. A maximum of 4 different collapse keys may be active at agiven time.

  • priority – Priority of the message (optional). Must be one ofhigh ornormal.

  • ttl – The time-to-live duration of the message (optional). This can be specifiedas a numeric seconds value or adatetime.timedelta instance.

  • restricted_package_name – The package name of the application where the registration tokensmust match in order to receive the message (optional).

  • data – A dictionary of data fields (optional). All keys and values in the dictionary must bestrings. When specified, overrides any data fields set viaMessage.data.

  • notification – Amessaging.AndroidNotification to be included in the message (optional).

  • fcm_options – Amessaging.AndroidFCMOptions to be included in the message (optional).

  • direct_boot_ok – A boolean indicating whether messages will be allowed to be delivered tothe app while the device is in direct boot mode (optional).

AndroidFCMOptions

classfirebase_admin.messaging.AndroidFCMOptions(analytics_label=None)

Bases:object

Options for features provided by the FCM SDK for Android.

Parameters:

analytics_label – contains additional options for features provided by the FCM Android SDK(optional).

AndroidNotification

classfirebase_admin.messaging.AndroidNotification(title=None,body=None,icon=None,color=None,sound=None,tag=None,click_action=None,body_loc_key=None,body_loc_args=None,title_loc_key=None,title_loc_args=None,channel_id=None,image=None,ticker=None,sticky=None,event_timestamp=None,local_only=None,priority=None,vibrate_timings_millis=None,default_vibrate_timings=None,default_sound=None,light_settings=None,default_light_settings=None,visibility=None,notification_count=None,proxy=None)

Bases:object

Android-specific notification parameters.

Parameters:
  • title – Title of the notification (optional). If specified, overrides the title set viamessaging.Notification.

  • body – Body of the notification (optional). If specified, overrides the body set viamessaging.Notification.

  • icon – Icon of the notification (optional).

  • color – Color of the notification icon expressed in#rrggbb form (optional).

  • sound – Sound to be played when the device receives the notification (optional). This isusually the file name of the sound resource.

  • tag – Tag of the notification (optional). This is an identifier used to replace existingnotifications in the notification drawer. If not specified, each request creates a newnotification.

  • click_action – The action associated with a user click on the notification (optional). Ifspecified, an activity with a matching intent filter is launched when a user clicks onthe notification.

  • body_loc_key – Key of the body string in the app’s string resources to use to localize thebody text (optional).

  • body_loc_args – A list of resource keys that will be used in place of the format specifiersinbody_loc_key (optional).

  • title_loc_key – Key of the title string in the app’s string resources to use to localize thetitle text (optional).

  • title_loc_args – A list of resource keys that will be used in place of the format specifiersintitle_loc_key (optional).

  • channel_id – channel_id of the notification (optional).

  • image – Image url of the notification (optional).

  • ticker – Sets theticker text, which is sent to accessibility services. Prior to APIlevel 21 (Lollipop), sets the text that is displayed in the status bar when thenotification first arrives (optional).

  • sticky – When set toFalse or unset, the notification is automatically dismissed when theuser clicks it in the panel. When set toTrue, the notification persists even whenthe user clicks it (optional).

  • event_timestamp – For notifications that inform users about events with an absolute timereference, sets the time that the event in the notification occurred as adatetime.datetime instance. If thedatetime.datetime instance is naive, itdefaults to be in the UTC timezone. Notifications in the panel are sorted by this time(optional).

  • local_only – Sets whether or not this notification is relevant only to the current device.Some notifications can be bridged to other devices for remote display, such as a Wear OSwatch. This hint can be set to recommend this notification not be bridged (optional).See Wear OS guides:https://developer.android.com/training/wearables/notifications/bridger#existing-method-of-preventing-bridging

  • priority – Sets the relative priority for this notification. Low-priority notifications maybe hidden from the user in certain situations. Note this priority differs fromAndroidMessagePriority. This priority is processed by the client after the messagehas been delivered. WhereasAndroidMessagePriority is an FCM concept that controlswhen the message is delivered (optional). Must be one ofdefault,min,low,high,max ornormal.

  • vibrate_timings_millis – Sets the vibration pattern to use. Pass in an array of millisecondsto turn the vibrator on or off. The first value indicates the duration to wait beforeturning the vibrator on. The next value indicates the duration to keep the vibrator on.Subsequent values alternate between duration to turn the vibrator off and to turn thevibrator on. Ifvibrate_timings is set anddefault_vibrate_timings is set toTrue, the default value is used instead of the user-specifiedvibrate_timings.

  • default_vibrate_timings – If set toTrue, use the Android framework’s default vibratepattern for the notification (optional). Default values are specified inconfig.xmlhttps://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml.Ifdefault_vibrate_timings is set toTrue andvibrate_timings is also set,the default value is used instead of the user-specifiedvibrate_timings.

  • default_sound – If set toTrue, use the Android framework’s default sound for thenotification (optional). Default values are specified inconfig.xmlhttps://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml

  • light_settings – Settings to control the notification’s LED blinking rate and color if LED isavailable on the device. The total blinking time is controlled by the OS (optional).

  • default_light_settings – If set toTrue, use the Android framework’s default LED lightsettings for the notification. Default values are specified inconfig.xmlhttps://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml.Ifdefault_light_settings is set toTrue andlight_settings is also set, theuser-specifiedlight_settings is used instead of the default value.

  • visibility – Sets the visibility of the notification. Must be eitherprivate,public,orsecret. If unspecified, it remains undefined in the Admin SDK, and defers tothe FCM backend’s default mapping.

  • notification_count – Sets the number of items this notification represents. May be displayedas a badge count for Launchers that support badging. SeeNotificationBadgehttps://developer.android.com/training/notify-user/badges. For example, this might beuseful if you’re using just one notification to represent multiple new messages but youwant the count here to represent the number of total new messages. If zero orunspecified, systems that support badging use the default, which is to increment anumber displayed on the long-press menu each time a new notification arrives.

  • proxy – Sets if the notification may be proxied. Must be one ofallow,deny, orif_priority_lowered. If unspecified, it remains undefined in the Admin SDK, anddefers to the FCM backend’s default mapping.

Aps

classfirebase_admin.messaging.Aps(alert=None,badge=None,sound=None,content_available=None,category=None,thread_id=None,mutable_content=None,custom_data=None)

Bases:object

Aps dictionary to be included in an APNS payload.

Parameters:
  • alert – A string or amessaging.ApsAlert instance (optional).

  • badge – A number representing the badge to be displayed with the message (optional).

  • sound – Name of the sound file to be played with the message or amessaging.CriticalSound instance (optional).

  • content_available – A boolean indicating whether to configure a background updatenotification (optional).

  • category – String identifier representing the message type (optional).

  • thread_id – An app-specific string identifier for grouping messages (optional).

  • mutable_content – A boolean indicating whether to support mutating notifications atthe client using app extensions (optional).

  • custom_data – A dict of custom key-value pairs to be included in the Aps dictionary(optional).

ApsAlert

classfirebase_admin.messaging.ApsAlert(title=None,subtitle=None,body=None,loc_key=None,loc_args=None,title_loc_key=None,title_loc_args=None,action_loc_key=None,launch_image=None,custom_data=None)

Bases:object

An alert that can be included inmessaging.Aps.

Parameters:
  • title – Title of the alert (optional). If specified, overrides the title set viamessaging.Notification.

  • subtitle – Subtitle of the alert (optional).

  • body – Body of the alert (optional). If specified, overrides the body set viamessaging.Notification.

  • loc_key – Key of the body string in the app’s string resources to use to localize thebody text (optional).

  • loc_args – A list of resource keys that will be used in place of the format specifiersinloc_key (optional).

  • title_loc_key – Key of the title string in the app’s string resources to use to localize thetitle text (optional).

  • title_loc_args – A list of resource keys that will be used in place of the format specifiersintitle_loc_key (optional).

  • action_loc_key – Key of the text in the app’s string resources to use to localize theaction button text (optional).

  • launch_image – Image for the notification action (optional).

  • custom_data – A dict of custom key-value pairs to be included in the ApsAlert dictionary(optional)

BatchResponse

classfirebase_admin.messaging.BatchResponse(responses:List[SendResponse])

Bases:object

The response received from a batch request to the FCM API.

propertyfailure_count:int
propertyresponses:List[SendResponse]

A list ofmessaging.SendResponse objects (possibly empty).

propertysuccess_count:int

CriticalSound

classfirebase_admin.messaging.CriticalSound(name,critical=None,volume=None)

Bases:object

Critical alert sound configuration that can be included inmessaging.Aps.

Parameters:
  • name – The name of a sound file in your app’s main bundle or in theLibrary/Soundsfolder of your app’s container directory. Specify the stringdefault to play thesystem sound.

  • critical – Set toTrue to set the critical alert flag on the sound configuration(optional).

  • volume – The volume for the critical alert’s sound. Must be a value between 0.0 (silent)and 1.0 (full volume) (optional).

ErrorInfo

classfirebase_admin.messaging.ErrorInfo(index,reason)

Bases:object

An error encountered when performing a topic management operation.

propertyindex

Index of the registration token to which this error is related to.

propertyreason

String describing the nature of the error.

FCMOptions

classfirebase_admin.messaging.FCMOptions(analytics_label=None)

Bases:object

Options for features provided by SDK.

Parameters:

analytics_label – contains additional options to use across all platforms (optional).

LightSettings

classfirebase_admin.messaging.LightSettings(color,light_on_duration_millis,light_off_duration_millis)

Bases:object

Represents settings to control notification LED that can be included in amessaging.AndroidNotification.

Parameters:
  • color – Sets the color of the LED in#rrggbb or#rrggbbaa format.

  • light_on_duration_millis – Along withlight_off_duration, defines the blink rate of LEDflashes.

  • light_off_duration_millis – Along withlight_on_duration, defines the blink rate of LEDflashes.

Message

classfirebase_admin.messaging.Message(data=None,notification=None,android=None,webpush=None,apns=None,fcm_options=None,token=None,topic=None,condition=None)

Bases:object

A message that can be sent via Firebase Cloud Messaging.

Contains payload information as well as recipient information. In particular, the message mustcontain exactly one of token, topic or condition fields.

Parameters:
  • data – A dictionary of data fields (optional). All keys and values in the dictionary must bestrings.

  • notification – An instance ofmessaging.Notification (optional).

  • android – An instance ofmessaging.AndroidConfig (optional).

  • webpush – An instance ofmessaging.WebpushConfig (optional).

  • apns – An instance ofmessaging.ApnsConfig (optional).

  • fcm_options – An instance ofmessaging.FCMOptions (optional).

  • token – The registration token of the device to which the message should be sent (optional).

  • topic – Name of the FCM topic to which the message should be sent (optional). Topic namemay contain the/topics/ prefix.

  • condition – The FCM condition to which the message should be sent (optional).

MulticastMessage

classfirebase_admin.messaging.MulticastMessage(tokens,data=None,notification=None,android=None,webpush=None,apns=None,fcm_options=None)

Bases:object

A message that can be sent to multiple tokens via Firebase Cloud Messaging.

Parameters:
  • tokens – A list of registration tokens of targeted devices.

  • data – A dictionary of data fields (optional). All keys and values in the dictionary must bestrings.

  • notification – An instance ofmessaging.Notification (optional).

  • android – An instance ofmessaging.AndroidConfig (optional).

  • webpush – An instance ofmessaging.WebpushConfig (optional).

  • apns – An instance ofmessaging.ApnsConfig (optional).

  • fcm_options – An instance ofmessaging.FCMOptions (optional).

Notification

classfirebase_admin.messaging.Notification(title=None,body=None,image=None)

Bases:object

A notification that can be included in a message.

Parameters:
  • title – Title of the notification (optional).

  • body – Body of the notification (optional).

  • image – Image url of the notification (optional)

SendResponse

classfirebase_admin.messaging.SendResponse(resp,exception)

Bases:object

The response received from an individual batched request to the FCM API.

propertyexception

AFirebaseError if an error occurs while sending the message to the FCM service.

propertymessage_id

A message ID string that uniquely identifies the message.

propertysuccess

A boolean indicating if the request was successful.

TopicManagementResponse

classfirebase_admin.messaging.TopicManagementResponse(resp)

Bases:object

The response received from a topic management operation.

propertyerrors

A list ofmessaging.ErrorInfo objects (possibly empty).

propertyfailure_count

Number of tokens that could not be subscribed or unsubscribed due to errors.

propertysuccess_count

Number of tokens that were successfully subscribed or unsubscribed.

WebpushConfig

classfirebase_admin.messaging.WebpushConfig(headers=None,data=None,notification=None,fcm_options=None)

Bases:object

Webpush-specific options that can be included in a message.

Parameters:
  • headers – A dictionary of headers (optional). ReferWebpush Specification for supportedheaders.

  • data – A dictionary of data fields (optional). All keys and values in the dictionary must bestrings. When specified, overrides any data fields set viaMessage.data.

  • notification – Amessaging.WebpushNotification to be included in the message (optional).

  • fcm_options – Amessaging.WebpushFCMOptions instance to be included in the message(optional).

WebpushFCMOptions

classfirebase_admin.messaging.WebpushFCMOptions(link=None)

Bases:object

Options for features provided by the FCM SDK for Web.

Parameters:

link – The link to open when the user clicks on the notification. Must be an HTTPS URL(optional).

WebpushNotification

classfirebase_admin.messaging.WebpushNotification(title=None,body=None,icon=None,actions=None,badge=None,data=None,direction=None,image=None,language=None,renotify=None,require_interaction=None,silent=None,tag=None,timestamp_millis=None,vibrate=None,custom_data=None)

Bases:object

Webpush-specific notification parameters.

Refer to theNotification Reference for more information.

Parameters:
  • title – Title of the notification (optional). If specified, overrides the title set viamessaging.Notification.

  • body – Body of the notification (optional). If specified, overrides the body set viamessaging.Notification.

  • icon – Icon URL of the notification (optional).

  • actions – A list ofmessaging.WebpushNotificationAction instances (optional).

  • badge – URL of the image used to represent the notification when there isnot enough space to display the notification itself (optional).

  • data – Any arbitrary JSON data that should be associated with the notification (optional).

  • direction – The direction in which to display the notification (optional). Must be either‘auto’, ‘ltr’ or ‘rtl’.

  • image – The URL of an image to be displayed in the notification (optional).

  • language – Notification language (optional).

  • renotify – A boolean indicating whether the user should be notified after a newnotification replaces an old one (optional).

  • require_interaction – A boolean indicating whether a notification should remain activeuntil the user clicks or dismisses it, rather than closing automatically (optional).

  • silentTrue to indicate that the notification should be silent (optional).

  • tag – An identifying tag on the notification (optional).

  • timestamp_millis – A timestamp value in milliseconds on the notification (optional).

  • vibrate – A vibration pattern for the device’s vibration hardware to emit when thenotification fires (optional). The pattern is specified as an integer array.

  • custom_data – A dict of custom key-value pairs to be included in the notification(optional)

WebpushNotificationAction

classfirebase_admin.messaging.WebpushNotificationAction(action,title,icon=None)

Bases:object

An action available to the users when the notification is presented.

Parameters:
  • action – Action string.

  • title – Title string.

  • icon – Icon URL for the action (optional).

Functions

send

firebase_admin.messaging.send(message:Message,dry_run:bool=False,app:App|None=None)str

Sends the given message via Firebase Cloud Messaging (FCM).

If thedry_run mode is enabled, the message will not be actually delivered to therecipients. Instead, FCM performs all the usual validations and emulates the send operation.

Parameters:
  • message – An instance ofmessaging.Message.

  • dry_run – A boolean indicating whether to run the operation in dry run mode (optional).

  • app – An App instance (optional).

Returns:

A message ID string that uniquely identifies the sent message.

Return type:

string

Raises:
  • FirebaseError – If an error occurs while sending the message to the FCM service.

  • ValueError – If the input arguments are invalid.

send_each

firebase_admin.messaging.send_each(messages:List[Message],dry_run:bool=False,app:App|None=None)BatchResponse

Sends each message in the given list via Firebase Cloud Messaging.

If thedry_run mode is enabled, the message will not be actually delivered to therecipients. Instead, FCM performs all the usual validations and emulates the send operation.

Parameters:
  • messages – A list ofmessaging.Message instances.

  • dry_run – A boolean indicating whether to run the operation in dry run mode (optional).

  • app – An App instance (optional).

Returns:

Amessaging.BatchResponse instance.

Return type:

BatchResponse

Raises:
  • FirebaseError – If an error occurs while sending the message to the FCM service.

  • ValueError – If the input arguments are invalid.

send_each_async

asyncfirebase_admin.messaging.send_each_async(messages:List[Message],dry_run:bool=False,app:App|None=None)BatchResponse

Sends each message in the given list asynchronously via Firebase Cloud Messaging.

If thedry_run mode is enabled, the message will not be actually delivered to therecipients. Instead, FCM performs all the usual validations and emulates the send operation.

Parameters:
  • messages – A list ofmessaging.Message instances.

  • dry_run – A boolean indicating whether to run the operation in dry run mode (optional).

  • app – An App instance (optional).

Returns:

Amessaging.BatchResponse instance.

Return type:

BatchResponse

Raises:
  • FirebaseError – If an error occurs while sending the message to the FCM service.

  • ValueError – If the input arguments are invalid.

send_each_for_multicast

firebase_admin.messaging.send_each_for_multicast(multicast_message,dry_run=False,app=None)

Sends the given mutlicast message to each token via Firebase Cloud Messaging (FCM).

If thedry_run mode is enabled, the message will not be actually delivered to therecipients. Instead, FCM performs all the usual validations and emulates the send operation.

Parameters:
  • multicast_message – An instance ofmessaging.MulticastMessage.

  • dry_run – A boolean indicating whether to run the operation in dry run mode (optional).

  • app – An App instance (optional).

Returns:

Amessaging.BatchResponse instance.

Return type:

BatchResponse

Raises:
  • FirebaseError – If an error occurs while sending the message to the FCM service.

  • ValueError – If the input arguments are invalid.

send_each_for_multicast_async

asyncfirebase_admin.messaging.send_each_for_multicast_async(multicast_message:MulticastMessage,dry_run:bool=False,app:App|None=None)BatchResponse

Sends the given mutlicast message to each token asynchronously via Firebase Cloud Messaging(FCM).

If thedry_run mode is enabled, the message will not be actually delivered to therecipients. Instead, FCM performs all the usual validations and emulates the send operation.

Parameters:
  • multicast_message – An instance ofmessaging.MulticastMessage.

  • dry_run – A boolean indicating whether to run the operation in dry run mode (optional).

  • app – An App instance (optional).

Returns:

Amessaging.BatchResponse instance.

Return type:

BatchResponse

Raises:
  • FirebaseError – If an error occurs while sending the message to the FCM service.

  • ValueError – If the input arguments are invalid.

subscribe_to_topic

firebase_admin.messaging.subscribe_to_topic(tokens,topic,app=None)

Subscribes a list of registration tokens to an FCM topic.

Parameters:
  • tokens – A non-empty list of device registration tokens. List may not have more than 1000elements.

  • topic – Name of the topic to subscribe to. May contain the/topics/ prefix.

  • app – An App instance (optional).

Returns:

ATopicManagementResponse instance.

Return type:

TopicManagementResponse

Raises:
  • FirebaseError – If an error occurs while communicating with instance ID service.

  • ValueError – If the input arguments are invalid.

unsubscribe_from_topic

firebase_admin.messaging.unsubscribe_from_topic(tokens,topic,app=None)

Unsubscribes a list of registration tokens from an FCM topic.

Parameters:
  • tokens – A non-empty list of device registration tokens. List may not have more than 1000elements.

  • topic – Name of the topic to unsubscribe from. May contain the/topics/ prefix.

  • app – An App instance (optional).

Returns:

ATopicManagementResponse instance.

Return type:

TopicManagementResponse

Raises:
  • FirebaseError – If an error occurs while communicating with instance ID service.

  • ValueError – If the input arguments are invalid.

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 2025-07-17 UTC.