The `exponent-server-sdk` is a community-maintained Python library that provides a convenient way to send push notifications to mobile applications built with Expo. It wraps the Expo Push Notification Service API, allowing Python servers to interact with Expo experiences. The current version is 2.2.0, with an irregular release cadence driven by community contributions and upstream Expo API changes.
Install & Compatibility
Where this runs
tested against v2.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.621s · 21.3MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.1s · import 0.566s · 22MB
19MB installed
● package 19MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
from exponent_server_sdk import PushClient
from exponent_server_sdk import PushMessage
from exponent_server_sdk import DeviceNotRegisteredError
from exponent_server_sdk import PushServerError
from exponent_server_sdk import PushTicketError
This quickstart demonstrates how to send a push notification using `exponent-server-sdk`. It initializes a `requests` session with an optional Expo access token for push security, constructs a `PushMessage` with a target Expo push token, title, body, and optional data, and publishes it using `PushClient`. It includes basic error handling for common scenarios like device unregistration or server errors. Ensure `EXPO_TOKEN` and a valid `EXPO_PUSH_TOKEN` are set as environment variables.
import os
import requests
from exponent_server_sdk import (
PushClient,
PushMessage,
DeviceNotRegisteredError,
PushServerError,
)
from requests.exceptions import ConnectionError, HTTPError
EXPO_ACCESS_TOKEN = os.environ.get('EXPO_TOKEN', '') # Get from Expo dashboard
EXPO_PUSH_TOKEN = os.environ.get('EXPO_PUSH_TOKEN', 'ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]') # A device-specific token
session = requests.Session()
session.headers.update(
{
"Authorization": f"Bearer {EXPO_ACCESS_TOKEN}",
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "application/json",
}
)
def send_expo_push_message(token, title, body, data=None):
try:
response = PushClient(session=session).publish(
PushMessage(
to=token,
title=title,
body=body,
data=data
)
)
response.validate_response()
print(f"Push message sent successfully: {response.json()}")
except DeviceNotRegisteredError:
print(f"Error: Device {token} is not registered. Stop sending messages to this token.")
except PushServerError as exc:
# Encountered some likely formatting/validation error.
print(f"Push server error: {exc.message}, Errors: {exc.errors}, Response data: {exc.response_data}")
except (ConnectionError, HTTPError) as exc:
# Encountered some Connection or HTTP error - retry a few times in case it is transient.
print(f"Connection or HTTP error: {exc}")
except Exception as exc:
print(f"An unexpected error occurred: {exc}")
if __name__ == "__main__":
if not EXPO_ACCESS_TOKEN:
print("Warning: EXPO_TOKEN environment variable not set. Push security might be enabled on your Expo account.")
if EXPO_PUSH_TOKEN == 'ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]':
print("Warning: EXPO_PUSH_TOKEN not set. Using a placeholder. Replace with an actual device token.")
send_expo_push_message(
token=EXPO_PUSH_TOKEN,
title="Hello from Python!",
body="This is a test notification from the Expo Server SDK.",
data={"key": "value", "another": "data"}
)
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.