Skip to main content

A Publish and Subscribe library for Celery

Project description

celery-pubsub 0.1.9

https://travis-ci.org/Mulugruntz/celery-pubsub.svg?branch=master Code Climate Test Coverage Issue Count Downloads

Publish and Subscribe with Celery

Basic usage:

import celery
import celery_pubsub

@celery.task
def my_task_1(*args, **kwargs):
    return "task 1 done"


@celery.task
def my_task_2(*args, **kwargs):
    return "task 2 done"


# First, let's subscribe
celery_pubsub.subscribe('some.topic', my_task_1)
celery_pubsub.subscribe('some.topic', my_task_2)

# Now, let's publish something
res = celery_pubsub.publish('some.topic', data='something', value=42)

# We can get the results if we want to (and if the tasks returned something)
# But in pub/sub, usually, there's no result.
print(res.get())

# This will get nowhere, as no task subscribed to this topic
res = celery_pubsub.publish('nowhere', data='something else', value=23)

Advanced usage:

Wildcards can be used in topic names:

  • * matches any one group
    • some.*.test will match some.awesome.test, some.random.test but not some.pretty.cool.test, elsewhere or here.some.up.test

    • some.* will match some.test and some.thing but it won’t match some or some.testy.test

  • # matches any number of groups
    • some.#.test will match some.awesome.test, some.random.test, some.pretty.cool.test but not elsewhere or here.some.up.test

    • some.# will match anything that starts with some., such as some.very.specific.topic.indeed

    • # will match anything

# Let's subscribe
celery_pubsub.subscribe('some.*', my_task_1)
celery_pubsub.subscribe('some.*.test', my_task_2)
celery_pubsub.subscribe('some.#', my_task_3)
celery_pubsub.subscribe('#', my_task_4)
celery_pubsub.subscribe('some.beep', my_task_5)
# it's okay to have more than one task on the same topic
celery_pubsub.subscribe('some.beep', my_task_6)

# Let's publish
celery_pubsub.publish('nowhere', 4)               # task 4 only
celery_pubsub.publish('some', 8)                  # task 4 only
celery_pubsub.publish('some.thing', 15)           # tasks 1, 3 and 4
celery_pubsub.publish('some.true.test', 16)       # tasks 2, 3 and 4
celery_pubsub.publish('some.beep', 23)            # tasks 1, 3, 4, 5 and 6
celery_pubsub.publish('some.very.good.test', 42)  # tasks 3 and 4

# And if you want to publish synchronously:
celery_pubsub.publish_now('some.very.good.test', 42)  # tasks 3 and 4

# You can unsubscribe too
celery_pubsub.unsubscribe('#', my_task_4)

# Now, task 4 will not be called anymore
celery_pubsub.publish('some.very.good.test', 42)  # task 3 only

Changelog:

  • 0.1.9
    • Added Python 3.4, 3.5, 3.7, and multiple branches of pypy

    • Pinned requirements’ dependency versions.
      • celery 4.1.0 -> 4.2.1

      • kombu 4.1.0 -> 4.2.1

      • billiard 3.5.0 -> 3.5.0.4

      • nose pinned to 1.3.7

      • coverage pinned to 4.3.4 (was already 4.3.4 but fuzzy)

      • codeclimate-test-reported pinned to 0.2.3

    • Extra badge to show the number of downloads (thanks to PePy)

  • 0.1.8
    • Fixup for broken pip install celery_pubsub==0.1.7

  • 0.1.7
    • PyPI long description fixed

    • Removed README.md and fixed README.rst

    • Added command python setup.py test to run unit tests with coverage

    • pypy support

  • 0.1.5
    • Python 3 support

  • 0.1.1
    • Added README

    • Refined setup

    • No need to access celery_pubsub.pubsub anymore. Direct access in celery_pubsub.

    • Tests moved out of package

    • Added Travis for CI

  • 0.1
    • Initial version

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

celery-pubsub-0.1.9.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

celery_pubsub-0.1.9-py2-none-any.whl (3.9 kB view details)

Uploaded Python 2

File details

Details for the file celery-pubsub-0.1.9.tar.gz.

File metadata

  • Download URL: celery-pubsub-0.1.9.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.13

File hashes

Hashes for celery-pubsub-0.1.9.tar.gz
Algorithm Hash digest
SHA256 de7033d4505c6ff971fd946129f287954e339c0a3365f73a81edab357a08e034
MD5 6d703745a92ae9830e0c5a7a0f6e7551
BLAKE2b-256 36f3469dcc1ee72610b2227b3a900ca1cea96c4b98dc5cc50a6296b3c420b61b

See more details on using hashes here.

File details

Details for the file celery_pubsub-0.1.9-py2-none-any.whl.

File metadata

  • Download URL: celery_pubsub-0.1.9-py2-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.13

File hashes

Hashes for celery_pubsub-0.1.9-py2-none-any.whl
Algorithm Hash digest
SHA256 37f998fd6eb9972f3f7f10a11e28890c4b6ee88d75dcb5ff8c583637f8e3d845
MD5 d9558e39b77b8e44bfdfc2dd8365ab42
BLAKE2b-256 816b00251c2ea19f08069768cf2c629b8adfbfc87b26f7dd7b3758d05a89f10e

See more details on using hashes here.

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