{"id":13502101,"url":"https://github.com/Robpol86/Flask-Celery-Helper","last_synced_at":"2025-03-29T10:32:46.030Z","repository":{"id":17568525,"uuid":"20371920","full_name":"Robpol86/Flask-Celery-Helper","owner":"Robpol86","description":"Celery support for Flask without breaking PyCharm inspections.","archived":true,"fork":false,"pushed_at":"2018-06-18T04:38:59.000Z","size":72,"stargazers_count":151,"open_issues_count":6,"forks_count":30,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-01T17:18:27.300Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Robpol86.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-01T06:10:56.000Z","updated_at":"2024-06-28T14:40:34.000Z","dependencies_parsed_at":"2022-08-31T02:50:26.757Z","dependency_job_id":null,"html_url":"https://github.com/Robpol86/Flask-Celery-Helper","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robpol86%2FFlask-Celery-Helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robpol86%2FFlask-Celery-Helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robpol86%2FFlask-Celery-Helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robpol86%2FFlask-Celery-Helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Robpol86","download_url":"https://codeload.github.com/Robpol86/Flask-Celery-Helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246174207,"owners_count":20735406,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T22:02:01.880Z","updated_at":"2025-03-29T10:32:45.576Z","avatar_url":"https://github.com/Robpol86.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"===================\nFlask-Celery-Helper\n===================\n\nEven though the `Flask documentation \u003chttp://flask.pocoo.org/docs/patterns/celery/\u003e`_ 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, PyPy, 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/master.svg?style=flat-square\u0026label=AppVeyor%20CI\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\u0026label=Travis%20CI\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\u0026label=Codecov\n    :target: https://codecov.io/gh/Robpol86/Flask-Celery-Helper\n    :alt: Coverage Status\n\n.. image:: https://img.shields.io/pypi/v/Flask-Celery-Helper.svg?style=flat-square\u0026label=Latest\n    :target: https://pypi.python.org/pypi/Flask-Celery-Helper\n    :alt: Latest Version\n\nAttribution\n===========\n\nSingle instance decorator inspired by\n`Ryan Roemer \u003chttp://loose-bits.com/2010/10/distributed-task-locking-in-celery.html\u003e`_.\n\nSupported Libraries\n===================\n\n* `Flask \u003chttp://flask.pocoo.org/\u003e`_ 0.12\n* `Redis \u003chttp://redis.io/\u003e`_ 3.2.6\n* `Celery \u003chttp://www.celeryproject.org/\u003e`_ 3.1.11\n\nQuickstart\n==========\n\nInstall:\n\n.. code:: bash\n\n    pip install Flask-Celery-Helper\n\nExamples\n========\n\nBasic Example\n-------------\n\n.. code:: python\n\n    # example.py\n    from flask import Flask\n    from flask_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\nRun these two commands in separate terminals:\n\n.. code:: bash\n\n    celery -A example.celery worker\n    python example.py\n\nFactory Example\n---------------\n\n.. code:: python\n\n    # extensions.py\n    from flask_celery import Celery\n\n    celery = Celery()\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.. 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.. code:: python\n\n    # manage.py\n    from application import create_app\n\n    app = create_app()\n    app.run()\n\nSingle Instance Example\n-----------------------\n\n.. code:: python\n\n    # example.py\n    import time\n    from flask import Flask\n    from flask_celery import Celery, single_instance\n    from flask_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.. changelog-section-start\n\nChangelog\n=========\n\nThis project adheres to `Semantic Versioning \u003chttp://semver.org/\u003e`_.\n\nUnreleased\n----------\n\nChanged\n    * Supporting Flask 0.12, switching from ``flask.ext.celery`` to ``flask_celery`` import recommendation.\n\n1.1.0 - 2014-12-28\n------------------\n\nAdded\n    * Windows support.\n    * ``single_instance`` supported on SQLite/MySQL/PostgreSQL in addition to Redis.\n\nChanged\n    * ``CELERY_RESULT_BACKEND`` no longer mandatory.\n    * Breaking changes: ``flask.ext.celery.CELERY_LOCK`` moved to ``flask.ext.celery._LockManagerRedis.CELERY_LOCK``.\n\n1.0.0 - 2014-11-01\n------------------\n\nAdded\n    * Support for non-Redis backends.\n\n0.2.2 - 2014-08-11\n------------------\n\nAdded\n    * Python 2.6 and 3.x support.\n\n0.2.1 - 2014-06-18\n------------------\n\nFixed\n    * ``single_instance`` arguments with functools.\n\n0.2.0 - 2014-06-18\n------------------\n\nAdded\n    * ``include_args`` argument to ``single_instance``.\n\n0.1.0 - 2014-06-01\n------------------\n\n* Initial release.\n\n.. changelog-section-end\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobpol86%2FFlask-Celery-Helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRobpol86%2FFlask-Celery-Helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobpol86%2FFlask-Celery-Helper/lists"}