All Projects → xtrinch → Fcm Django

xtrinch / Fcm Django

Licence: mit
FCM Django: Send push notifications via django to websites, iOS & android mobile devices through FCM (Firebase Cloud Messaging)

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Fcm Django

Push Receiver
A library to subscribe to GCM/FCM and receive notifications within a node process.
Stars: ✭ 125 (-74.75%)
Mutual labels:  push-notifications, firebase-cloud-messaging, fcm
fcm
Golang client library for Firebase Cloud Messaging.
Stars: ✭ 22 (-95.56%)
Mutual labels:  push-notifications, fcm, firebase-cloud-messaging
Electron Push Receiver
A module to bring Web Push support to Electron allowing it to receive notifications from Firebase Cloud Messaging (FCM).
Stars: ✭ 158 (-68.08%)
Mutual labels:  push-notifications, firebase-cloud-messaging, fcm
fcmpush
Firebase Cloud Messaging API wrapper for Ruby, suppot HTTP v1 API including access_token auto refresh feature.
Stars: ✭ 44 (-91.11%)
Mutual labels:  push-notifications, fcm, firebase-cloud-messaging
Django Push Notifications
Send push notifications to mobile devices through GCM or APNS in Django.
Stars: ✭ 1,881 (+280%)
Mutual labels:  django, push-notifications, fcm
andpush
Android Push Notification in Ruby: The fastest client for FCM (Firebase Cloud Messaging)
Stars: ✭ 83 (-83.23%)
Mutual labels:  push-notifications, fcm, firebase-cloud-messaging
Nsot
Network Source of Truth is an open source IPAM and network inventory database
Stars: ✭ 337 (-31.92%)
Mutual labels:  django, django-rest-framework
Drf Flex Fields
Dynamically set fields and expand nested resources in Django REST Framework serializers.
Stars: ✭ 350 (-29.29%)
Mutual labels:  django, django-rest-framework
Django Api Domains
A pragmatic styleguide for Django API Projects
Stars: ✭ 365 (-26.26%)
Mutual labels:  django, django-rest-framework
Pushnotification
PHP and Laravel Package to send push notifications to Android and IOS devices.
Stars: ✭ 395 (-20.2%)
Mutual labels:  push-notifications, fcm
Presentations
Collection of presentations for advanced Python topics
Stars: ✭ 264 (-46.67%)
Mutual labels:  django, django-rest-framework
Onlinejudge
open source online judge based on Vue, Django and Docker. | 青岛大学开源 Online Judge | QQ群 496710125 | [email protected]
Stars: ✭ 4,458 (+800.61%)
Mutual labels:  django, django-rest-framework
Dj Rest Auth
Authentication for Django Rest Framework
Stars: ✭ 491 (-0.81%)
Mutual labels:  django, django-rest-framework
Docker Django Nginx Uwsgi Postgres Tutorial
Docker + Django + Nginx + uWSGI + Postgres 基本教學 - 從無到有 ( Docker + Django + Nginx + uWSGI + Postgres Tutorial )
Stars: ✭ 334 (-32.53%)
Mutual labels:  django, django-rest-framework
Django Rest Framework Jwt
JSON Web Token Authentication support for Django REST Framework
Stars: ✭ 3,105 (+527.27%)
Mutual labels:  django, django-rest-framework
Channels Api
RESTful Websocket APIs with Django Rest Framework and Channels
Stars: ✭ 353 (-28.69%)
Mutual labels:  django, django-rest-framework
Openciviwiki
Building a Better Democracy for the Internet Age
Stars: ✭ 275 (-44.44%)
Mutual labels:  django, django-rest-framework
Django React Boilerplate
DIY Django + React Boilerplate for starting your SaaS
Stars: ✭ 385 (-22.22%)
Mutual labels:  django, django-rest-framework
Django Rest Framework Passwordless
Passwordless Auth for Django REST Framework
Stars: ✭ 412 (-16.77%)
Mutual labels:  django, django-rest-framework
Meethub
This is a Python/Django based event management system. A meetup clone.
Stars: ✭ 411 (-16.97%)
Mutual labels:  django, django-rest-framework

fcm-django

.. image:: https://badge.fury.io/py/fcm-django.svg :target: https://badge.fury.io/py/fcm-django

Django app for Firebase Cloud Messaging. Used as an unified platform for sending push notifications to mobile devices & browsers (android / ios / chrome / firefox / ...).

FCMDevice model fields

  • registration_id (required - is FCM token)
  • name (optional)
  • active (default: true)
  • user (optional)
  • device_id (optional - can be used to uniquely identify devices)
  • type ('android', 'web', 'ios')

Functionality:

  • all necessary migrations
  • model admins for django admin
  • admin actions for testing single and bulk notification sending
  • automatic device pruning: devices to which notifications fail to send are marked as inactive
  • devices marked as inactive will not be sent notifications
  • Django rest framework viewsets

Demo javascript client project

Unsure how to use this project? Check out the demo at: https://github.com/xtrinch/fcm-django-web-demo

Setup

You can install the library directly from pypi using pip:

$ pip install fcm-django

Edit your settings.py file:

.. code-block:: python

INSTALLED_APPS = (
	...
	"fcm_django"
)

FCM_DJANGO_SETTINGS = {
	 # default: _('FCM Django')
	"APP_VERBOSE_NAME": "[string for AppConfig's verbose_name]",
	 # Your firebase API KEY
	"FCM_SERVER_KEY": "[your api key]",
	 # true if you want to have only one active device per registered user at a time
	 # default: False
	"ONE_DEVICE_PER_USER": True/False,
	 # devices to which notifications cannot be sent,
	 # are deleted upon receiving error response from FCM
	 # default: False
	"DELETE_INACTIVE_DEVICES": True/False,
}

Native Django migrations are in use. manage.py migrate will install and migrate all models.

Messages

You can read more about different types of messages here_.

.. _here: https://firebase.google.com/docs/cloud-messaging/concept-options

In short, there are two types: notifications and data messages.

Notification:

.. code-block:: json

{
    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification" : {
      "body" : "great match!",
      "title" : "Portugal vs. Denmark",
      "icon" : "myicon"
    }
}

Data message:

.. code-block:: json

{
   "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
   "data" : {
     "Nick" : "Mario",
     "body" : "great match!",
     "Room" : "PortugalVSDenmark"
   },
}

As in the following example, you can send either a notification, a data message, or both.

Sending messages

For a list of possible parameters see https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support

.. code-block:: python

from fcm_django.models import FCMDevice

device = FCMDevice.objects.all().first()

device.send_message("Title", "Message")
device.send_message(data={"test": "test"})
device.send_message(title="Title", body="Message", icon=..., data={"test": "test"})

Sending messages in bulk

.. code-block:: python

from fcm_django.models import FCMDevice

devices = FCMDevice.objects.all()

devices.send_message(title="Title", body="Message")
devices.send_message(title="Title", body="Message", data={"test": "test"})
devices.send_message(data={"test": "test"})

Sending messages to topic

.. code-block:: python

from fcm_django.fcm import fcm_send_topic_message

fcm_send_topic_message(topic_name='My topic', message_body='Hello', message_title='A message')

Using multiple FCM server keys

By default the message will be sent using the FCM server key specified in the settings.py. This default key can be overridden by specifying a key when calling send_message. This can be used to send messages using different firebase projects.

.. code-block:: python

from fcm_django.models import FCMDevice

device = FCMDevice.objects.all().first()
device.send_message(title="Title", body="Message", api_key="[project 1 api key]")
device.send_message(title="Title", body="Message", api_key="[project 2 api key]")

Django REST Framework (DRF) support

Viewsets come in two different varieties:

  • FCMDeviceViewSet

    • Permissions as specified in settings (AllowAny by default, which is not recommended)
    • A device may be registered without associating it with a user
    • Will not allow duplicate registration_id's
  • FCMDeviceAuthorizedViewSet

    • Permissions are IsAuthenticated and custom permission IsOwner, which will only allow the request.user to get and update devices that belong to that user
    • Requires a user to be authenticated, so all devices will be associated with a user
    • Will allow duplicate registration_id's for different users, so you are responsible for cleanup (if that is generally perceived as undesired behaviour or if the package itself should be doing the cleanup, open an issue or email me)

Routes can be added one of two ways:

  • Routers_ (include all views)

http://www.django-rest-framework.org/tutorial/6-viewsets-and-routers#using-routers

.. code-block:: python

from fcm_django.api.rest_framework import FCMDeviceAuthorizedViewSet

from rest_framework.routers import DefaultRouter

router = DefaultRouter()

router.register(r'devices', FCMDeviceAuthorizedViewSet)

urlpatterns = patterns('',
	# URLs will show up at <api_root>/devices
	# DRF browsable API which lists all available endpoints
	url(r'^', include(router.urls)),
	# ...
)
  • Using as_view_ (specify which views to include)

http://www.django-rest-framework.org/tutorial/6-viewsets-and-routers#binding-viewsets-to-urls-explicitly

.. code-block:: python

from fcm_django.api.rest_framework import FCMDeviceAuthorizedViewSet

urlpatterns = patterns('',
	# Only allow creation of devices by authenticated users
	url(r'^devices?$', FCMDeviceAuthorizedViewSet.as_view({'post': 'create'}), name='create_fcm_device'),
	# ...
)

Python 3 support

fcm-django is fully compatible with Python 2.7 & 3.4 & 3.5 & 3.6 & 3.7

Django version compatibility

Compatible with Django versions 1.8+. For lower django versions, use fcm-django version 0.3.2 and below.

Acknowledgements

Library relies on pyFCM for sending notifications, for more info about all the possible fields, see: https://github.com/olucurious/PyFCM

Need help, have any questions, suggestions?

Submit an issue/PR on this project. Please do not send me emails, as then the community has no chance to see your questions / provide answers.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].