Registry / communication / exponent-server-sdk

exponent-server-sdk

JSON →
library2.2.0pypypi✓ verified 35d ago

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.

communication
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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.621s · 21.3MB
glibc
py 3.103.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"} )
Debug
Known footguns
breakingMajor breaking changes occurred between versions 1.0.2 and 2.0.0. Version 1.0.2 introduced class/variable renames that were effectively breaking but not reflected in the version number. Version 2.0.0 formally acknowledged these changes and also switched to using `requests.Session` for API calls and implemented chunking for receipt checking.
gotchaIf you have enabled 'Push Security' in your Expo account settings, you *must* provide an Expo access token in the `Authorization` header with all API requests. Failure to do so will result in an `UNAUTHORIZED` error. The token should be a bearer token.
gotchaThe official `exponent-server-sdk` library is synchronous. If you require asynchronous push notification capabilities for use with async frameworks like FastAPI, consider using the independently maintained `async-expo-push-notifications` library, which offers full async/await support and Pydantic models.
gotchaThe Expo Push API has a payload size limit. The total notification payload (including title, body, data, etc.) must be at most 4096 bytes on both Android and iOS. Exceeding this limit will result in a `MessageTooBigError`.
gotchaIf a push token is invalid or a device is no longer registered (e.g., app uninstalled, permissions revoked), the Expo API will return a `DeviceNotRegisteredError` in the push receipt.
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.

Agent activity
15 hits · last 30 days
gptbot
4
ahrefsbot
4
googlebot
2
dotbot
1
script
1
bingbot
1
bytedance
1
Resources