smarter.ai Python API
Project description
Smarter API for Python
This API allows communication between artifacts 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 artifact's code to be accessible for the smarter.ai platform, follow these steps:
- Go to Open Studio
- Create a new Experiment
- Chose a code-based template of your choosing.
- Follow the wizard and make sure to choose
Python 3.6
as the programming Language. - Go to Project -> Code and write/upload your code there.
-
You can then start building your artifact's code by copy-pasting the code found in the examples below.
-
The artifact's interface needs to consist of the following:
- Import
smarterai
:from smarterai import *
- A class called
SmarterArtifact
. SmarterArtifact
should inherit fromSmarterPlugin
:class SmarterArtifact(SmarterPlugin)
- The class should have a method
invoke
with the following signature:def invoke(self, port: str, msg: SmarterMessage, send_message: SmarterSender) -> Optional[SmarterMessage]
- Import
Example 1
This is the basic interface for all the python artifacts.
from smarterai import *
class SmarterArtifact(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 artifact needs initializing/booting before it starts running. Then a method boot
needs to be defined.
from smarterai import *
class SmarterArtifact(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
Authoured 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.