---
title: Configure a notification listener using the Python SDK
slug: feature-experimentation/docs/set-up-notification-listener-python
docTags: 
createdAt: 2026-08-05T20:39:52.000Z
---

Notification listeners trigger a callback function that you define when certain actions are triggered in the SDK.

The most common use case is to send a stream of all feature flag decisions to an analytics provider or to an internal data warehouse to join it with other data that you have about your users.

## Notification listener types

For information about notification listener types and use cases, see [Notification listeners](docId:0d__cjuKECyJGqgTV0_5e).

For code samples, see the following sections.

## Add and remove all notification listeners

The following example code shows how to add a listener, remove a listener, remove all listeners of a specific type (such as all decision listeners), and remove all listeners.

:::hint{type="info"}
**Note**
The following code examples assume you have already [initialized the Python SDK](docId:3RNo0adSzdB2ndnj5I_WC) and have already created an `optimizely_client` instance.
:::

```python
from optimizely.helpers import enums

# Remove Notification Listener
optimizely_client.notification_center.remove_notification_listener(notification_id)

# Remove all Notification Listeners
optimizely_client.notification_center.clear_all_notification_listeners()

# Remove all Notification Listeners of a certain type
optimizely_client.clear_notification_listeners(enums.NotificationTypes.DECISION)
```

## Configure each type of notification listener

The following example code shows how to configure each type of notification listener.

```python
from optimizely.helpers import enums
#import your third-party analytics integration here

#######################################
# SET UP DECISION NOTIFICATION LISTENER
#######################################

def on_decision(decision_type, user_id, attributes, decision_info):
    # Add a DECISION Notification Listener for type FLAG
    if decision_type == 'flag':
        # Access information about feature flag, for example, key and enabled status
        print(decision_info.get('flag_key'))
        print(decision_info.get('enabled'))
        print(decision_info.get('decision_event_dispatched'))      
        #Send data to analytics provider here
  
notification_id = optimizely_client.notification_center.add_notification_listener(
enums.NotificationTypes.DECISION, on_decision)


#######################################
# SET UP LOG EVENT NOTIFICATION LISTENER
#######################################

def on_log_event(logEvent): 
    #process the logEvent object here (send to analytics provider, audit/inspect data)

optimizely_client.notification_center.add_notification_listener(enums.NotificationTypes.LOG_EVENT, on_log_event)

#######################################
# SET UP OPTIMIZELY CONFIG NOTIFICATION LISTENER
#######################################

# listen to OPTIMIZELY_CONFIG_UPDATE to get updated data
# You will get notifications whenever the datafile is updated except for SDK initialization
def on_config_update_listener(*args):
    config = optimizely_client.get_optimizely_config()

optimizely_client.notification_center.add_notification_listener(
    enums.NotificationTypes.OPTIMIZELY_CONFIG_UPDATE, on_config_update_listener)

#######################################
# SET UP TRACK LISTENER
#######################################

def on_track(event):    
    #process the event here (send to analytics provider, audit/inspect data)
  
optimizely_client.notification_center.add_notification_listener(
    enums.NotificationTypes.TRACK, on_track)
```
