django-temporalio


Namedjango-temporalio JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/RegioHelden/django-temporalio
SummaryTemporal.io integration for Django
upload_time2024-05-30 16:39:03
maintainerNone
docs_urlNone
authorRegioHelden GmbH
requires_python>=3.11
licenseMIT
keywords django temporal.io temporal
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-temporalio
___

A small Django app that provides helpers for integrating [Temporal.io](https://temporal.io/) with Django.

## Features

- Registry: Provides a registry that holds mappings between queue names and registered activities and workflows.
- Management Commands: Includes management commands to manage Temporal.io workers and sync schedules.

## Installation

You can install `django_temporalio` using pip:

```bash
$ pip install django-temporalio
```

Add `django_temporalio` to your `INSTALLED_APPS`:

```python
INSTALLED_APPS = [
    ...
    'django_temporalio.apps.DjangoTemporalioConfig',
    ...
]
```

Add the following settings to your `settings.py`:

```python
from temporalio.worker import WorkerConfig

DJANGO_TEMPORALIO = {
    "URL": "localhost:7233",
    "BASE_MODULE": "path.to.module",
    "WORKER_CONFIGS": {
        "main": WorkerConfig(
            task_queue="MAIN_TASK_QUEUE",
            ...
        ),
        ...
    },
}
```

## Usage

Activities, workflows and schedules should be placed inside the base module defined by the `BASE_MODULE` setting, 
preferably outside of any Django application, in order to keep the uses of 
the [imports_passed_through](https://python.temporal.io/temporalio.workflow.unsafe.html) context manager encapsulated 
inside the module, along with Temporal.io related code.

### Workflow and Activity Registry

The registry is a singleton that holds mappings between queue names and registered activities and workflows.
You can register activities and workflows using the `register` method. 

Activities and workflows should be declared in modules matching the following patterns `*workflows*.py` and 
`*activities*.py` respectively. 

```python
from temporalio import activity, workflow
from django_temporalio.registry import queue_activities, queue_workflows

@queue_activities.register("HIGH_PRIORITY_TASK_QUEUE", "MAIN_TASK_QUEUE")
@activity.defn
def my_activity():
    pass

@queue_workflows.register("HIGH_PRIORITY_TASK_QUEUE", "MAIN_TASK_QUEUE")
@workflow.defn
class MyWorkflow:
    pass
```

### Schedule Registry

You can register schedules using the `register` method. 

Schedules should be declared in `schedules.py` module.

```python
from django_temporalio.registry import schedules
from temporalio.client import Schedule


schedules.register("do-cool-stuff-every-hour", Schedule(...))
```

### Management Commands

To see a queue's registered activities and workflows:

```bash
$ ./manage.py show_temporalio_queue_registry
```

To start a worker defined in the settings (for production):

```bash
$ ./manage.py start_temporalio_worker <worker_name>
```

To start a worker for development (starts a worker for each registered queue, WORKER_CONFIGS setting is ignored):

```bash
$ ./manage.py start_temporalio_worker --all
```

To sync schedules with Temporal.io:

```bash
$ ./manage.py sync_temporalio_schedules
```

To see what sync operation would do without actually syncing:

```bash
$ ./manage.py sync_temporal_schedules --dry-run
```

## Configuration

You can configure the app using the following settings:

DJANGO_TEMPORALIO: A dictionary containing the following keys:

- URL: The Temporal.io host to connect to, defaults to `http://localhost:7233`
- NAMESPACE: The Temporal.io namespace to use, defaults to `default`
- WORKER_CONFIGS: A dictionary containing worker configurations. 
  The key is the worker name and the value is a `WorkerConfig` instance.
- BASE_MODULE: A python module that holds workflows, activities and schedules, defaults to `None`


## 1.0.0 (2024-05-16)

* Initial release

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/RegioHelden/django-temporalio",
    "name": "django-temporalio",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "django, temporal.io, temporal",
    "author": "RegioHelden GmbH",
    "author_email": "opensource@regiohelden.de",
    "download_url": "https://files.pythonhosted.org/packages/21/20/294b64ddbe3858776543a95a9f9f2ae5474e3ad869c576ba0396a0604a1d/django_temporalio-1.1.0.tar.gz",
    "platform": null,
    "description": "# django-temporalio\n___\n\nA small Django app that provides helpers for integrating [Temporal.io](https://temporal.io/) with Django.\n\n## Features\n\n- Registry: Provides a registry that holds mappings between queue names and registered activities and workflows.\n- Management Commands: Includes management commands to manage Temporal.io workers and sync schedules.\n\n## Installation\n\nYou can install `django_temporalio` using pip:\n\n```bash\n$ pip install django-temporalio\n```\n\nAdd `django_temporalio` to your `INSTALLED_APPS`:\n\n```python\nINSTALLED_APPS = [\n    ...\n    'django_temporalio.apps.DjangoTemporalioConfig',\n    ...\n]\n```\n\nAdd the following settings to your `settings.py`:\n\n```python\nfrom temporalio.worker import WorkerConfig\n\nDJANGO_TEMPORALIO = {\n    \"URL\": \"localhost:7233\",\n    \"BASE_MODULE\": \"path.to.module\",\n    \"WORKER_CONFIGS\": {\n        \"main\": WorkerConfig(\n            task_queue=\"MAIN_TASK_QUEUE\",\n            ...\n        ),\n        ...\n    },\n}\n```\n\n## Usage\n\nActivities, workflows and schedules should be placed inside the base module defined by the `BASE_MODULE` setting, \npreferably outside of any Django application, in order to keep the uses of \nthe [imports_passed_through](https://python.temporal.io/temporalio.workflow.unsafe.html) context manager encapsulated \ninside the module, along with Temporal.io related code.\n\n### Workflow and Activity Registry\n\nThe registry is a singleton that holds mappings between queue names and registered activities and workflows.\nYou can register activities and workflows using the `register` method. \n\nActivities and workflows should be declared in modules matching the following patterns `*workflows*.py` and \n`*activities*.py` respectively. \n\n```python\nfrom temporalio import activity, workflow\nfrom django_temporalio.registry import queue_activities, queue_workflows\n\n@queue_activities.register(\"HIGH_PRIORITY_TASK_QUEUE\", \"MAIN_TASK_QUEUE\")\n@activity.defn\ndef my_activity():\n    pass\n\n@queue_workflows.register(\"HIGH_PRIORITY_TASK_QUEUE\", \"MAIN_TASK_QUEUE\")\n@workflow.defn\nclass MyWorkflow:\n    pass\n```\n\n### Schedule Registry\n\nYou can register schedules using the `register` method. \n\nSchedules should be declared in `schedules.py` module.\n\n```python\nfrom django_temporalio.registry import schedules\nfrom temporalio.client import Schedule\n\n\nschedules.register(\"do-cool-stuff-every-hour\", Schedule(...))\n```\n\n### Management Commands\n\nTo see a queue's registered activities and workflows:\n\n```bash\n$ ./manage.py show_temporalio_queue_registry\n```\n\nTo start a worker defined in the settings (for production):\n\n```bash\n$ ./manage.py start_temporalio_worker <worker_name>\n```\n\nTo start a worker for development (starts a worker for each registered queue, WORKER_CONFIGS setting is ignored):\n\n```bash\n$ ./manage.py start_temporalio_worker --all\n```\n\nTo sync schedules with Temporal.io:\n\n```bash\n$ ./manage.py sync_temporalio_schedules\n```\n\nTo see what sync operation would do without actually syncing:\n\n```bash\n$ ./manage.py sync_temporal_schedules --dry-run\n```\n\n## Configuration\n\nYou can configure the app using the following settings:\n\nDJANGO_TEMPORALIO: A dictionary containing the following keys:\n\n- URL: The Temporal.io host to connect to, defaults to `http://localhost:7233`\n- NAMESPACE: The Temporal.io namespace to use, defaults to `default`\n- WORKER_CONFIGS: A dictionary containing worker configurations. \n  The key is the worker name and the value is a `WorkerConfig` instance.\n- BASE_MODULE: A python module that holds workflows, activities and schedules, defaults to `None`\n\n\n## 1.0.0 (2024-05-16)\n\n* Initial release\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Temporal.io integration for Django",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/RegioHelden/django-temporalio"
    },
    "split_keywords": [
        "django",
        " temporal.io",
        " temporal"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "08ead23dffa33acf35ccc7b13f8f433590fb121d6a53ce5eb2ef3d1beffa2388",
                "md5": "a7ad4f16094b32350c9705fe26963b32",
                "sha256": "a37db0f511a3219a497e9b1eaa34a60b6a6f05bd78eb2ce36072f7be87fd2789"
            },
            "downloads": -1,
            "filename": "django_temporalio-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a7ad4f16094b32350c9705fe26963b32",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 10480,
            "upload_time": "2024-05-30T16:39:02",
            "upload_time_iso_8601": "2024-05-30T16:39:02.178587Z",
            "url": "https://files.pythonhosted.org/packages/08/ea/d23dffa33acf35ccc7b13f8f433590fb121d6a53ce5eb2ef3d1beffa2388/django_temporalio-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2120294b64ddbe3858776543a95a9f9f2ae5474e3ad869c576ba0396a0604a1d",
                "md5": "46d3d40f5cd1421f239e3da8b6ccfe5b",
                "sha256": "ad1ce72772fe45f68533871dacd801f2ab00f718d2c51cb61d1fda7eae32a914"
            },
            "downloads": -1,
            "filename": "django_temporalio-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "46d3d40f5cd1421f239e3da8b6ccfe5b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 9297,
            "upload_time": "2024-05-30T16:39:03",
            "upload_time_iso_8601": "2024-05-30T16:39:03.373679Z",
            "url": "https://files.pythonhosted.org/packages/21/20/294b64ddbe3858776543a95a9f9f2ae5474e3ad869c576ba0396a0604a1d/django_temporalio-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-30 16:39:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "RegioHelden",
    "github_project": "django-temporalio",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "django-temporalio"
}
        
Elapsed time: 0.26790s