# Celery Tryton module

**URL:** <https://discuss.tryton.org/t/celery-tryton-module/739>\
**Category:** Third Party Modules\
**Created:** [September 16, 2018, 7:12am UTC](https://discuss.tryton.org/t/celery-tryton-module/739 "2018-09-16T07:12:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [September 16, 2018, 7:12am UTC](https://discuss.tryton.org/t/celery-tryton-module/739/1 "2018-09-16T07:12:57Z")

</div>

# celery\_tryton

- ✍ [B2CK](http://www.b2ck.com/)
- 📦 [celery\_tryton · PyPI](https://pypi.org/project/celery_tryton/)
- 🐛 [https://celery-tryton.b2ck.com/](https://celery-tryton.b2ck.com/)
- 🦎 4.0, 4.2, 4.4, 4.6, 4.8
- 🐍 2.7, 3.4, 3.5, 3.6

Celery integration with Tryton. It defines an abstract base Task class that runs inside a Tryton transaction. If the task is called from within a Tryton transaction, the context of this one will be automatically restored when the worker will execute it.  
Getting Started

Here is a simple application:

```
from celery import Celery
from celery_tryton import TrytonTask, celery_app
from trytond.pool import Pool

celery_app.conf.TRYTON_DATABASE = 'test'

@celery.task(base=TrytonTask)
def hello(user_id):
    User = Pool().get('res.user')
    user = User(user_id)
    return 'hello world, %s' % user.name

```

Configuration

All standard celery configuration options will work but in addition TRYTON\_DATABASE must be set to the default Tryton database name and optionally TRYTON\_CONFIG to load a specific configuration file.

The celery\_app will load the configuration from the config value from the section [celery] defined in the trytond configuration when used from a Tryton module.  
Example

Start a worker:

```
$ celery worker --app=examples.purchase_requests

```

Call generate\_all task:

```
$ celery call examples.purchase_requests.generate_all

```

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [November 24, 2022, 2:17pm UTC](https://discuss.tryton.org/t/celery-tryton-module/739/4 "2022-11-24T14:17:43Z")

</div>


