### PyAPNs2 Development Setup Source: https://github.com/pr0ger/pyapns2/blob/master/README.md Details the steps required to set up the PyAPNs2 project for development, including cloning the repository, creating a virtual environment, and installing development dependencies with test support. ```shell # Clone the source code. git clone https://github.com/Pr0Ger/PyAPNs2.git cd PyAPNs2 # Create a virtualenv and install dependencies. virtualenv venv . venv/bin/activate pip install -e .[tests] ``` -------------------------------- ### PyAPNs2 Installation Source: https://github.com/pr0ger/pyapns2/blob/master/README.md Provides the command to install the PyAPNs2 library using pip. This is the standard method for adding the library to a Python project. ```shell pip install apns2 ``` -------------------------------- ### Running PyAPNs2 Tests Source: https://github.com/pr0ger/pyapns2/blob/master/README.md Explains how to execute the test suite for PyAPNs2 using the pytest framework. This is crucial for verifying the library's functionality and ensuring code quality. ```shell pytest ``` -------------------------------- ### Linting PyAPNs2 Code Source: https://github.com/pr0ger/pyapns2/blob/master/README.md Shows how to run the linter (pylint) on the PyAPNs2 codebase to check for code style and potential errors. This helps maintain code quality and consistency. ```shell pip install pylint pylint --reports=n apns2 test ``` -------------------------------- ### Running PyAPNs2 Tests with Tox Source: https://github.com/pr0ger/pyapns2/blob/master/README.md Demonstrates how to use tox to run PyAPNs2 tests across multiple Python versions. This ensures compatibility and proper functioning in different Python environments. ```shell pyenv install 3.5.6; pyenv install 3.6.7; pyenv install 3.7.1; pyenv install 3.8.0 pyenv local 3.8.0 3.7.1 3.6.7 3.5.6 pip install tox tox ``` -------------------------------- ### Token-Based Authentication for APNs Source: https://github.com/pr0ger/pyapns2/blob/master/README.md Illustrates how to use token-based authentication with APNs, which is the recommended method. This involves providing authentication key details such as the key path, key ID, and team ID to the APNs client. ```python from apns2.client import APNsClient from apns2.payload import Payload from apns2.credentials import TokenCredentials import collections token_hex = 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b87' payload = Payload(alert="Hello World!", sound="default", badge=1) topic = 'com.example.App' auth_key_path = 'path/to/auth_key' auth_key_id = 'app_auth_key_id' team_id = 'app_team_id' token_credentials = TokenCredentials(auth_key_path=auth_key_path, auth_key_id=auth_key_id, team_id=team_id) client = APNsClient(credentials=token_credentials, use_sandbox=False) Notification = collections.namedtuple('Notification', ['token', 'payload']) notifications = [Notification(payload=payload, token=token_hex)] client.send_notification_batch(notifications=notifications, topic=topic) ``` -------------------------------- ### Basic APNs Notification Sending Source: https://github.com/pr0ger/pyapns2/blob/master/README.md Demonstrates how to send a single push notification to APNs using a certificate file for authentication. It includes creating a payload, initializing the APNs client, and sending the notification. ```python from apns2.client import APNsClient from apns2.payload import Payload token_hex = 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b87' payload = Payload(alert="Hello World!", sound="default", badge=1) topic = 'com.example.App' client = APNsClient('key.pem', use_sandbox=False, use_alternative_port=False) client.send_notification(token_hex, payload, topic) ``` -------------------------------- ### Batch APNs Notification Sending Source: https://github.com/pr0ger/pyapns2/blob/master/README.md Shows how to send multiple push notifications to APNs in a single batch request. This is more efficient for sending notifications to many devices simultaneously. It requires preparing a list of notifications, each with a token and payload. ```python import collections from apns2.client import APNsClient from apns2.payload import Payload token_hex = 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b87' payload = Payload(alert="Hello World!", sound="default", badge=1) topic = 'com.example.App' Notification = collections.namedtuple('Notification', ['token', 'payload']) notifications = [Notification(payload=payload, token=token_hex)] client = APNsClient('key.pem', use_sandbox=False, use_alternative_port=False) client.send_notification_batch(notifications=notifications, topic=topic) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.