smarter.ai Python API
Project description
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:
-
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:
- Import
smarterai:from smarterai import *
- A class called
SmarterFlex. SmarterFlexshould inherit fromSmarterPlugin:class SmarterFlex(SmarterPlugin)
- The class should have a method
invokewith the following signature:def invoke(self, port: str, msg: SmarterMessage, send_message: SmarterSender) -> Optional[SmarterMessage]
- Import
Example 1
This is the basic interface for a python based Flex.
from smarterai import *
class SmarterFlex(SmarterPlugin):
def invoke(self, port: str, msg: SmarterMessage, send_message: SmarterSender) -> Optional[SmarterMessage]:
print("Received the message '{0}' on port '{1}'".format(msg, 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 SmarterFlex(SmarterPlugin):
def __init__(self):
self.port_fn_mapper = {'boot': self.process_input}
def boot(self, msg: SmarterMessage, send_message: SmarterSender) -> Optional[SmarterMessage]:
# Write code here
return
def invoke(self, port: str, msg: SmarterMessage, send_message: SmarterSender) -> Optional[SmarterMessage]:
print("Received the message '{0}' on port '{1}'".format(msg, port))
self.port_fn_mapper[port](msg, send_message)
return
Credits
Authored by Nevine Soliman and Carlos Medina (smarter.ai - All rights reserved)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file smarterai-0.1.2.tar.gz.
File metadata
- Download URL: smarterai-0.1.2.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
288189d8834661bcdb030ab6ed7d9f8a1be6d93c318df1021563c34394ba64e6
|
|
| MD5 |
10e05369656092c5b69760ed1261d2d9
|
|
| BLAKE2b-256 |
ed3b6c4c6873556bc188da3eb62ee938e152d6252657e354ea70ff7845e387fb
|