API Reference

aapns.api

class aapns.api.APNSBaseClient

Abstract base class defining the APIs a Client implementation must provide.

close()

Close the client. This coroutine should only be called once and the client cannot be used anymore afterwards.

send_notification(token: str, notification: aapns.models.Notification, *, apns_id: Optional[str] = None, expiration: Optional[int] = None, priority: aapns.config.Priority = <Priority.normal: 5>, topic: Optional[str] = None, collapse_id: Optional[str] = None, time_sensitive: bool = False) → Optional[str]

Send the notification to the device identified by the token. For details about the parameters, refer to Appls APNS documentation.

class aapns.api.Target

Abstract base class defining the API a Target must implement.

class aapns.api.Server(client_cert_path: str, host: str, port: int = 443, ca_file: Optional[str] = None, pool_size: int = 2)

Target to talk to APNS Servers. Most use cases are covered by the convenience classmethods provided, so instantiating this class directly is rarely required.

If you wish to create a custom instance of this class, you must provide the path to the client certificate to use as a string, the hostname of the server as a string, the port of hte server as an integer, and optionally the path to a root certificate to trust for TLS and the desired connection pool size.

classmethod production(client_cert_path: str) → aapns.api.Server

Returns the server configured to connect to production APNS.

classmethod production_alt_port(client_cert_path: str) → aapns.api.Server

Returns the server configured to connect to production APNS using the alternative port.

classmethod development(client_cert_path: str) → aapns.api.Server

Returns the server configured to connect to development APNS.

classmethod development_alt_port(client_cert_path: str) → aapns.api.Server

Returns the server configured to connect to development APNS using the alternative port.

class aapns.api.Simulator(device_id: str, app_id: str)

Target to talk to a local simulator. Provide the device ID of your simulator and the app ID of your app as arguments.

send_notification(token: str, notification: aapns.models.Notification, *, apns_id: Optional[str] = None, expiration: Optional[int] = None, priority: aapns.config.Priority = <Priority.normal: 5>, topic: Optional[str] = None, collapse_id: Optional[str] = None, time_sensitive: bool = False) → Optional[str]

Send the notification to the device identified by the token. For details about the parameters, refer to Appls APNS documentation.

class aapns.api.APNS(pool: 'PoolProtocol')
close()

Close the client. This coroutine should only be called once and the client cannot be used anymore afterwards.

send_notification(token: str, notification: aapns.models.Notification, *, apns_id: Optional[str] = None, expiration: Optional[int] = None, priority: aapns.config.Priority = <Priority.normal: 5>, topic: Optional[str] = None, collapse_id: Optional[str] = None, time_sensitive: bool = False) → Optional[str]

Send the notification to the device identified by the token. For details about the parameters, refer to Appls APNS documentation.

aapns.models

class aapns.models.Localized(key: str, args: Optional[List[str]] = None)

Represents a localized string to be used for the body or title of an Alert.

class aapns.models.Alert(body: Union[str, aapns.models.Localized], title: Union[str, aapns.models.Localized, None] = None, subtitle: Union[str, aapns.models.Localized, None] = None, action_loc_key: Optional[str] = None, launch_image: Optional[str] = None)

Represents an alert, which can be used in Notification.

class aapns.models.PushType

Enum holding possible types of push notifications

class aapns.models.Notification(alert: aapns.models.Alert, push_type: aapns.models.PushType = <PushType.alert: 'alert'>, badge: Optional[int] = None, sound: Optional[str] = None, content_available: bool = False, category: Optional[str] = None, thread_id: Optional[str] = None, mutable_content: bool = False, target_content_id: Optional[str] = None, extra: Optional[Dict[str, Any]] = None)

Represents a notification to send. For details on the parameters, please refer to the Apple APNS documentation.

aapns.config

class aapns.config.Priority

Enum defining the priority of the notification

aapns.errors

exception aapns.errors.APNSError

Base class for all errors raised by aapns itself.

exception aapns.errors.Blocked

This connection cannot temporarily send more requests.

exception aapns.errors.Closed

This connection was closed, the condition is permanent.

exception aapns.errors.Timeout

This request has timed out or would time out.

exception aapns.errors.FormatError

The error response could not be parsed.

exception aapns.errors.ResponseTooLarge

Server sent abnormally large respinse.

exception aapns.errors.StreamReset

Error raised if the HTTP2 stream used to send a notification was reset by APNS.

exception aapns.errors.ResponseError

Base class for response errors when sending notifications.

See below for concrete instance.

reason

The error code from APNS for this exception.

apns_id

The APNS ID this error corresponds to.

exception aapns.errors.BadCollapseId
exception aapns.errors.BadDeviceToken
exception aapns.errors.BadExpirationDate
exception aapns.errors.BadMessageId
exception aapns.errors.BadPriority
exception aapns.errors.BadTopic
exception aapns.errors.DeviceTokenNotForTopic
exception aapns.errors.DuplicateHeaders
exception aapns.errors.IdleTimeout
exception aapns.errors.MissingDeviceToken
exception aapns.errors.MissingTopic
exception aapns.errors.PayloadEmpty
exception aapns.errors.BadCertificate
exception aapns.errors.BadCertificateEnvironment
exception aapns.errors.ExpiredProviderToken
exception aapns.errors.Forbidden
exception aapns.errors.InvalidProviderToken
exception aapns.errors.MissingProviderToken
exception aapns.errors.BadPath
exception aapns.errors.MethodNotAllowed
exception aapns.errors.Unregistered
exception aapns.errors.PayloadTooLarge
exception aapns.errors.TooManyProviderTokenUpdates
exception aapns.errors.TooManyRequests
exception aapns.errors.InternalServerError
exception aapns.errors.ServiceUnavailable
exception aapns.errors.Shutdown
exception aapns.errors.UnkownResponseError