Skip to content

OneSignal#

flet_onesignal.onesignal.OneSignal #

OneSignal integration for Flet applications.

This is the main entry point for the OneSignal SDK. Add it to your page's services list to enable push notifications and in-app messaging.

Example
import flet as ft
import flet_onesignal as fos

async def main(page: ft.Page):
    onesignal = fos.OneSignal(app_id="your-app-id")
    page.services.append(onesignal)  # Use services, NOT overlay!

    # Request notification permission
    granted = await onesignal.notifications.request_permission()

    # Login a user
    await onesignal.login("user-123")

ft.run(main)

Attributes:

Name Type Description
app_id str

Your OneSignal App ID.

log_level Optional[OSLogLevel]

Optional SDK log level for console/logcat output.

visual_alert_level Optional[OSLogLevel]

Optional SDK log level for visual alerts (iOS toast notifications).

require_consent bool

Whether to require user consent before collecting data.

Attributes#

app_id class-attribute instance-attribute #

app_id: str = ''

Your OneSignal App ID from the dashboard.

debug property #

debug: OneSignalDebug

Access the Debug namespace for SDK logging configuration.

in_app_messages property #

in_app_messages: OneSignalInAppMessages

Access the In-App Messages namespace for IAM triggers and control.

live_activities property #

live_activities: OneSignalLiveActivities

Access the Live Activities namespace (iOS only).

location property #

location: OneSignalLocation

Access the Location namespace for location sharing.

log_level class-attribute instance-attribute #

log_level: Optional[OSLogLevel] = None

SDK log level for console/logcat output. Defaults to None (no logging).

notifications property #

notifications: OneSignalNotifications

Access the Notifications namespace for push notification management.

on_error class-attribute instance-attribute #

on_error: Optional[EventHandler[OSErrorEvent]] = None

Called when an error occurs in the SDK.

on_iam_click class-attribute instance-attribute #

on_iam_click: Optional[
    EventHandler[OSInAppMessageClickEvent]
] = None

Called when the user clicks on an in-app message.

on_iam_did_dismiss class-attribute instance-attribute #

on_iam_did_dismiss: Optional[
    EventHandler[OSInAppMessageDidDismissEvent]
] = None

Called after an in-app message is dismissed.

on_iam_did_display class-attribute instance-attribute #

on_iam_did_display: Optional[
    EventHandler[OSInAppMessageDidDisplayEvent]
] = None

Called after an in-app message is displayed.

on_iam_will_dismiss class-attribute instance-attribute #

on_iam_will_dismiss: Optional[
    EventHandler[OSInAppMessageWillDismissEvent]
] = None

Called before an in-app message is dismissed.

on_iam_will_display class-attribute instance-attribute #

on_iam_will_display: Optional[
    EventHandler[OSInAppMessageWillDisplayEvent]
] = None

Called before an in-app message is displayed.

on_notification_click class-attribute instance-attribute #

on_notification_click: Optional[
    EventHandler[OSNotificationClickEvent]
] = None

Called when the user taps on a notification.

on_notification_foreground class-attribute instance-attribute #

on_notification_foreground: Optional[
    EventHandler[OSNotificationWillDisplayEvent]
] = None

Called when a notification is received while the app is in the foreground.

on_permission_change class-attribute instance-attribute #

on_permission_change: Optional[
    EventHandler[OSPermissionChangeEvent]
] = None

Called when the notification permission status changes.

on_push_subscription_change class-attribute instance-attribute #

on_push_subscription_change: Optional[
    EventHandler[OSPushSubscriptionChangedEvent]
] = None

Called when the push subscription state changes.

on_user_change class-attribute instance-attribute #

on_user_change: Optional[
    EventHandler[OSUserChangedEvent]
] = None

Called when the OneSignal user state changes.

require_consent: bool = False

Whether to require user consent before the SDK collects data (GDPR compliance).

session property #

session: OneSignalSession

Access the Session namespace for outcomes tracking.

user property #

user: OneSignalUser

Access the User namespace for identity, tags, aliases, email, SMS.

visual_alert_level class-attribute instance-attribute #

visual_alert_level: Optional[OSLogLevel] = None

SDK log level for visual alerts (iOS toast notifications). Defaults to None.

Functions#

consent_given async #

consent_given(given: bool) -> None

Indicate whether the user has given consent for data collection.

This method should be called after the user accepts or declines your privacy terms when require_consent is True.

Parameters:

Name Type Description Default
given bool

True if the user gave consent, False otherwise.

required

init #

init()

Initialize the service and sub-modules.

login async #

login(external_id: str) -> None

Login to OneSignal with an external user ID.

This switches the user context to the specified user. If the user doesn't exist, a new user will be created.

Parameters:

Name Type Description Default
external_id str

Your unique identifier for the user.

required

logout async #

logout() -> None

Logout the current user.

After logout, a new anonymous device-scoped user will be created.