An efficient APNs Client Library for Python/asyncio
Project description
aioapns is a library designed specifically for sending push-notifications to iOS devices via Apple Push Notification Service. aioapns provides an efficient client through asynchronous HTTP2 protocol for use with Python’s asyncio framework.
aioapns requires Python 3.5 or later.
Performance
In my testing aioapns allows you to send on average 1.3k notifications per second on a single core.
Features
Internal connection pool which adapts to the current load
Support for certificate and token based connections
Ability to set TTL (time to live) for notifications
Ability to set priority for notifications
Ability to set collapse-key for notifications
Ability to use production or development APNs server
Installation
Use pip to install:
$ pip install aioapns
Basic Usage
import asyncio
from uuid import uuid4
from aioapns import APNs, NotificationRequest, PushType
async def run():
apns_cert_client = APNs(
client_cert='/path/to/apns-cert.pem',
use_sandbox=False,
)
apns_key_client = APNs(
key='/path/to/apns-key.p8',
key_id='<KEY_ID>',
team_id='<TEAM_ID>',
topic='<APNS_TOPIC>', # Bundle ID
use_sandbox=False,
)
request = NotificationRequest(
device_token='<DEVICE_TOKEN>',
message = {
"aps": {
"alert": "Hello from APNs",
"badge": "1",
}
},
notification_id=str(uuid4()), # optional
time_to_live=3, # optional
push_type=PushType.ALERT, # optional
)
await apns_cert_client.send_notification(request)
await apns_key_client.send_notification(request)
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
License
aioapns is developed and distributed under the Apache 2.0 license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file aioapns-1.9.tar.gz
.
File metadata
- Download URL: aioapns-1.9.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48f096e6fcc8373ca84bf7af19c9e67af8c511833ce247d2a7770bd284d0d360 |
|
MD5 | ce95196a005eeb6707cc57e723eb2884 |
|
BLAKE2b-256 | 4cb9a8528c3b126b46dee1f2615ce8c18d8f942ead29ad8a24e837c9c19c9c26 |