JPush API Python Client

Github Source Code

Overview

This is a Python version development package for the JPush REST API. It is provided by JPush officially and generally supports the latest API features. Corresponding REST API documentation: https://docs.jiguang.cn/jpush/server/push/server_overview/

Compatible Version

  • Python 2.7
  • Python 3

Environment Configuration

Pip Method::

  1. sudo pip install jpush

Easy_install Method:

  1. sudo easy_install jpush

Source Code Method:

  1. sudo python setup.py install

Sample Code

Sample code is in the examples folder of jpush-api-python-client, click to view all examples.

The following fragment comes from the file in the project code: example_all.py in the examples/push_examples directory of jpush-api-python-client

This sample demonstrates message push, log settings, and exception handling.

  1. _jpush = jpush.JPush(app_key, master_secret)
  2. push = _jpush.create_push()
  3. # if you set the logging level to "DEBUG",it will show the debug logging.
  4. _jpush.set_logging("DEBUG")
  5. push.audience = jpush.all_
  6. push.notification = jpush.notification(alert="hello python jpush api")
  7. push.platform = jpush.all_
  8. try:
  9. response=push.send()
  10. except common.Unauthorized:
  11. raise common.Unauthorized("Unauthorized")
  12. except common.APIConnectionException:
  13. raise common.APIConnectionException("conn error")
  14. except common.JPushFailure:
  15. print ("JPushFailure")
  16. except:
  17. print ("Exception")

Log Description

The default logging level is WARNING , which is set to DEBUG in order to facilitate debugging. The setting method is:

  1. _jpush.set_logging("DEBUG")

Exception Description

  • Unauthorized
    • AppKey, Master Secret error. Must correct if the verification fails
  • APIConnectionException
    • Include incorrect information: timeouts, no network, etc.
  • JPushFailure
    • The request is wrong. Please refer to the business return code.

HTTP Status Code

Reference document::http://docs.jiguang.cn/jpush/server/push/http_status_code/ Push v3 API Status Code Reference document:http://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/  Report API Status Code Reference Document:http://docs.jiguang.cn/jpush/server/push/rest_api_v3_report/ Device API Status Code Reference Document:http://docs.jiguang.cn/jpush/server/push/rest_api_v3_device/ Push Schedule API Status Code Reference Document:http://docs.jiguang.cn/jpush/server/push/rest_api_push_schedule/ 

Release page has a detailed version for record releasing and downloading.