Metadata-Version: 2.1
Name: django-aeotrade-connector
Version: 0.1.0rc3
Summary: A connector development framework adapted to Django
Author: hero
Author-email: wanghao@aeotrade.com
Requires-Python: >=3.10,<4
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: aio-pika (>=9.5.3,<10.0.0)
Requires-Dist: aiohttp (>=3.11.10,<4.0.0)
Requires-Dist: django-apscheduler (>=0.7.0,<0.8.0)
Requires-Dist: django-redis (>=5.4.0,<6.0.0)
Requires-Dist: djangorestframework (>=3.15.2,<4.0.0)
Requires-Dist: httpx (>=0.28.1,<0.29.0)
Requires-Dist: pydantic (>=2.10.3,<3.0.0)
Requires-Dist: requests (>=2.32.3,<3.0.0)
Requires-Dist: xmltodict (>=0.14.2,<0.15.0)
Description-Content-Type: text/markdown

# Overview

Django Aeotrade Connector is a framework that allows you to easily create your `connector`
with [Aeotrade OS](https://www.aeotrade.com/portal).

Latest version: [0.1.0rc2](https://pypi.org/project/django-aeotrade-connector/)

# Quickstart

## Install

```bash
pip install django-aeotrade-connector
```
After installing the package, you should add `aeotrade_connector` to django's `INSTALLED_APPS`

## Usage

### Initialize connector in django project

```bash
python manage.py initconnector
```

This will create `urls.py` and `dispatcher.py` to your project

### Create connector app

```bash
python manage.py startconnector <my_connector>
```

After executing this command, you should add `my_connector` to `INSTALLED_APPS` also. Then you will see a new django app named
`my_connector` in your django project.
In this app, you can see `services.py` and `task.py` python files. In `services.py`, you must implement some connector methods,
which are inherited from `ConnectorServices`. and in `task.py`, you can define your connector tasks. those tasks will be
registered when django setup.

### Configuration

In `app.py`:

Before you start to run your connector, you must configure your connector in the `app.py` file. The configuration file
is located in the `my_connector/app.py` file.

```Python
class MyConnectorConfig(AppConfig):
    name = 'my_connector'

    class Config:
        # required config
        connector = True
        connector_config_model = ConnectorBaseConfig(
            # required config
            label="my_first_connector",
            code="my_first_connector_code",
            mq_recv_model=MQManagerConfig(
                url="amqp://root:123456@localhost:5672/",
                exchange="test",
                queue="q_receive",
                pot=POT.Thread
            ),
            # optional config
            event_up_chain = True,
            files_up_chain = False,
            callback = some_function_name,
            callback_args = ['arg1', 'arg2'],
            callback_kwargs = {'key1': 'value1', 'key2': 'value2'},
            task_stop_when_error = False,
            auto_heartbeat = True,
            kw = {"extra_key": "extra_value"},
        )


```

In django.settings.py:

```Python
INSTALLED_APPS = [
    ...,
    'aeotrade_connector'
    'my_connector',
]

AC_MANAGEMENT_ENDPOINT = 'http://www.example.com:8000'

IS_TEST = False  # or True

# Redis is used to implement a distributed lock, ensuring that the scheduled task
# is executed only once even when multiple workers are started.
CACHES = {
    'default': {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": 'redis://localhost:6379/0',
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
            "CONNECTION_POOL_KWARGS": {"max_connections": 100}
        }
    }
}
```

