Skip to main content
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 (android / ios). Developed with the help of https://github.com/olucurious/PyFCM

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
- Django rest framework viewsets

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 = {
"FCM_SERVER_KEY": "[your api key]"
}

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
----------------

.. 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"})

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
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'),
# ...
)

Demo javascript app
-------------------
Very basic demonstration of web push notifications:
https://github.com/xtrinch/fcm-django-web-demo


Python 3 support
----------------
``fcm-django`` is fully compatible with Python 3.4 & 3.5


Acknowledgments
----------------
https://github.com/jleclanche/django-push-notifications

Need help, have any questions, suggestions?
----------------
Submit an issue/PR or email me at mojca.rojko@gmail.com

Release files for fcm-django 0.2.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fcm-django 0.2.7
File Size Uploaded
fcm-django-0.2.7.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fcm-django 0.2.7
File Interpreter ABI Platform
fcm_django-0.2.7-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size:21.7 kB

Release files / fcm-django-0.2.7.tar.gz

Download URL fcm-django-0.2.7.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
39ae9ec0d2a5835de459558d1321f17f4f0c93568284e0042614d873f04329e1
BLAKE2b-256 checksum
How to use checksums
0cc04f3551cc6ee505275f5194c69e04d566fbff03fd7e11545043fbcbf58fc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / fcm_django-0.2.7-py2.py3-none-any.whl

Download URL fcm_django-0.2.7-py2.py3-none-any.whl
Size 12.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
a701b7ffef32b86ddf66afbd37151ddd407666ed2cf4cb902fc1b1113b7d6a6b
BLAKE2b-256 checksum
How to use checksums
9e42532fa31024b5f7334673df0fa4ecb673e72fc7687c9e1756704e35eb4dd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

3.2.0

2 release files

3.1.0

1 release file

3.0.0

1 release file

2.3.1

1 release file

2.3.0

1 release file

2.2.1

1 release file

2.2.0

1 release file

2.1.0

1 release file

2.0.1

1 release file

2.0.0

1 release file

1.0.15

1 release file

1.0.14

1 release file

1.0.13

1 release file

1.0.12

1 release file

1.0.11

1 release file

1.0.10

1 release file

1.0.9

2 release files

1.0.8

2 release files

1.0.7

1 release file

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.3.11

1 release file

0.3.10

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

1 release file

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.20

2 release files

0.2.19

2 release files

0.2.15

2 release files

0.2.14

2 release files

0.2.13

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.9

2 release files

0.2.8

2 release files

This release

0.2.7 This release

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page