steamship.invocable package#

Submodules#

steamship.invocable.config module#

class steamship.invocable.config.Config[source]#

Bases: steamship.base.model.CamelModel

Base class Steamship Package and Plugin configuration objects.

extend_with_dict(d: dict, overwrite: bool = False)[source]#

Sets the attributes on this object with provided keys and values.

extend_with_json_file(path: pathlib.Path, overwrite: bool = False, fail_on_missing_file: bool = True)[source]#

Extends this config object’s values with a JSON file from disk.

This is useful for applying late-bound defaults, such as API keys added to a deployment bundle.

steamship.invocable.entrypoint module#

This class is necessary to be able to please the entrypoints of both localstack and AWS.

If we set the entrypoint directly to steamship.invocable.safe_handler (imported in the init from lambda_handler), AWS is happy, but localstack is not because it tries to read steamship.invocable as a py file, not a module.

If we set the entrypoint to steamship.invocable.lambda_handler.safe_handler, Localstack is happy, but AWS is not, because it tries to read lambda_handler first, which imports things from steamship.invocable, which imports things from lambda_handler.

By adding this file which basically no-ops safe_handler into steamship.invocable.entrypoint.safe_handler, both are happy.

steamship.invocable.invocable module#

Please see https://docs.steamship.com/ for information about building a Steamship Package

class steamship.invocable.invocable.Invocable(client: Optional[steamship.client.steamship.Steamship] = None, config: Optional[Dict[str, Any]] = None)[source]#

Bases: abc.ABC

A Steamship microservice.

This model.py class:

  1. Provide a pre-authenticated instance of the Steamship client

  2. Provides a Lambda handler that routes to registered functions

  3. Provides useful methods connecting functions to the router.

config: steamship.invocable.config.Config#
config_cls() Type[steamship.invocable.config.Config][source]#

Returns the configuration object for the Invocable.

By default, Steamship packages and plugins will not take any configuration. Steamship packages and plugins may declare a configuration object which extends from Config, if needed, as follows:

class MyPackageOrPlugin:
class MyConfig(Config):

def config_cls(self):

return MyPackageOrPlugin.MyConfig

steamship.invocable.invocable.endpoint(verb: Optional[str] = None, path: Optional[str] = None, **kwargs)[source]#

By using kwargs we can tag the function with Any parameters.

steamship.invocable.invocable.get(path: str, **kwargs)[source]#
steamship.invocable.invocable.make_registering_decorator(decorator)[source]#

Returns a copy of foreignDecorator, which is identical in every way(*), except also appends a .decorator property to the callable it spits out.

(*)We can be somewhat “hygienic”, but newDecorator still isn’t signature-preserving, i.e. you will not be able to get a runtime list of parameters. For that, you need hackish libraries…but in this case, the only argument is func, so it’s not a big issue

steamship.invocable.invocable.post(path: str, **kwargs)[source]#

steamship.invocable.invocable_request module#

class steamship.invocable.invocable_request.InvocableRequest(*, clientConfig: steamship.base.configuration.Configuration = None, invocation: steamship.invocable.invocable_request.Invocation = None, loggingConfig: steamship.invocable.invocable_request.LoggingConfig = None, invocationContext: steamship.invocable.invocable_request.InvocationContext = None)[source]#

Bases: steamship.base.model.CamelModel

A request as the Steamship Hosting Framework receives it from the Engine.

This class is different from the other Request class:
  • steamship.base.request represents a request from the Steamship Client

  • this class represents a request from the Steamship Engine to a Steamship-hosted App/Plugin

It contains both a package/plugin invocation and also the client configuration in which that invocation is intended to execute.

client_config: steamship.base.configuration.Configuration#
invocation: steamship.invocable.invocable_request.Invocation#
invocation_context: steamship.invocable.invocable_request.InvocationContext#
logging_config: steamship.invocable.invocable_request.LoggingConfig#
class steamship.invocable.invocable_request.Invocation(*, httpVerb: str = None, invocationPath: str = None, arguments: Dict[str, Any] = None, config: Dict[str, Any] = None)[source]#

Bases: steamship.base.model.CamelModel

arguments: Dict[str, Any]#
config: Dict[str, Any]#
http_verb: str#
invocation_path: str#
class steamship.invocable.invocable_request.InvocationContext(*, tenantId: str = None, userId: str = None, workspaceId: str = None, invocableHandle: str = None, invocableVersionHandle: str = None, invocableInstanceHandle: str = None, invocableType: str = None)[source]#

Bases: steamship.base.model.CamelModel

invocable_handle: str#
invocable_instance_handle: str#
invocable_type: str#
invocable_version_handle: str#
tenant_id: str#
user_id: str#
workspace_id: str#
class steamship.invocable.invocable_request.LoggingConfig(*, loggingHost: str = None, loggingPort: str = None)[source]#

Bases: steamship.base.model.CamelModel

logging_host: str#
logging_port: str#

steamship.invocable.invocable_response module#

class steamship.invocable.invocable_response.Http(*, status: int = None, base64Wrapped: bool = None, headers: Dict[str, str] = None)[source]#

Bases: steamship.base.model.CamelModel

base64_wrapped: bool#
headers: Dict[str, str]#
status: int#
class steamship.invocable.invocable_response.InvocableResponse(status: Task = None, error: SteamshipError = None, http: Http = None, data: Any = None, string: str = None, json: Any = None, _bytes: Union[bytes, io.BytesIO] = None, mime_type=None)[source]#

Bases: pydantic.generics.GenericModel, Generic[steamship.invocable.invocable_response.T]

Mirrors the Response object in the Steamship server.

data: T#
static error(code: int, message: Optional[str] = None, error: Optional[steamship.base.error.SteamshipError] = None, exception: Optional[Exception] = None, prefix: Optional[str] = None) steamship.invocable.invocable_response.InvocableResponse[source]#

Merges a number of error channels into one unified Response object.

Aggregates all possible messages into a single ” | “-delimeted error message.

If the final resulting error message is non-null, prefixes with the provided prefix

static from_obj(obj: Any) steamship.invocable.invocable_response.InvocableResponse[source]#
http: Http#
post_update(client: steamship.base.client.Client)[source]#

Pushes this response object to the corresponding Task on the Steamship Engine.

Typically apps and plugins return their results to the Engine synchronously via HTTP. But sometimes that’s not practice – for example:

  • Microsoft’s OCR endpoint returns a Job Token that can be exchanged for updates, and eventually a result.

  • Google’s AutoML can take 20-30 minutes to train.

  • Fine-tuning BERT on ECS can take an arbitrarily long amount of time.

In these cases, it can be useful for the package/plugin to occasionally post updates to the Engine outside of the Engine’s initial synchronous request-response conversation.

set_data(data: Optional[Any] = None, string: Optional[str] = None, json: Optional[Any] = None, _bytes: Optional[Union[bytes, _io.BytesIO]] = None, mime_type=None)[source]#
status: Task#

steamship.invocable.lambda_handler module#

steamship.invocable.lambda_handler.create_handler(invocable_cls: Type[steamship.invocable.invocable.Invocable])[source]#

Deprecated wrapper function for a Steamship invocable within an AWS Lambda function. Called by code within a plugin or package.

steamship.invocable.lambda_handler.create_safe_handler(known_invocable_for_testing: Optional[Type[steamship.invocable.invocable.Invocable]] = None)[source]#
steamship.invocable.lambda_handler.encode_exception(obj)[source]#

When logging an exception ex: logging.exception(some_error), the exception must be turned into a string so that it is accepted by elasticsearch

steamship.invocable.lambda_handler.handler(internal_handler, event: Dict, _: Optional[Dict] = None) dict[source]#
steamship.invocable.lambda_handler.internal_handler(invocable_cls_func: Callable[[], Type[steamship.invocable.invocable.Invocable]], event: Dict, client: steamship.client.steamship.Steamship) steamship.invocable.invocable_response.InvocableResponse[source]#
steamship.invocable.lambda_handler.safe_handler(event, context=None)#
steamship.invocable.lambda_handler.safely_find_invocable_class() Type[steamship.invocable.invocable.Invocable][source]#

Safely find the invocable class within invocable code.

steamship.invocable.package_service module#

class steamship.invocable.package_service.PackageService(client: Optional[steamship.client.steamship.Steamship] = None, config: Optional[Dict[str, Any]] = None)[source]#

Bases: steamship.invocable.invocable.Invocable

The Abstract Base Class of a Steamship Package.

Packages may implement whatever methods they like. To expose these methods as invocable HTTP routes, annotate the method with @get or @post and the route name.

Package implementations are effectively stateless, though they will have stateful

steamship.invocable.plugin_service module#

class steamship.invocable.plugin_service.PluginService(client: Optional[steamship.client.steamship.Steamship] = None, config: Optional[Dict[str, Any]] = None)[source]#

Bases: steamship.invocable.invocable.Invocable, Generic[steamship.invocable.plugin_service.IN, steamship.invocable.plugin_service.OUT], abc.ABC

The Abstract Base Class of a Steamship Plugin.

All Steamship Plugins implement the operation:

  • run(PluginRequest[T]) -> Response[U]

Many plugins are effectively stateless. This run operation defines their entire capability. Examples of such stateless plugins are: - File Import Plugin - Export Plugin

Other plugins have state but in a very controlled way: - they can be trained, - this trainable process produces a “model”, - that model acts as the state on which the run method is conditioned

This model is stored in the Steamship Workspace that owns the Plugin Instance, and access to it is provided by the hosting environment that runs the model. - TODO(ted) Document this process.

These stateful plugins are called “Trainable Plugins,” and they must implement the following additional methods:

  • get_training_parameters(PluginRequest[TrainingParameterInput]) -> Response[TrainingParameterOutput]

  • train(PluginRequest[TrainPluginInput]) -> Response[TrainPluginOutput]

abstract run(request: PluginRequest[IN]) Union[OUT, InvocableResponse[OUT]][source]#

Runs the core operation implemented by this plugin: import, export, blockify, tag, etc.

This is the method that a Steamship Plugin implements to perform its main work.

class steamship.invocable.plugin_service.TrainablePluginService(client: Optional[steamship.client.steamship.Steamship] = None, config: Optional[Dict[str, Any]] = None)[source]#

Bases: steamship.invocable.plugin_service.PluginService, Generic[steamship.invocable.plugin_service.IN, steamship.invocable.plugin_service.OUT], abc.ABC

abstract get_training_parameters(request: steamship.invocable.plugin_service.PluginRequest[TrainingParameterPluginInput]) steamship.plugin.tagger.InvocableResponse[TrainingParameterPluginOutput][source]#

Produces the trainable parameters for this plugin.

This method is run by the Steamship Engine prior to training to fetch hyperparameters.

  • The user themselves can provide hyperparameters on the TrainingParameterPluginInput object.

  • This method then transforms those into the TrainingParameterPluginOutput object, altering the user’s values if desired.

  • The Engine then takes those TrainingParameterPluginOutput and presents them on the TrainPluginInput

abstract model_cls() Type[steamship.plugin.trainable_model.TrainableModel][source]#

Returns the constructor of the TrainableModel this TrainablePluginService uses.

This is required so the run method below can load the model and provide it to the subclass implementor.

run(request: PluginRequest[IN]) Union[OUT, InvocableResponse[OUT]][source]#

Loads the trainable model before passing the request to the run_with_model handler on the subclass.

abstract run_with_model(request: PluginRequest[IN], model: TrainableModel) Union[OUT, InvocableResponse[OUT]][source]#

Rather than implementing run(request), a TrainablePluginService implements run_with_model(request, model)

abstract train(request: steamship.plugin.trainable_model.PluginRequest[TrainPluginInput], model: steamship.plugin.trainable_model.TrainableModel) steamship.plugin.trainable_model.InvocableResponse[TrainPluginOutput][source]#

Train the model.

abstract train_status(request: steamship.plugin.trainable_model.PluginRequest[TrainPluginInput], model: steamship.plugin.trainable_model.TrainableModel) steamship.plugin.trainable_model.InvocableResponse[TrainPluginOutput][source]#

Train the model.

Module contents#

class steamship.invocable.Config[source]#

Bases: steamship.base.model.CamelModel

Base class Steamship Package and Plugin configuration objects.

extend_with_dict(d: dict, overwrite: bool = False)[source]#

Sets the attributes on this object with provided keys and values.

extend_with_json_file(path: pathlib.Path, overwrite: bool = False, fail_on_missing_file: bool = True)[source]#

Extends this config object’s values with a JSON file from disk.

This is useful for applying late-bound defaults, such as API keys added to a deployment bundle.

class steamship.invocable.Invocable(client: Optional[steamship.client.steamship.Steamship] = None, config: Optional[Dict[str, Any]] = None)[source]#

Bases: abc.ABC

A Steamship microservice.

This model.py class:

  1. Provide a pre-authenticated instance of the Steamship client

  2. Provides a Lambda handler that routes to registered functions

  3. Provides useful methods connecting functions to the router.

config: steamship.invocable.config.Config#
config_cls() Type[steamship.invocable.config.Config][source]#

Returns the configuration object for the Invocable.

By default, Steamship packages and plugins will not take any configuration. Steamship packages and plugins may declare a configuration object which extends from Config, if needed, as follows:

class MyPackageOrPlugin:
class MyConfig(Config):

def config_cls(self):

return MyPackageOrPlugin.MyConfig

class steamship.invocable.InvocableRequest(*, clientConfig: steamship.base.configuration.Configuration = None, invocation: steamship.invocable.invocable_request.Invocation = None, loggingConfig: steamship.invocable.invocable_request.LoggingConfig = None, invocationContext: steamship.invocable.invocable_request.InvocationContext = None)[source]#

Bases: steamship.base.model.CamelModel

A request as the Steamship Hosting Framework receives it from the Engine.

This class is different from the other Request class:
  • steamship.base.request represents a request from the Steamship Client

  • this class represents a request from the Steamship Engine to a Steamship-hosted App/Plugin

It contains both a package/plugin invocation and also the client configuration in which that invocation is intended to execute.

client_config: steamship.base.configuration.Configuration#
invocation: steamship.invocable.invocable_request.Invocation#
invocation_context: steamship.invocable.invocable_request.InvocationContext#
logging_config: steamship.invocable.invocable_request.LoggingConfig#
class steamship.invocable.InvocableResponse(status: Task = None, error: SteamshipError = None, http: Http = None, data: Any = None, string: str = None, json: Any = None, _bytes: Union[bytes, io.BytesIO] = None, mime_type=None)[source]#

Bases: pydantic.generics.GenericModel, Generic[steamship.invocable.invocable_response.T]

Mirrors the Response object in the Steamship server.

data: T#
static error(code: int, message: Optional[str] = None, error: Optional[steamship.base.error.SteamshipError] = None, exception: Optional[Exception] = None, prefix: Optional[str] = None) steamship.invocable.invocable_response.InvocableResponse[source]#

Merges a number of error channels into one unified Response object.

Aggregates all possible messages into a single ” | “-delimeted error message.

If the final resulting error message is non-null, prefixes with the provided prefix

static from_obj(obj: Any) steamship.invocable.invocable_response.InvocableResponse[source]#
http: Http#
post_update(client: steamship.base.client.Client)[source]#

Pushes this response object to the corresponding Task on the Steamship Engine.

Typically apps and plugins return their results to the Engine synchronously via HTTP. But sometimes that’s not practice – for example:

  • Microsoft’s OCR endpoint returns a Job Token that can be exchanged for updates, and eventually a result.

  • Google’s AutoML can take 20-30 minutes to train.

  • Fine-tuning BERT on ECS can take an arbitrarily long amount of time.

In these cases, it can be useful for the package/plugin to occasionally post updates to the Engine outside of the Engine’s initial synchronous request-response conversation.

set_data(data: Optional[Any] = None, string: Optional[str] = None, json: Optional[Any] = None, _bytes: Optional[Union[bytes, _io.BytesIO]] = None, mime_type=None)[source]#
status: Task#
class steamship.invocable.Invocation(*, httpVerb: str = None, invocationPath: str = None, arguments: Dict[str, Any] = None, config: Dict[str, Any] = None)[source]#

Bases: steamship.base.model.CamelModel

arguments: Dict[str, Any]#
config: Dict[str, Any]#
http_verb: str#
invocation_path: str#
class steamship.invocable.InvocationContext(*, tenantId: str = None, userId: str = None, workspaceId: str = None, invocableHandle: str = None, invocableVersionHandle: str = None, invocableInstanceHandle: str = None, invocableType: str = None)[source]#

Bases: steamship.base.model.CamelModel

invocable_handle: str#
invocable_instance_handle: str#
invocable_type: str#
invocable_version_handle: str#
tenant_id: str#
user_id: str#
workspace_id: str#
class steamship.invocable.LoggingConfig(*, loggingHost: str = None, loggingPort: str = None)[source]#

Bases: steamship.base.model.CamelModel

logging_host: str#
logging_port: str#
class steamship.invocable.PackageService(client: Optional[steamship.client.steamship.Steamship] = None, config: Optional[Dict[str, Any]] = None)[source]#

Bases: steamship.invocable.invocable.Invocable

The Abstract Base Class of a Steamship Package.

Packages may implement whatever methods they like. To expose these methods as invocable HTTP routes, annotate the method with @get or @post and the route name.

Package implementations are effectively stateless, though they will have stateful

steamship.invocable.create_handler(invocable_cls: Type[steamship.invocable.invocable.Invocable])[source]#

Deprecated wrapper function for a Steamship invocable within an AWS Lambda function. Called by code within a plugin or package.

steamship.invocable.get(path: str, **kwargs)[source]#
steamship.invocable.post(path: str, **kwargs)[source]#
steamship.invocable.safe_handler(event, context=None)#