Metadata-Version: 2.4
Name: py-timod
Version: 1.0.0
Summary: ThingsDB module builder
Home-page: https://github.com/thingsdb/py-timod
Author: Jeroen van der Heijden
Author-email: jeroen@transceptor.technology
License: GPLv3+
Keywords: database connector module builder
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Build Tools
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: msgpack
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: requires-dist
Dynamic: summary

[![CI](https://github.com/thingsdb/py-timod/workflows/CI/badge.svg)](https://github.com/thingsdb/py-timod/actions)
[![Release Version](https://img.shields.io/github/release/thingsdb/py-timod)](https://github.com/thingsdb/py-timod/releases)

# timod

Library for creating ThingsDB modules using the Python language

## Installation

```shell
$ pip install py-timod
```

## Usage

Modules for ThingsDB read from `stdin` and write a response back to `stdout`. Work by the module must be non-blocking.

If the module requires configuration data, for example a connection string, then this configuration will be send immediately after start-up but may be received again when the module configuration is changed in ThingsDB.

Do not use functions like `print` since these function will write to `stdout` and this is reserved for ThingsDB. Instead, use `logging...` to write to `stderr` instead.

The following code may be used as a template: (see: https://github.com/thingsdb/ThingsDB/tree/master/modules/python/demo.py)

```python
import logging
from typing import Any
from timod import start_module, TiHandler, LookupError


class Handler(TiHandler):

    async def on_config(self, cfg: Any):
        logging.info(cfg)

    async def on_request(self, req: dict[str, Any]):
        if 'message' not in req:
            raise LookupError('missing `message` in request')

        return req['message']


if __name__ == '__main__':
    start_module('demo', Handler())
```


