Skip to main content

Send requests to Apple Push Notification service (APNs) to push notifications to users.

Project description

pyAPNsKit

Send requests to Apple Push Notification service (APNs) to push notifications to users via HTTP/2, token-based

pip install pyAPNsKit

Get Started

Quickly push notifications to devices (async, batch supported)

import asyncio
from pyAPNsKit import apns

p8key = ""
with open('AuthKey_KeyID.p8', 'r') as p8file:
    p8key = p8file.read()

client = apns.Client("teamID", "topic", "KeyID", p8key, isSandbox=False)

async def main():
    responses = await client.sendAlert(
        ["deviceToken1", "deviceToken2"],  # support batch
        "title",
        "subtitle",
        "message",
        sound=True,
        apns_collapse_id="Collapse"
    )
    for resp in responses:
        print(resp.isSuccess, resp.status_code, resp.reason, resp.apns_id)

asyncio.run(main())

[!NOTE]

For parameters, their acquisition methods, and instructions, please refer to the Apple Developer Document

Customized

import asyncio
from pyAPNsKit import apns, APNsHeader, APNsBody, types

p8key = ""
with open('AuthKey_KeyID.p8', 'r') as p8file:
    p8key = p8file.read()

header = APNsHeader.APNsHeader(
    teamID="teamID",
    topic="topic",
    keyID="KeyID",
    p8Key=p8key,
    pushType=types.PushType.alert,
    apns_collapse_id="Collapse"
)
body = APNsBody.APNsBody().withAlert(
    title="title",
    subtitle="sub",
    message="message"
).withSound().withBadge(1)

async def main():
    responses = await apns.asyncPushByDeviceTokens(
        ["deviceToken1", "deviceToken2"],
        header,
        body,
        isSandbox=False
    )
    for resp in responses:
        print(resp.isSuccess, resp.status_code, resp.reason, resp.apns_id)

asyncio.run(main())

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

pyapnskit-0.2.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyapnskit-0.2.1-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file pyapnskit-0.2.1.tar.gz.

File metadata

  • Download URL: pyapnskit-0.2.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyapnskit-0.2.1.tar.gz
Algorithm Hash digest
SHA256 283c0fbe06d8bff92753421505f064d50c875c98b4036b7565a37e0b4a234377
MD5 0c765cd80331efe2a614ec5749f83643
BLAKE2b-256 1da301ed662f8f76e6668da72cd9f0db3a08ba96ca9e93999814141838a57a27

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapnskit-0.2.1.tar.gz:

Publisher: python-publish.yml on guoPhineas/pyAPNsKit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyapnskit-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pyapnskit-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyapnskit-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af677c25b8926193354b60968b345e762aeed3e74eddd1ce03503b38f73de5f9
MD5 67db04c5eb984e8a15e8a23cc1a6c01a
BLAKE2b-256 a43cce2d75901e23974148a38e457033b56da49d027471564bbce306cd8c1088

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapnskit-0.2.1-py3-none-any.whl:

Publisher: python-publish.yml on guoPhineas/pyAPNsKit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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