Skip to main content

Django websub subscriber

Project description

Build Status codecov Support Python versions 3.6, 3.7 and 3.8 pypi-version

Django websub subscriber.


pip install websubsub

Add websubsub.apps.WebsubsubConfig to the list of INSTALLED_APPS in your


Set the WEBSUBSUB_OWN_ROOTURL setting in your to the full url of your project site, e.g. It will be used to build full callback urls.

Set DUMBLOCK_REDIS_URL settings in your Redis locks are used to ensure subscription/unsubscription tasks are consistent with hub and local database.

DUMBLOCK_REDIS_URL= 'redis://redishost:6379'

Add websubsub.tasks.refresh_subscriptions and websubsub.tasks.retry_failed to celerybeat schedule. If you define it in

    'websub_refresh': {
        'task': 'websubsub.tasks.refresh_subscriptions',
        'schedule': 3600  # Hourly
    'websub_retry': {
        'task': 'websubsub.tasks.retry_failed',
        'schedule': 600  # Every 10 minutes


Create Websub callback

Create celery task handler, usually in

from celery import shared_task

def news_task(data):
    print('got news!')

Callback url should end with uuid. Register url for handler in

from websubsub.views import WssView
from .tasks import news_task, reports_task

urlpatterns = [
    path('/websubcallback/news/<uuid:id>', WssView.as_view(news_task), name='webnews')
    path('/websubcallback/reports/<uuid:id>', WssView.as_view(reports_task), name='webreports')


You can create subscription on the go, or use static subscriptions.

To create subscription in the code:

from websubsub.models import Subscription
Subscription.create(topic='mytopic', urlname='webnews', hub='')

This will create Subscription object in the database and schedule celery task to subscribe with hub.

Static subscriptions

Static subscriptions can be defined in your, they are then materialized with management command ./ websub_static_subscribe.

Add static subscriptions in your

    '': {
        'subscriptions': [
            {'topic': 'mytopic', 'callback_urlname': 'webnews'},

Execute ./ websub_static_subscribe


To unsubscribe existing subscription, call Subscription.unsubscribe() method:

from websubsub.models import Subscription


WEBSUBSUB_OWN_ROOTURL - ex.: Required. Will be used to build full callback urls.

DUMBLOCK_REDIS_URL - ex.: redis://redishost:6379. Required. Will be used to lock atomic tasks.

WEBSUBSUB_AUTOFIX_URLS - If True, then websubsub.tasks.subscribe() task will be allowed to ovewrite subscription.callback_url, resolving its callback_urlname. If False, it will print an error and exit. Default: True





WEBSUBSUB_VERIFY_WAIT_TIME - How many seconds should pass before unverified subscription is considered failed. After that time, websubsub.tasks.retry_failed() task will be able to retry subscription process again.

Management commands

./ websub_static_subscribe - Materialize static subscriptions from settings. Optional arguments:

  • --purge-orphans - delete old static subscriptions from database

  • -y, --yes - answer yes to all

  • --reset-counters - reset retry counters

  • --force - send new subscription request to hub even if already subscribed or explicitly unsubscribed

./ websub_purge_unresolvable - Delete all subscriptions with unresolvable urlname from database.

./ websub_purge_all - Delete all subscriptions from database.

./ websub_reset_counters - Reset retry counters for all subscriptions in database.

./ websub_handle_url_changes - Guess changed urlnames for subscriptions from current callback_url. Also detect changed url patterns and schedule resubscribe with new url.

./ dumpdata websubsub --indent 2 - Show all subscriptions.


pip install -r tests/requirements.txt

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

websubsub-0.9.3.tar.gz (20.2 kB view hashes)

Uploaded source

Built Distribution

websubsub-0.9.3-py3-none-any.whl (34.7 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page