Skip to main content

A library for interacting with APNs using HTTP/2 and token-based authentication.

Project description

Copyright (c) 2018 mobivention GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Download-URL: https://bitbucket.org/mobivention/mobi-apns/get/0.2.7.zip
Project-URL: Bug Reports, https://bitbucket.org/mobivention/mobi-apns/issues
Project-URL: Source, https://bitbucket.org/mobivention/mobi-apns/
Project-URL: Company Home, https://www.mobivention.com
Description: mobi-apns
=========

A library for interacting with APNs using HTTP/2 and token based
authentication.

Forked from Gene Sluder’s gobiko.apns
(https://github.com/genesluder/python-apns)

Installation
------------

``pip install mobi-apns``

Requirements
------------

- Python 3.5+
- hyper
- pyjwt
- cryptography

Usage
-----

Create a client

::

from mobi.apns import APNsClient, APNsMessage

client = APNsClient(
team_id=TEAM_ID,
bundle_id=BUNDLE_ID,
auth_key_id=APNS_KEY_ID,
auth_key_filepath=APNS_KEY_FILEPATH,
use_sandbox=True
)

Alternatively, you can create a client with the contents of the auth key
file directly::

::

client = APNsClient(
team_id=TEAM_ID,
bundle_id=BUNDLE_ID,
auth_key_id=APNS_KEY_ID,
auth_key=APNS_KEY,
use_sandbox=True
)

If you run into any problems deserializing the key, try wrapping it to
64 lines::

::

client = APNsClient(
team_id=TEAM_ID,
bundle_id=BUNDLE_ID,
auth_key_id=APNS_KEY_ID,
auth_key=APNS_KEY,
use_sandbox=True,
wrap_key=True
)

Construct a message::

::

message = APNsMessage('TEST',
badge=1,
sound='default',
loc_key='This is a %@',
loc_args=['Test'])

Now you can send a message to a device by specifying its registration
ID::

::

client.send_message(
registration_id,
message
)

Or you can send bulk messages to a list of devices::

::

client.send_bulk_message(
[registration_id_1, registration_id_2],
message
)

Payload
-------

Additional APNs payload values can be passed into the message
construction

::

message = APNsMessage(
"All your base are belong to us.",
badge=None,
sound=None,
category=None,
content_available=False,
action_loc_key=None,
loc_key=None,
loc_args=[],
extra={},
identifier=None,
expiration=None,
priority=10,
topic=None
)

Pruning
-------

The legacy binary interface APNs provided an endpoint to check whether a
registration ID had become inactive. Now the service returns a
BadDeviceToken error when you attempt to deliver an alert to an inactive
registration ID. If you need to prune inactive IDs from a database you
can handle the BadDeviceToken exception to do so::

::

from mobi.apns.exceptions import BadDeviceToken

try:
client.send_message(OLD_REGISTRATION_ID, "Message to an invalid registration ID.")
except BadDeviceToken:
# Handle invalid ID here
pass

Same approach if sending by bulk::

::

from mobi.apns.exceptions import PartialBulkMessage

try:
client.send_bulk_message([registration_id1, registration_id2], "Message")
except PartialBulkMessage as e:
# Handle list of invalid IDs using e.bad_registration_ids
pass

Documentation
-------------

- More information on APNs and an explanation of the above can be found
``in this blog post <http://gobiko.com/blog/token-based-authentication-http2-example-apns/>``\ \_.

- Apple documentation for APNs can be found
``here <https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html#//apple_ref/doc/uid/TP40008194-CH8-SW1>``\ \_.

Credits
-------

- Gene Sluder

Keywords: apns,push notifications
Platform: UNKNOWN
Requires-Python: >=3.5
Description-Content-Type: text/x-rst

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mobi-apns-0.2.7.tar.gz (7.8 kB view hashes)

Uploaded Source

Built Distribution

mobi_apns-0.2.7-py2.py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page