exponent-server-sdk-python-async
This repo is made for the async version of the exponent-server-sdk-python made by Bahadır Araz.
Installation
pip install exponent-server-sdk-async
Usage
Use to send push notifications to Exponent Experiences from a Python server. Full documentation on the API is available if you want to dive into the details.
import asyncio
import os
import httpx
from loguru import logger
from dotenv import load_dotenv
from exponent_server_sdk_async import (
AsyncPushClient,
PushMessage,
DeviceNotRegisteredError,
PushTicketError,
PushServerError
)
# Logger setup
logger.add("debug.log", rotation="1 week", compression="zip")
load_dotenv()
logger.debug("Using Expo Token: {}", os.getenv('EXPO_TOKEN'))
async def send_push_message_to_multiple(tokens, message, extra, title, navigate_to=None):
async with httpx.AsyncClient(headers={
"Authorization": f"Bearer {os.getenv('EXPO_TOKEN')}",
"Accept": "application/json",
"Content-Type": "application/json",
}) as session:
push_client = AsyncPushClient(session=session)
push_messages = [
PushMessage(
to=token,
body=message,
data={'extra': extra, 'navigateTo': navigate_to},
badge=1,
title=title,
sound="default"
) for token in tokens
]
try:
push_tickets = await push_client.publish_multiple(push_messages)
for push_ticket in push_tickets:
if push_ticket.is_success():
logger.info("Notification sent successfully to: {}", push_ticket.push_message.to)
else:
logger.warning("Failed to send notification to: {}, Error: {}", push_ticket.push_message.to, push_ticket.message)
except PushServerError as exc:
logger.error("Push server error: {}", exc)
raise
except DeviceNotRegisteredError as exc:
logger.error("Device not registered error: {}", exc)
raise
except PushTicketError as exc:
logger.error("Push ticket error: {}", exc)
raise
async def main():
tokens = [
"ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]",
"ExponentPushToken[yyyyyyyyyyyyyyyyyyyyyy]",
"ExponentPushToken[zzzzzzzzzzzzzzzzzzzzzz]"
]
extra_parameters = {"key": "value"}
# Send a simple push message to multiple recipients
await send_push_message_to_multiple(tokens, "Hello Multi-User", extra_parameters, "Greeting")
# Navigate to home data for multiple recipients
await send_push_message_to_multiple(tokens, "Navigate to home", extra_parameters, "Home", "/(tabs)/(home)")
if __name__ == "__main__":
asyncio.run(main())
Metadata
Release files for exponent-server-sdk-async 2.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| exponent_server_sdk_async-2.1.7.tar.gz | 6.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| exponent_server_sdk_async-2.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.3 kB
Release files / exponent_server_sdk_async-2.1.7.tar.gz
| Download URL | exponent_server_sdk_async-2.1.7.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6e8e213009b4146336336a51a54e089072afffc8c5b01233b00c8030c97e9e94
|
|
BLAKE2b-256 checksum How to use checksums |
42ed8c3120e29553bf1d669ab9c04511011c92924bcc7721dcd337c7d809f7c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / exponent_server_sdk_async-2.1.7-py3-none-any.whl
| Download URL | exponent_server_sdk_async-2.1.7-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23f33cb49d53bc925b3538b2eda4b9ab4655bd825481a1fd4effd6b9d022f2a0
|
|
BLAKE2b-256 checksum How to use checksums |
b7467e9227c3ee902c5feb71267f32d2a27f33c971f00bb5b6f52442c0eb99d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|