[Solved]-Can i use celery without django

13👍

Yes you can. Celery is a generic asynchronous task queue. In place of “django_project” you would point to your module. See http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html#application for an example.

Here is an example project layout using celery:

project-dir/
    mymodule/
         __init__.py 
         celery.py
         tasks.py
    tests/
    setup.py
    etc, etc (e.g. tox.ini, requirements.txt, project management files)

In mymodule/celery.py:

# -*- coding : utf-8 -*-
from __future__ import absolute_import

from celery import Celery

app = Celery('mymodule',
             broker='amqp://',
             backend='amqp://',
             include=['mymodule.tasks'])

if __name__ == '__main__':
    app.start()

In mymodule/tasks.py:

from __future__ import absolute_import

from mymodule.celery import app

@app.task
def add(x, y):
    return x + y
👤Thtu

4👍

You can definitely use Celery without using any web framework like Django or Flask. Just create the Celery object and your tasks accordingly and run the following command

celery -A filename.celery_object_name worker --loglevel=info

Later, just run the Python file. You don’t need to set anything. It works exactly with or without any Web Framework.

Leave a comment