Airship Python Library
urbanairship
is a Python library for using the Airship web service in support of our messaging product
lines and related features.
Installation
Using pip
:
$ pip install urbanairship
Using the library
The library is intended to be used with the small footprint of a single import. To get started, import the package, and create an appropriate client object representing a single Airship project.
import urbanairship as ua
client = ua.client.BasicAuthClient('<app key>', '<master secret>')
push = ua.Push(client)
push.audience = ua.all_
push.notification = ua.notification(alert='Hello, world!')
push.device_types = ua.device_types('ios', 'android')
push.send()
The library uses requests for communication with the Airship API, providing connection pooling and strict SSL checking. All client objects are threadsafe, and can be instantiated once and reused in multiple threads.
Authentication
The library supports three authentication methods:
Basic Authentication - Using app key and master secret
Bearer Token Authentication - Using app key and Airship-generated bearer token
OAuth2 Authentication - Using JWT assertions with automatic token refresh
For more details on each authentication method, see the Client Classes and Authentication documentation.
Logging
urbanairship
uses the standard logging module for integration into
an application’s existing logging. If you do not have logging
configured otherwise, your application can set it up like so:
import logging
logging.basicConfig()
If you’re having trouble with the Airship API, you can turn on verbose debug logging.
logging.getLogger('urbanairship').setLevel(logging.DEBUG)
Exceptions
- class urbanairship.AirshipFailure(error: str | None, error_code: str | int | None, details: str | None, response: str | None, *args: Any)
Raised when we get an error response from the server.
- Parameters:
args – For backwards compatibility,
*args
includes the status and response body.
- class urbanairship.Unauthorized
Raised when we get a 401 from the server
- class urbanairship.ConnectionFailure
Raised when there’s a connection failure.
Development
The library source code is available on GitHub.
Tests can be run with nose:
nosetests --with-doctest