Package: pypn
Abstraction library to send push notifications through APNs, GCM and OneSignal.Caution!This library only supports Python 3.5RequirementsCaution!Requirements are not installed automatically by pip. The recomended
dependencies can be found in requirements.txt.For APNs an @oeegor/apns2-client fork is used,pypnbranchhttps://github.com/alej0varas/apns2-client.gitFor GCM @geeknam/python-gcmdevelopbranch is used.https://github.com/geeknam/python-gcm.gitFor OneSignalyaosac.https://pypi.python.org/pypi/yaosacUsageAPNSapns=pypn.Notification(pypn.APNS)apns.send(token,data)Possible values fortokenare:A stringA list of stringCurrently sending multiple notifications means iterating over the list
and send one request per user.GCMgcm=pypn.Notification(pypn.APNS)gcm.send(token,data)Possible values fortokenare:A stringregistration_idortopic(just the name, without “/topic/”)A list of string,registration_idsOneSignalones=pypn.Notification(pypn.OS)ones.send(token,data)Possible values fortokenare:A list of OneSignal’splayer_idYou need an App Auth Key and App Id. They can be set as environment
variables ‘OS_APP_AUTH_KEY’ and ‘OS_APP_ID’ or assigned to the client
viauser_auth_keyandapp_idattributes.Dummydummy=pypn.Notification(pypn.DUMMY)dummy.send(token,data)DataPyPN has been built as a layer in between a “back-end”(I’m working
on a Django application to handle data) and the existing push
notification libraries. That means notifications are defined including
all the required fields for each provider. This data is then passed to
PyPN together with the provider “name”.Example dataNot every field value is set.data={# Common fields'body':'1, 2, 3, ... push sucks!''sound':'default','priority':'high','title':'Hello, World!',# APNs aps'apns_badge':69,'apns_content_available':1,'apns_category':'','apns_mutable_content':True,# APNs alert'apns_alert_title_loc_key':'','apns_alert_title_loc_args':'','apns_alert_loc_key':'','apns_alert_loc_args':'','apns_alert_action_loc_key':'','apns_alert_launch_image':'',# APNs data'apns_custom':{'custom':'values'},# GCM data'gcm_data':{'custom':'values'},# GCM notification'gcm_notification_icon':'','gcm_notification_tag':'','gcm_notification_color':'','gcm_notification_click_action':'','gcm_notification_body_loc_key':'','gcm_notification_body_loc_args':'','gcm_notification_title_loc_key':'','gcm_notification_title_loc_args':'',# GCM options'gcm_option_collapse_key':'','gcm_option_content_available':'','gcm_option_delay_while_idle':'','gcm_option_time_to_live':40320,'gcm_option_restricted_package_name':'',}CredentialsCredentials are expected to be in placed in the environment.For APNs the path to the .pem certificate and the pass-phrase if any:APNS_CERT_FILEAPNS_CERT_PASSWORDFor GCM the server key:GCM_SERVER_KEYFor OneSignal the application id and the API key:OS_APP_AUTH_KEYOS_APP_IDDebugDebug is the default value for every provider(you willnotget
notifications through GCM unless you set debug to false). This can
also be set in the environment:APNS_MODE: Possible values are “dev” and “prod”GCM_DRY_RUN: Possible values are 0 and 1There is no debug mode for OneSignal :(Dummy: There is a dummy provider that does nothinAlso logging for the gcm library can be enabled settingGCM_LOGGINGenvironment variable to 1.ContributingFeel free to open a pull request or issue in GitHub.TestingInstall requirementspipinstall-rrequirements.txtCopy and update the environment filecp.env-template.envDON’T FORGET TO EDIT .env :)Install honchopipinstallhonchoUnithonchorunpythontests.pyIntegrationThis will send a notification to your devices.honchorunpythontests_integration.py