Skip to main content

smarter.ai Python API

Project description

made-with-python PyPi version

Smarter API for Python

This API allows communication between any python based Flex component on the smarter.ai platform.

User Installation

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

To install using pip:

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.

  • Then in order for the Flex's code to be accessible for the smarter.ai platform, follow these steps:

    1. Visit the Studio
    2. Create a new Flex
    3. Chose a code-based template of your choosing.
    4. Follow the wizard and make sure to choose Python 3.6 as the programming Language.
    5. Go to Project -> Code and write/upload your code there.
  • You can then start building your Flex's code by copy-pasting the code found in the examples below.

  • The Flex's interface needs to consist of the following:

    1. Import smarterai:
          from smarterai import *
      
    2. A class called SmarterFlex.
    3. SmarterFlex should inherit from SmarterPlugin:
          class SmarterComponent(SmarterPlugin):
      
    4. The class should have a method invoke with the following signature:
          def invoke(self, port: str, message: SmarterMessage, smarter_sender: SmarterSender) -> Optional[SmarterMessage]:
      

Example 1

This is the basic interface for a python based Flex.

from smarterai import *


class SmarterComponent(SmarterPlugin):
    def invoke(self, port: str, message: SmarterMessage, smarter_sender: SmarterSender) -> Optional[SmarterMessage]:
        print("Received the message '{0}' on port '{1}'".format(message, port))
        return

Example 2

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

from smarterai import *


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

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

    def invoke(self, port: str, message: SmarterMessage, smarter_sender: SmarterSender) -> Optional[SmarterMessage]:
        print("Received the message '{0}' on port '{1}'".format(message, port))
        self.port_fn_mapper[port](message, smarter_sender)
        return

Credits

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smarterai-0.2.0.tar.gz (4.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page