smarterai


Namesmarterai JSON
Version 1.9.0 PyPI version JSON
download
home_pagehttps://www.smarter.ai/
Summarysmarter.ai Python API
upload_time2024-02-14 11:49:53
maintainer
docs_urlNone
authorNevine Soliman and Carlos Medina
requires_python>=3
license
keywords machine learning artificial intelligence
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/)
[![PyPi version](https://badgen.net/pypi/v/pip/)](https://pypi.org/project/pip/)

# Smarter API for Python

This API allows communication between any python based Component on the [smarter.ai](https://www.smarter.ai/)
platform.

## User Installation

The latest released version are available at the Python Package Index (PyPI).

To install using pip:

```bash
pip install smarterai
```

## Usage

- For starters an account needs to be created at our platform. So visit our website and create an account
  at [smarter.ai](https://www.smarter.ai/).

- Then in order for the python code to be accessible for the [smarter.ai](https://www.smarter.ai/) platform, follow
  these steps:
    1. Visit the [Studio](https://studio.smarter.ai/digital_twin)
    2. Start a new [new Experiment](https://studio.smarter.ai/digital_twin/newExperiment)
    3. Chose a Full Pipeline Template.
    4. Follow the wizard.
    5. Go to Build -> Experiment Editor.
    6. From _Container: Environment_ Drag & drop a python component.
    7. From _Blank: Starter Templates_ Drag & drop Python Code Template on top of the added Environment component.
    8. Double-click on the Python Code Template newly added Component.
    9. Edit/upload your code there.

- You can then start building your code by copy-pasting the code found in the examples below.

- The Python Component's interface needs to consist of the following:
    1. Imports:
  ```python
  from typing import Optional
  from smarterai import SmarterApp, SmarterMessage, SmarterApi
  ```
    2. A class called ```SmarterComponent```.
    2. ```SmarterComponent``` should inherit from ```SmarterApp```:
  ```python
  class SmarterComponent(SmarterApp):
  ```
    3. The class should have a method ```invoke``` with the following signature:
  ```python
  def invoke(self, port: str, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:
  ```

### Example 1

This is the basic interface for a python based component.

```python
from typing import Optional
from smarterai import SmarterApp, SmarterMessage, SmarterApi


class SmarterComponent(SmarterApp):
    def invoke(self, port: str, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:
        print(f"Received the message '{message}' on port '{port}'")
        return
```

### Example 2

If your component needs initializing/booting before it starts running. Then a method ```boot``` needs to be defined.

```python
from typing import Optional
from smarterai import SmarterApp, SmarterMessage, SmarterApi


class SmarterComponent(SmarterApp):
    def __init__(self):
        self.port_fn_mapper = {'boot': self.boot}

    def boot(self, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:
        # Write code here
        return

    def invoke(self, port: str, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:
        print(f"Received the message '{message}' on port '{port}'")
        if port in self.port_fn_mapper:
            self.port_fn_mapper[port](message, smarter_api)
        return
```

### Example 3

If your component needs to send messages to other components, then you can use smarter_api.

```python
from typing import Optional
from smarterai import SmarterApp, SmarterMessage, SmarterApi


class SmarterComponent(SmarterApp):
    def __init__(self):
        self.port_fn_mapper = {'boot': self.boot, 'start': self.start}

    def boot(self, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:
        # Write code here
        return

    def start(self, message: SmarterMessage, smarter_api: SmarterApi) -> None:
        port = 'out'
        user_id = message.get('userId')
        new_message = SmarterMessage({'name': f'Smarter AI Welcomes {user_id}'})
        smarter_api.send_message(message=new_message, port=port)

    def invoke(self, port: str, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:
        print(f"Received the message '{message}' on port '{port}'")
        if port in self.port_fn_mapper:
            self.port_fn_mapper[port](message, smarter_api)
        return
```

### Example 4

If your component needs to set data to front-end patterns.

```python
from typing import Optional
from smarterai import SmarterApp, SmarterMessage, SmarterApi


class SmarterComponent(SmarterApp):
    def __init__(self):
        self.port_fn_mapper = {'boot': self.boot, 'start': self.start}

    def boot(self, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:
        # Write code here
        return

    def start(self, message: SmarterMessage, smarter_api: SmarterApi) -> None:
        pattern = "text_field"
        data = 'some value'
        smarter_api.set_data(pattern=pattern, data=data)

    def invoke(self, port: str, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:
        print(f"Received the message '{message}' on port '{port}'")
        if port in self.port_fn_mapper:
            self.port_fn_mapper[port](message, smarter_api)
        return
```

## Credits

Authored by Nevine Soliman and Carlos Medina (smarter.ai - All rights reserved)
            

Raw data

            {
    "_id": null,
    "home_page": "https://www.smarter.ai/",
    "name": "smarterai",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": "",
    "keywords": "machine learning,artificial intelligence",
    "author": "Nevine Soliman and Carlos Medina",
    "author_email": "dev@smarter.ai",
    "download_url": "https://files.pythonhosted.org/packages/f4/8e/5840034391d79cf036f980f6c60d499776ffd598ee2a8ed62d0321497d40/smarterai-1.9.0.tar.gz",
    "platform": null,
    "description": "[![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/)\n[![PyPi version](https://badgen.net/pypi/v/pip/)](https://pypi.org/project/pip/)\n\n# Smarter API for Python\n\nThis API allows communication between any python based Component on the [smarter.ai](https://www.smarter.ai/)\nplatform.\n\n## User Installation\n\nThe latest released version are available at the Python Package Index (PyPI).\n\nTo install using pip:\n\n```bash\npip install smarterai\n```\n\n## Usage\n\n- For starters an account needs to be created at our platform. So visit our website and create an account\n  at [smarter.ai](https://www.smarter.ai/).\n\n- Then in order for the python code to be accessible for the [smarter.ai](https://www.smarter.ai/) platform, follow\n  these steps:\n    1. Visit the [Studio](https://studio.smarter.ai/digital_twin)\n    2. Start a new [new Experiment](https://studio.smarter.ai/digital_twin/newExperiment)\n    3. Chose a Full Pipeline Template.\n    4. Follow the wizard.\n    5. Go to Build -> Experiment Editor.\n    6. From _Container: Environment_ Drag & drop a python component.\n    7. From _Blank: Starter Templates_ Drag & drop Python Code Template on top of the added Environment component.\n    8. Double-click on the Python Code Template newly added Component.\n    9. Edit/upload your code there.\n\n- You can then start building your code by copy-pasting the code found in the examples below.\n\n- The Python Component's interface needs to consist of the following:\n    1. Imports:\n  ```python\n  from typing import Optional\n  from smarterai import SmarterApp, SmarterMessage, SmarterApi\n  ```\n    2. A class called ```SmarterComponent```.\n    2. ```SmarterComponent``` should inherit from ```SmarterApp```:\n  ```python\n  class SmarterComponent(SmarterApp):\n  ```\n    3. The class should have a method ```invoke``` with the following signature:\n  ```python\n  def invoke(self, port: str, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:\n  ```\n\n### Example 1\n\nThis is the basic interface for a python based component.\n\n```python\nfrom typing import Optional\nfrom smarterai import SmarterApp, SmarterMessage, SmarterApi\n\n\nclass SmarterComponent(SmarterApp):\n    def invoke(self, port: str, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:\n        print(f\"Received the message '{message}' on port '{port}'\")\n        return\n```\n\n### Example 2\n\nIf your component needs initializing/booting before it starts running. Then a method ```boot``` needs to be defined.\n\n```python\nfrom typing import Optional\nfrom smarterai import SmarterApp, SmarterMessage, SmarterApi\n\n\nclass SmarterComponent(SmarterApp):\n    def __init__(self):\n        self.port_fn_mapper = {'boot': self.boot}\n\n    def boot(self, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:\n        # Write code here\n        return\n\n    def invoke(self, port: str, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:\n        print(f\"Received the message '{message}' on port '{port}'\")\n        if port in self.port_fn_mapper:\n            self.port_fn_mapper[port](message, smarter_api)\n        return\n```\n\n### Example 3\n\nIf your component needs to send messages to other components, then you can use smarter_api.\n\n```python\nfrom typing import Optional\nfrom smarterai import SmarterApp, SmarterMessage, SmarterApi\n\n\nclass SmarterComponent(SmarterApp):\n    def __init__(self):\n        self.port_fn_mapper = {'boot': self.boot, 'start': self.start}\n\n    def boot(self, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:\n        # Write code here\n        return\n\n    def start(self, message: SmarterMessage, smarter_api: SmarterApi) -> None:\n        port = 'out'\n        user_id = message.get('userId')\n        new_message = SmarterMessage({'name': f'Smarter AI Welcomes {user_id}'})\n        smarter_api.send_message(message=new_message, port=port)\n\n    def invoke(self, port: str, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:\n        print(f\"Received the message '{message}' on port '{port}'\")\n        if port in self.port_fn_mapper:\n            self.port_fn_mapper[port](message, smarter_api)\n        return\n```\n\n### Example 4\n\nIf your component needs to set data to front-end patterns.\n\n```python\nfrom typing import Optional\nfrom smarterai import SmarterApp, SmarterMessage, SmarterApi\n\n\nclass SmarterComponent(SmarterApp):\n    def __init__(self):\n        self.port_fn_mapper = {'boot': self.boot, 'start': self.start}\n\n    def boot(self, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:\n        # Write code here\n        return\n\n    def start(self, message: SmarterMessage, smarter_api: SmarterApi) -> None:\n        pattern = \"text_field\"\n        data = 'some value'\n        smarter_api.set_data(pattern=pattern, data=data)\n\n    def invoke(self, port: str, message: SmarterMessage, smarter_api: SmarterApi) -> Optional[SmarterMessage]:\n        print(f\"Received the message '{message}' on port '{port}'\")\n        if port in self.port_fn_mapper:\n            self.port_fn_mapper[port](message, smarter_api)\n        return\n```\n\n## Credits\n\nAuthored by Nevine Soliman and Carlos Medina (smarter.ai - All rights reserved)",
    "bugtrack_url": null,
    "license": "",
    "summary": "smarter.ai Python API",
    "version": "1.9.0",
    "project_urls": {
        "Homepage": "https://www.smarter.ai/"
    },
    "split_keywords": [
        "machine learning",
        "artificial intelligence"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f48e5840034391d79cf036f980f6c60d499776ffd598ee2a8ed62d0321497d40",
                "md5": "1f45fafedec930095fe8fb4c8c4d31af",
                "sha256": "37e46a1ef6e7e4e6d9060d8870764b7b183458f427fa6aedfb21e1bb6b698904"
            },
            "downloads": -1,
            "filename": "smarterai-1.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1f45fafedec930095fe8fb4c8c4d31af",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 15731,
            "upload_time": "2024-02-14T11:49:53",
            "upload_time_iso_8601": "2024-02-14T11:49:53.804700Z",
            "url": "https://files.pythonhosted.org/packages/f4/8e/5840034391d79cf036f980f6c60d499776ffd598ee2a8ed62d0321497d40/smarterai-1.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-14 11:49:53",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "smarterai"
}
        
Elapsed time: 0.20565s