{"id":10331,"library":"urbanairship","title":"Urban Airship Python Library","description":"The `urbanairship` library is a Python client for interacting with the Airship REST API, enabling programmatic access to features like sending push notifications, managing audiences, and retrieving reports. It is currently at version 7.3.1 and receives updates periodically, with major releases introducing significant changes.","status":"active","version":"7.3.1","language":"en","source_language":"en","source_url":"https://github.com/urbanairship/python-library","tags":["push notifications","mobile","marketing","airship","client library"],"install":[{"cmd":"pip install urbanairship","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"HTTP client for API requests","package":"requests","optional":false},{"reason":"Time zone handling","package":"pytz","optional":false},{"reason":"ISO 8601 date parsing","package":"iso8601","optional":false},{"reason":"Extends datetime functionality","package":"python-dateutil","optional":false}],"imports":[{"symbol":"BasicAuthClient","correct":"from urbanairship import BasicAuthClient"},{"symbol":"BearerTokenAuthClient","correct":"from urbanairship import BearerTokenAuthClient"},{"note":"The `Airship` class was removed in v7.0.0. Use `BasicAuthClient` or `BearerTokenAuthClient` instead.","wrong":"from urbanairship import Airship","symbol":"Airship","correct":"N/A (removed in v7.0.0)"},{"symbol":"Push","correct":"from urbanairship import Push"},{"symbol":"Audience","correct":"from urbanairship import Audience"},{"symbol":"Notification","correct":"from urbanairship import Notification"},{"symbol":"Platform","correct":"from urbanairship import Platform"}],"quickstart":{"code":"import os\nfrom urbanairship import BasicAuthClient, Push, Audience, Notification, Platform\n\n# Replace with your actual credentials or set as environment variables\nAPP_KEY = os.environ.get('URBAN_AIRSHIP_APP_KEY', 'YOUR_APP_KEY')\nMASTER_SECRET = os.environ.get('URBAN_AIRSHIP_MASTER_SECRET', 'YOUR_MASTER_SECRET')\n\nif APP_KEY == 'YOUR_APP_KEY' or MASTER_SECRET == 'YOUR_MASTER_SECRET':\n    print(\"Please set URBAN_AIRSHIP_APP_KEY and URBAN_AIRSHIP_MASTER_SECRET environment variables or replace placeholders.\")\n    # exit(1) # Uncomment to prevent execution with dummy credentials\n\n# Initialize the client with Basic Authentication\nclient = BasicAuthClient(APP_KEY, MASTER_SECRET)\n\ntry:\n    # Create a Push object\n    push = Push(client)\n\n    # Target all devices\n    push.audience = Audience.all()\n\n    # Define the notification message\n    push.notification = Notification(alert=\"Hello from Urban Airship Python Library!\")\n\n    # Specify device types (platforms) to target\n    push.device_types = Platform.all()\n\n    # Send the push notification\n    response = push.send()\n\n    print(f\"Push notification sent successfully! Status: {response.status_code}\")\n    print(f\"Response body: {response.json()}\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to send a basic push notification to all devices using `BasicAuthClient`, which is the recommended client for key/secret authentication. Ensure your Airship App Key and Master Secret are configured either as environment variables or directly in the code (for development purposes)."},"warnings":[{"fix":"Migrate to `urbanairship.BasicAuthClient` for key/secret authentication or `urbanairship.BearerTokenAuthClient` for token-based authentication.","message":"The primary `urbanairship.Airship` client class was removed in version 7.0.0. Code using this class will raise an `AttributeError` or `ImportError` on v7.x.x.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Ensure your project is running on Python 3.10 or newer. Upgrade your Python environment if necessary.","message":"Version 7.0.0 dropped support for Python versions prior to 3.10. Older versions (e.g., v6.0.1) dropped support for Python 2 and prior to 3.6.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Always refer to the library's source code or release notes for the most accurate usage patterns, especially for client instantiation. Use `BasicAuthClient` or `BearerTokenAuthClient`.","message":"The official GitHub README for the `urbanairship/python-library` project may contain outdated quickstart examples that still reference the removed `urbanairship.Airship` class, even for current 7.x.x versions. Following these examples will lead to errors.","severity":"gotcha","affected_versions":">=7.0.0"},{"fix":"If your application relies on location-based targeting or data, you will need to find alternative methods or use an older version of the library (prior to 6.0.1), though this is not recommended due to lack of updates.","message":"Support for location APIs, including the `LocationFinder` class and location-based audience selectors, was removed in version 6.0.1.","severity":"breaking","affected_versions":">=6.0.1"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Replace `urbanairship.Airship(key, secret)` with `urbanairship.BasicAuthClient(key, secret)` or `urbanairship.BearerTokenAuthClient(token)`.","cause":"Attempting to use the `Airship` client class in `urbanairship` versions 7.0.0 or newer. This class was removed.","error":"AttributeError: module 'urbanairship' has no attribute 'Airship'"},{"fix":"Upgrade to `urbanairship` version 7.3.1 or newer. If upgrading is not possible, ensure that when sending a `message`, a `notification` object is also included or structure your payload appropriately to avoid this edge case.","cause":"In `urbanairship` versions before 7.3.1, sending a `message` without a `notification` could improperly raise a `TypeError`.","error":"TypeError: 'int' object is not subscriptable"},{"fix":"Change your import statement from `from urbanairship import Airship` to `from urbanairship import BasicAuthClient` or `from urbanairship import BearerTokenAuthClient`.","cause":"Attempting to import the `Airship` client class directly from the `urbanairship` package in versions 7.0.0 or newer. This class no longer exists.","error":"ImportError: cannot import name 'Airship' from 'urbanairship'"}]}