GithubHelp home page GithubHelp logo

urbanairship / python-library Goto Github PK

View Code? Open in Web Editor NEW
83.0 100.0 67.0 2.71 MB

A Python library for using the Airship APIs for push notifications, reporting and other message types

Home Page: https://docs.airship.com/api/libraries/python/

License: Other

Python 100.00%

python-library's Introduction

image


urbanairship is a Python library for using the Airship REST API for push notifications, message center messages, email, and SMS.

Requirements

Python 2.7, 3.6, 3.7, 3.8, or 3.9 is required. Other requirements can be found in requirements.txt.

Questions

The best place to ask questions or report a problem is our support site: http://support.airship.com/

Usage

See the full documentation for this library, as well as the Airship API Documentation.

Simple iOS Push

>>> import urbanairship as ua >>> airship = ua.Airship('application_key', 'master_secret') >>> push = airship.create_push() >>> push.audience = ua.or(ua.alias('adam'), ua.ios_channel('some_ios_channel')) >>> push.notification = ua.notification(alert='Hello') >>> push.device_types = ua.device_types('ios') >>> push.send()

Broadcast to iOS and Android devices

>>> push = airship.create_push() >>> push.audience = ua.all >>> push.notification = ua.notification( ... ios=ua.ios(alert='Hello iOS'), ... android=ua.android(alert='Hello Android')) >>> push.device_types = ua.device_types('ios', 'android') >>> push.send()

Sending a message center message to a single iOS device

>>> import urbanairship as ua >>> airship = ua.Airship('application_key', 'master_secret') >>> push = airship.create_push() >>> push.audience = ua.ios_channel('some_ios_channel') >>> push.notification = ua.notification(alert='Hello') >>> push.device_types = ua.device_types('ios') >>> push.message = ua.message( ... 'Hello, message center user', ... '<html><h1>Hello!</h1><p>Goodbye.</p></html>') >>> push.send()

Web Push to a tag

>>> import urbanairship as ua >>> airship = ua.Airship('application_key', 'master_secret') >>> push = airship.create_push() >>> push.audience = ua.tag('web_tag') >>> push.notification = ua.notification(alert='Hello') >>> push.device_types = ua.device_types('web') >>> push.send()

History

  • 6.0 Support for Bearer Token Authentication. Removes support for Python 2.
  • 5.0 Support for SMS and Email messages. See changelog for other updates.
  • 4.0 Support for Automation, removed Feedback
  • 3.0 Support for Open Channels, several other significant changes
  • 2.0 Support for Web Notify and more iOS 10, stopped supporting Python 2.6
  • 1.0 Support for In-App and iOS 10
  • 0.8 Support for Reports APIs
  • 0.7 Support for Python 3, major refactoring
  • 0.6 Major refactoring, support for push api v3
  • 0.5 Added Android, Rich Push, and scheduled notifications
  • 0.4 Added batch push
  • 0.3 Added deregister, device token list, other minor improvements
  • 0.2 Added tags, broadcast, feedback
  • 0.1 Initial release

See the CHANGELOG file for more details.

python-library's People

Contributors

aschuman0 avatar brett-s avatar bugzpdx avatar crow avatar devinsmythe avatar kfrye avatar leegenes avatar lolsborn avatar madelgi avatar martin-vct avatar martinfua avatar maxmarchuk avatar mgood avatar mhooge avatar mmchugh avatar nadinyrosh avatar nickadlard avatar pdxmele avatar robotadam avatar sarahdactyl71 avatar seanyc avatar ustun avatar vially avatar whileloup avatar whyqqqqq avatar wilsab30 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-library's Issues

Fix ValueError: zero length field name in format in Python 2.6

The _request method in core.py omits positional arguments when formatting a user agent string with the library's version, which breaks compatibility with Python 2.6. Positional arguments are optional only in Python 2.7 and above.

Traceback (most recent call last):
  File "/var/www/Watchdog/urbanairship/push/core.py", line 45, in send
    common.PUSH_URL, 'application/json', version=3)
  File "/urbanairship/core.py", line 64, in _request
    {'User-agent': "UAPythonLib/{}".format(__about__.__version__)}
ValueError: zero length field name in format

Android Pushes

It is rather question than issue.
Are Google/Android pushes enabled in python library?
How to use them?

Batching Push Sends

Hey, I was looking for batching push requests and make a single request and not multiple requests. Let me explain more clearly. For eg, I have a push with certain channel ids and payload and there is another push with certain channel ids and payload. Now instead of making 2 requests, I want to make one single send that we do like push.send() . I have seen we can do this by passing array of push objects in Postman and it works fine. I am not able to replicate this behaviour in Python. Is there anyone we can do that. If yes, then can anyone help me and share a sample code snippet or if it's in working phase? Thanks!

Support for Tag Groups / Data Bridge API

There appears to be no way to add a device to a tag under a specific tag group even though the latest version 0.7.4 was released after the data bridge was out. Are there plans to support tag groups?

Erroneous log messages

We only accept issues for bug reporting purposes.

All feature requests, implementation concerns or general queries should be sent to our support team.

Before completing the form below, please check the following:

  • You are using the most recent version of the library.
  • You are using a supported version of Python for that library version.
  • This issue is reproducible.

Expected Behavior

Log non-200 urbanairship responses at an INFO or DEBUG level

Current Behavior

Currently they're logged as at an ERROR level, while all other messages are logged at an INFO level.

Possible Solution

Change this line from logger.error(... to logger.info(...

logger.error(
"Request failed with status %d: '%s %s': %s",
response.status_code, error_code, error, details)

Steps to Reproduce

Get a non 200 response

Detailed Description

This is the only place that logs messages at the ERROR level. This seems a bit excessive since the logging happens during the creation of a loud AirshipFailure, which will propagate up the stack with a full stack trace

Possible Fix

API is only using global base url and giving error for EU regions. There is no place to define region so that it can take base url properly.

All bugs, feature requests, implementation concerns or general queries should be sent to our support team.

You are welcome to submit an issue here for bugs, but please also reach out to our support team as well.

Before completing the form below, please check the following:

  • [ √] You are using the most recent version of the library.
  • [ √] You are using a supported version of Python for that library version.
  • [ √] This issue is reproducible.

Expected Behavior

It should take region or atleast the baseurl.

Current Behavior

not allowing to change baseurl

Possible Solution

we should be able to change baseurl.

Steps to Reproduce

  1. Create account in eu region
  2. Install Python urbanairship library
  3. Use your keys which are working fine in postman
  4. you will not get authenticated

No option to create Airship object with Bearer Auth

All bugs, feature requests, implementation concerns or general queries should be sent to our support team.

You are welcome to submit an issue here for bugs, but please also reach out to our support team as well.

Before completing the form below, please check the following:

  • You are using the most recent version of the library.
  • You are using a supported version of Python for that library version.
  • This issue is reproducible.

Expected Behavior

The Airship constructor should have an option to create an object with a token instead of needing to provide an app secret and an app key.

Current Behavior

Developer can only create an Airship object with app key and app secret

Possible Solution

Create an extra "token" argument in Airship to constructor and validate whether it is enough to use the class' methods

Steps to Reproduce

  1. airship = Airship(token="abcde")

Detailed Description

init__() got an unexpected keyword argument 'token'

Possible Fix

Test issue

All bugs, feature requests, implementation concerns or general queries should be sent to our support team.

You are welcome to submit an issue here for bugs, but please also reach out to our support team as well.

Before completing the form below, please check the following:

  • You are using the most recent version of the library.
  • You are using a supported version of Python for that library version.
  • This issue is reproducible.

Expected Behavior

Current Behavior

Possible Solution

Steps to Reproduce

Detailed Description

Possible Fix

"Europe/Kyiv" is not a valid timezone

Expected Behavior

While setting the email channel we are facing an error response and the airship is not recognizing Kyiv in the timezone. I guess IANA already released the changes related to this in 2022 by renaming Kyiv from Kiev.

It should accept timezone value "Europe/Kyiv"

(400, b'{"ok":false,"error":"Could not parse request body.","error_code":40000,"details":{"error":"Europe/Kyiv is not a valid timezone."}}')

Sending template push

Is there a way to send a template push in this library? I am referring to this example here: http://docs.urbanairship.com/api/ua.html#template-creation-and-push-example

this payload is used:

{
    "device_types": "all",
    "audience": {
       "ios_channel": "b8f9b663-0a3b-cf45-587a-be880946e881"
    },
    "merge_data": {
        "template_id": "ef34a8d9-0ad7-491c-86b0-aea74da15161",
        "substitutions": {
            "TITLE": "Ms.",
            "FIRST_NAME": "Alice",
            "LAST_NAME": "Jones"
        }
    }
}

However in this library 1.0.0 I can't find a way to add that "merge_data" block that contains the template information.

urbanairship.SegmentList not working

All bugs, feature requests, implementation concerns or general queries should be sent to our support team.

You are welcome to submit an issue here for bugs, but please also reach out to our support team as well.

Before completing the form below, please check the following:

  • You are using the most recent version of the library.
  • You are using a supported version of Python for that library version.
  • This issue is reproducible.

Expected Behavior

When listing the segments, I should get a response.

Current Behavior

The list is empty.

Possible Solution

Set next_url properly here

def __init__(self, airship, limit=None):
next_url = airship.urls.get('segments_url')
params = {'limit': limit} if limit else {}
super(SegmentList, self).__init__(airship, params)

- next_url = airship.urls.get('segments_url')
+ self.next_url = airship.urls.get('segments_url')

Steps to Reproduce

import urbanairship as ua
airship = ua.Airship("app_key", "master_secret")
segment_list = ua.SegmentList(airship)

assert list(segment_list) == [] 
# True = bug

segment_list.next_url = airship.urls.get('segments_url')
assert list(segment_list) == []
# False = fix

Detailed Description

Possible Fix

Will see if I can open a PR

ua-sphinx-docs-theme submodule is missing?

Expected Behavior

All referenced submodules should exist.

Current Behavior

urbanairship/ua-sphinx-docs-theme.git as a submodule appears to be missing (or private in github)

Possible Solution

remove submodule or make the theme available

Steps to Reproduce

git clone project
git submodule update --init --recursive

Detailed Description

Here is a log:

git submodule update --init --recursive
source/urbanairship/docs/_themes/urbanairship'...
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of '[email protected]:urbanairship/ua-sphinx-docs-theme.git' into submodule path '.../source/urbanairship/docs/_themes/urbanairship' failed
Failed to clone 'docs/_themes/urbanairship'. Retry scheduled
Cloning into '.../source/urbanairship/docs/_themes/urbanairship'...
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of '[email protected]:urbanairship/ua-sphinx-docs-theme.git' into submodule path '.../source/urbanairship/docs/_themes/urbanairship' failed
Failed to clone 'docs/_themes/urbanairship' a second time, aborting
Failed to recurse into submodule path 'server/source/urbanairship'

Possible Fix

Error handling code assumes response content is JSON

When the API responds with Error 503: Your request could not be completed, please retry., the call to json.dumps(details) raises an exception:

  File "/home/ubuntu/virtualenvs/venv-3.4.3/lib/python3.4/site-packages/urbanairship/push/core.py", line 49, in send
    version=3
  File "/home/ubuntu/virtualenvs/venv-3.4.3/lib/python3.4/site-packages/urbanairship/core.py", line 65, in _request
    raise common.AirshipFailure.from_response(response)
  File "/home/ubuntu/virtualenvs/venv-3.4.3/lib/python3.4/site-packages/urbanairship/common.py", line 75, in from_response
    response.status_code, error_code, error, json.dumps(details))
  File "/opt/circleci/python/3.4.3/lib/python3.4/json/__init__.py", line 230, in dumps
    return _default_encoder.encode(obj)
  File "/opt/circleci/python/3.4.3/lib/python3.4/json/encoder.py", line 192, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/opt/circleci/python/3.4.3/lib/python3.4/json/encoder.py", line 250, in iterencode
    return _iterencode(o, 0)
  File "/opt/circleci/python/3.4.3/lib/python3.4/json/encoder.py", line 173, in default
    raise TypeError(repr(o) + " is not JSON serializable")
nose.proxy.TypeError: b'Error 503: Your request could not be completed, please retry.' is not JSON serializable

No Global Attributes Field in the urbanairship Python Library

Expected Behavior

I decided to use python library of urbanairship in my code. There is a field called global_attributes available in the push object(referring to the docs), but I am not able to find any field present in the python library.

Current Behavior

Not able to find any global_attributes field in the push object in the python library. Its even there in the java library. Its very strange that not to have it in python library.

Please help me out if there is any way to use this field.

Key error at urbanairship/common.py L 66

We only accept issues for bug reporting purposes.

All feature requests, implementation concerns or general queries should be sent to our support team.

Before completing the form below, please check the following:

  • You are using the most recent version of the library. --->3.0.1
  • You are using a supported version of Python for that library --->version. 3.6
  • This issue is reproducible.

Expected Behavior

When you upload a file to a Static List, and the csv is delimited with ; string:

import urbanairship as ua
from local_credentials import uas

airshipauth = ua.Airship(**uas)

#creating a Static List:
new_static_list = ua.devices.StaticList(airshipauth, 'new_static_list')
new_static_list.create()
# it returns {'ok':True}
#uploading list
with open('users.csv', 'rb') as _file:
    new_static_list.upload(_file)
# ????

Current Behavior

But, you get KeyError exception for some non-expected exception at core.py:

    new_static_list.upload(_file)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-46-d4f457512c8d> in <module>()
----> 1 result.upload(_file)

~/anaconda3/envs/genericenv/lib/python3.6/site-packages/urbanairship/devices/static_lists.py in upload(self, csv_file)
     48             content_type='text/csv',
     49             version=3,
---> 50             encoding='gzip'
     51         )
     52         return response.json()

~/anaconda3/envs/genericenv/lib/python3.6/site-packages/urbanairship/core.py in _request(self, method, body, url, content_type, version, params, encoding)
     63             raise common.Unauthorized
     64         elif not (200 <= response.status_code < 300):
---> 65             raise common.AirshipFailure.from_response(response)
     66 
     67         return response

~/anaconda3/envs/genericenv/lib/python3.6/site-packages/urbanairship/common.py in from_response(cls, response)
     63             error = payload['error']
     64             error_code = payload['error_code']
---> 65             details = payload['details']
     66         except (ValueError, TypeError):
     67             error = response.reason

KeyError: 'details'

Steps to Reproduce

Detailed Description

in Current Behaviour

Package Types with library

All bugs, feature requests, implementation concerns or general queries should be sent to our support team.

You are welcome to submit an issue here for bugs, but please also reach out to our support team as well.

Before completing the form below, please check the following:

  • You are using the most recent version of the library.
  • You are using a supported version of Python for that library version.
  • This issue is reproducible.

Expected Behavior

The library should be packaged with type annotations.

Current Behavior

The library does not included type annotations

Possible Solution

Support PEP 561 -- include types in published package

Steps to Reproduce

  1. Install urbanairship in a python project
  2. Import any class from the urbanairship package
  3. Run a type linter like mypy
  4. Observe that linter will report urbanairship is missing type annotations.

Detailed Description

It appears as if the library source code is typed. Why not also package the types along for consumers that leverage type annotations.

Possible Fix

Error registering device token

register method from Airship object expects only 201 response code but the API could return 201 or 200.

Maybe the lib should expect both statuses as success?

Example code bellow:

>>> from urbanairship import ua
>>> air = ua.Airship('key', 'master secret')
>>> air.register('my-device-token', tags=['something'])
False

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.