Flask-Celery-Helper


NameFlask-Celery-Helper JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/Robpol86/Flask-Celery-Helper
SummaryCelery support for Flask without breaking PyCharm inspections.
upload_time2014-12-29 04:10:33
maintainerNone
docs_urlNone
author@Robpol86
requires_pythonNone
licenseMIT
keywords flask celery redis
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            Flask-Celery-Helper
===================

Even though the `Flask documentation <http://flask.pocoo.org/docs/patterns/celery/>`_ says Celery extensions are
unnecessary now, I found that I still need an extension to properly use Celery in large Flask applications. Specifically
I need an init_app() method to initialize Celery after I instantiate it.

This extension also comes with a ``single_instance`` method.

* Python 2.6, 2.7, 3.3, and 3.4 supported on Linux and OS X.
* Python 2.7, 3.3, and 3.4 supported on Windows (both 32 and 64 bit versions of Python).

.. image:: https://img.shields.io/appveyor/ci/Robpol86/Flask-Celery-Helper.svg?style=flat-square
   :target: https://ci.appveyor.com/project/Robpol86/Flask-Celery-Helper
   :alt: Build Status Windows

.. image:: https://img.shields.io/travis/Robpol86/Flask-Celery-Helper/master.svg?style=flat-square
   :target: https://travis-ci.org/Robpol86/Flask-Celery-Helper
   :alt: Build Status

.. image:: https://img.shields.io/codecov/c/github/Robpol86/Flask-Celery-Helper/master.svg?style=flat-square
   :target: https://codecov.io/github/Robpol86/Flask-Celery-Helper
   :alt: Coverage Status

.. image:: https://img.shields.io/pypi/v/Flask-Celery-Helper.svg?style=flat-square
   :target: https://pypi.python.org/pypi/Flask-Celery-Helper/
   :alt: Latest Version

.. image:: https://img.shields.io/pypi/dm/Flask-Celery-Helper.svg?style=flat-square
   :target: https://pypi.python.org/pypi/Flask-Celery-Helper/
   :alt: Downloads

Attribution
-----------

Single instance decorator inspired by
`Ryan Roemer <http://loose-bits.com/2010/10/distributed-task-locking-in-celery.html>`_.

Supported Platforms
-------------------

* OSX and Linux.
* Python 2.6, 2.7, 3.3, 3.4
* `Flask <http://flask.pocoo.org/>`_ 0.10.1
* `Redis <http://redis.io/>`_ 2.9.1
* `Celery <http://www.celeryproject.org/>`_ 3.1.11

Quickstart
----------

Install:

.. code:: bash

    pip install Flask-Celery-Helper


Example:

.. code:: python

    # example.py
    from flask import Flask
    from flask.ext.celery import Celery
    
    app = Flask('example')
    app.config['CELERY_BROKER_URL'] = 'redis://localhost'
    app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost'
    celery = Celery(app)
    
    @celery.task()
    def add_together(a, b):
        return a + b
    
    if __name__ == '__main__':
        result = add_together.delay(23, 42)
        print(result.get())


Run these two commands in separate terminals:

.. code:: bash

    celery -A example.celery worker
    python example.py


Factory Example
---------------

.. code:: python

    # extensions.py
    from flask.ext.celery import Celery
    
    celery = Celery()


.. code:: python

    # application.py
    from flask import Flask
    from extensions import celery
    
    def create_app():
        app = Flask(__name__)
        app.config['CELERY_IMPORTS'] = ('tasks.add_together', )
        app.config['CELERY_BROKER_URL'] = 'redis://localhost'
        app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost'
        celery.init_app(app)
        return app


.. code:: python

    # tasks.py
    from extensions import celery
    
    @celery.task()
    def add_together(a, b):
        return a + b


.. code:: python

    # manage.py
    from application import create_app
    
    app = create_app()
    app.run()


Single Instance Example
-----------------------

.. code:: python

    # example.py
    import time
    from flask import Flask
    from flask.ext.celery import Celery, single_instance
    from flask.ext.redis import Redis
    
    app = Flask('example')
    app.config['REDIS_URL'] = 'redis://localhost'
    app.config['CELERY_BROKER_URL'] = 'redis://localhost'
    app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost'
    celery = Celery(app)
    Redis(app)
    
    @celery.task(bind=True)
    @single_instance
    def sleep_one_second(a, b):
        time.sleep(1)
        return a + b
    
    if __name__ == '__main__':
        task1 = sleep_one_second.delay(23, 42)
        time.sleep(0.1)
        task2 = sleep_one_second.delay(20, 40)
        results1 = task1.get(propagate=False)
        results2 = task2.get(propagate=False)
        print(results1)  # 65
        if isinstance(results2, Exception) and str(results2) == 'Failed to acquire lock.':
            print('Another instance is already running.')
        else:
            print(results2)  # Should not happen.


Changelog
---------

1.1.0
`````

* Added Windows support.
* ``CELERY_RESULT_BACKEND`` no longer mandatory.
* ``single_instance`` supported on SQLite/MySQL/PostgreSQL in addition to Redis.
* Breaking changes: ``flask.ext.celery.CELERY_LOCK`` moved to ``flask.ext.celery._LockManagerRedis.CELERY_LOCK``.

1.0.0
`````

* Support for non-Redis backends.

0.2.2
`````

* Added Python 2.6 and 3.x support.

0.2.1
`````

* Fixed ``single_instance`` arguments with functools.

0.2.0
`````

* Added include_args argument to ``single_instance``.

0.1.0
`````

* Initial release.
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Robpol86/Flask-Celery-Helper",
    "name": "Flask-Celery-Helper",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "flask celery redis",
    "author": "@Robpol86",
    "author_email": "robpol86@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/71/f5/3631b71ac28d9b691ff2e2371a95121be18c742c963098635c11cf4a254f/Flask-Celery-Helper-1.1.0.tar.gz",
    "platform": "UNKNOWN",
    "description": "Flask-Celery-Helper\n===================\n\nEven though the `Flask documentation <http://flask.pocoo.org/docs/patterns/celery/>`_ says Celery extensions are\nunnecessary now, I found that I still need an extension to properly use Celery in large Flask applications. Specifically\nI need an init_app() method to initialize Celery after I instantiate it.\n\nThis extension also comes with a ``single_instance`` method.\n\n* Python 2.6, 2.7, 3.3, and 3.4 supported on Linux and OS X.\n* Python 2.7, 3.3, and 3.4 supported on Windows (both 32 and 64 bit versions of Python).\n\n.. image:: https://img.shields.io/appveyor/ci/Robpol86/Flask-Celery-Helper.svg?style=flat-square\n   :target: https://ci.appveyor.com/project/Robpol86/Flask-Celery-Helper\n   :alt: Build Status Windows\n\n.. image:: https://img.shields.io/travis/Robpol86/Flask-Celery-Helper/master.svg?style=flat-square\n   :target: https://travis-ci.org/Robpol86/Flask-Celery-Helper\n   :alt: Build Status\n\n.. image:: https://img.shields.io/codecov/c/github/Robpol86/Flask-Celery-Helper/master.svg?style=flat-square\n   :target: https://codecov.io/github/Robpol86/Flask-Celery-Helper\n   :alt: Coverage Status\n\n.. image:: https://img.shields.io/pypi/v/Flask-Celery-Helper.svg?style=flat-square\n   :target: https://pypi.python.org/pypi/Flask-Celery-Helper/\n   :alt: Latest Version\n\n.. image:: https://img.shields.io/pypi/dm/Flask-Celery-Helper.svg?style=flat-square\n   :target: https://pypi.python.org/pypi/Flask-Celery-Helper/\n   :alt: Downloads\n\nAttribution\n-----------\n\nSingle instance decorator inspired by\n`Ryan Roemer <http://loose-bits.com/2010/10/distributed-task-locking-in-celery.html>`_.\n\nSupported Platforms\n-------------------\n\n* OSX and Linux.\n* Python 2.6, 2.7, 3.3, 3.4\n* `Flask <http://flask.pocoo.org/>`_ 0.10.1\n* `Redis <http://redis.io/>`_ 2.9.1\n* `Celery <http://www.celeryproject.org/>`_ 3.1.11\n\nQuickstart\n----------\n\nInstall:\n\n.. code:: bash\n\n    pip install Flask-Celery-Helper\n\n\nExample:\n\n.. code:: python\n\n    # example.py\n    from flask import Flask\n    from flask.ext.celery import Celery\n    \n    app = Flask('example')\n    app.config['CELERY_BROKER_URL'] = 'redis://localhost'\n    app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost'\n    celery = Celery(app)\n    \n    @celery.task()\n    def add_together(a, b):\n        return a + b\n    \n    if __name__ == '__main__':\n        result = add_together.delay(23, 42)\n        print(result.get())\n\n\nRun these two commands in separate terminals:\n\n.. code:: bash\n\n    celery -A example.celery worker\n    python example.py\n\n\nFactory Example\n---------------\n\n.. code:: python\n\n    # extensions.py\n    from flask.ext.celery import Celery\n    \n    celery = Celery()\n\n\n.. code:: python\n\n    # application.py\n    from flask import Flask\n    from extensions import celery\n    \n    def create_app():\n        app = Flask(__name__)\n        app.config['CELERY_IMPORTS'] = ('tasks.add_together', )\n        app.config['CELERY_BROKER_URL'] = 'redis://localhost'\n        app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost'\n        celery.init_app(app)\n        return app\n\n\n.. code:: python\n\n    # tasks.py\n    from extensions import celery\n    \n    @celery.task()\n    def add_together(a, b):\n        return a + b\n\n\n.. code:: python\n\n    # manage.py\n    from application import create_app\n    \n    app = create_app()\n    app.run()\n\n\nSingle Instance Example\n-----------------------\n\n.. code:: python\n\n    # example.py\n    import time\n    from flask import Flask\n    from flask.ext.celery import Celery, single_instance\n    from flask.ext.redis import Redis\n    \n    app = Flask('example')\n    app.config['REDIS_URL'] = 'redis://localhost'\n    app.config['CELERY_BROKER_URL'] = 'redis://localhost'\n    app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost'\n    celery = Celery(app)\n    Redis(app)\n    \n    @celery.task(bind=True)\n    @single_instance\n    def sleep_one_second(a, b):\n        time.sleep(1)\n        return a + b\n    \n    if __name__ == '__main__':\n        task1 = sleep_one_second.delay(23, 42)\n        time.sleep(0.1)\n        task2 = sleep_one_second.delay(20, 40)\n        results1 = task1.get(propagate=False)\n        results2 = task2.get(propagate=False)\n        print(results1)  # 65\n        if isinstance(results2, Exception) and str(results2) == 'Failed to acquire lock.':\n            print('Another instance is already running.')\n        else:\n            print(results2)  # Should not happen.\n\n\nChangelog\n---------\n\n1.1.0\n`````\n\n* Added Windows support.\n* ``CELERY_RESULT_BACKEND`` no longer mandatory.\n* ``single_instance`` supported on SQLite/MySQL/PostgreSQL in addition to Redis.\n* Breaking changes: ``flask.ext.celery.CELERY_LOCK`` moved to ``flask.ext.celery._LockManagerRedis.CELERY_LOCK``.\n\n1.0.0\n`````\n\n* Support for non-Redis backends.\n\n0.2.2\n`````\n\n* Added Python 2.6 and 3.x support.\n\n0.2.1\n`````\n\n* Fixed ``single_instance`` arguments with functools.\n\n0.2.0\n`````\n\n* Added include_args argument to ``single_instance``.\n\n0.1.0\n`````\n\n* Initial release.",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Celery support for Flask without breaking PyCharm inspections.",
    "version": "1.1.0",
    "project_urls": {
        "Download": "UNKNOWN",
        "Homepage": "https://github.com/Robpol86/Flask-Celery-Helper"
    },
    "split_keywords": [
        "flask",
        "celery",
        "redis"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "71f53631b71ac28d9b691ff2e2371a95121be18c742c963098635c11cf4a254f",
                "md5": "1850fa43dff0c909cbde348e83be5bed",
                "sha256": "454d4a989c82894be30e5d764341e9f16bb2cedfb2a7f9d5edc67c09e195f8c5"
            },
            "downloads": -1,
            "filename": "Flask-Celery-Helper-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1850fa43dff0c909cbde348e83be5bed",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7874,
            "upload_time": "2014-12-29T04:10:33",
            "upload_time_iso_8601": "2014-12-29T04:10:33.999667Z",
            "url": "https://files.pythonhosted.org/packages/71/f5/3631b71ac28d9b691ff2e2371a95121be18c742c963098635c11cf4a254f/Flask-Celery-Helper-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2014-12-29 04:10:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Robpol86",
    "github_project": "Flask-Celery-Helper",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "appveyor": true,
    "tox": true,
    "lcname": "flask-celery-helper"
}
        
Elapsed time: 0.17270s