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-2.0.2.tar.gz
.
File metadata
- Download URL: aioapns-2.0.2.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea58ce685aa6d0ffbdc3be4a6999c7268b9c765f806d3e4da7677c098fb72cbc |
|
MD5 | 0c74fa763e0091080ce6f6522d2874f4 |
|
BLAKE2b-256 | 0a4783a67bbf71334317e97e882e779d6407af891f5a1eef7e30af18a7bf5b5f |