Action editor

In the Action editor, you can write your code and configure the execution environment by specifying the necessary libraries and dependencies for your action. You can also test your code with a simulated event before integrating it into the Pipeline.

The action editor consists of the Code editor, and the following tabs: Environment, Testing, and Settings.

Code editor

When creating or editing your action, you can find the Code editor on the right-hand side at all times. Here, you can write your Python code using a handler function.

Handler function

def handler(event, context): This function will process the input data and return results to be used in subsequent pipeline stages.

Arguments

event: This dictionary provides runtime information about the execution, including the event's unique identifier, event type, and the ID of the pipeline where the trigger occurs.

{
    "uuid": 2757097,
    "event": "project c",
    "pipeline_id": 0
}

context: is the input data passed to the function, which includes a trigger payload.

{
    "op": "c",
    "after": {
        "id": 0,
        "name": "MyProject",
        "type": "Vector",
        "status": "NotStarted",
        "options": 0,
        "team_id": 0,
        "createdAt": 1718965118000,
        "deletedAt": 0,
        "is_pinned": false,
        "updatedAt": 1718965118000,
        "creator_id": "[email protected]",
        "description": null,
        "upload_state": "Initial",
        "entropy_status": "NotStarted",
        "sharing_status": null,
        "attachment_name": null,
        "attachment_path": null,
        "custom_editor_url": null
    },
    "ts_ms": 1718965118466,
    "before": null
}

Return value

The function should return a serializable JSON object, which represents the result of the action and will be used by the next stage in the pipeline. Make sure to structure this result in a way that is compatible with subsequent processing steps.

Example

Here's an example of how you might use the handler method in your code to handle an event.

The following script sends a message to a Slack channel using Slack's API. For detailed information and additional examples, please refer to the templates available in our GitHub repository.

import os
import logging

from superannotate import SAClient
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError

logging.basicConfig(level=logging.INFO)

SLACK_TOKEN = os.environ['SLACK_TOKEN']
CHANNEL_ID = os.environ['CHANNEL_ID']


def handler(event, context):
    sa = SAClient()

    current_state = context['after']
    project_name = sa.get_project_by_id(current_state['project_id'])['name']

    # Change the message to be sent
    message = f"Ready for annotation: {project_name} has been updated"

    slack_client = WebClient(token=SLACK_TOKEN)
    # Call the conversations.list method using the WebClient
    slack_client.chat_postMessage(
        channel=CHANNEL_ID,
        text=message
        # You could also use a blocks[] array to send richer content
    )

Environment configurations

In the Environment tab, you set up the execution environment for your action by creating a container image. This environment is where your code will be executed.

Python Version

Specify the version of Python that your code will use. The chosen Python version should be compatible with your code and any libraries you plan to use.

Dependencies

List and manage the dependencies required by your code. This includes external libraries and packages that your action needs to function correctly.

Action testing

In the Testing tab, you can test the action by replicating execution using simulated events.

To test your code, you first need to create the action, ensure the environment is successfully built, and then set up the test configurations.

📘

Keep in mind that you can only test code when editing an existing action.

Create a test

To create a test configuration:

  1. When in the Testing tab, click + Create.
  2. Type in the configuration’s name in the Test name field.
  3. Select a secret you want to link to your test (optional). Refer to the Secret section for details.
  4. Select a payload template (optional). This section lists all available events at SuperAnnotate. Payload templates provide a structured JSON format that you can customize for your testing needs.
  5. Modify the prefilled data of the selected payload template or manually enter valid JSON into the Event and Context fields.
  6. Click Save.

Once you’ve done this, you can see your configuration in a list under Test configurations. You may have a maximum of 10 configurations at one time. You can Run, Edit, or Delete your configurations from this menu.

While running your test, you may Revoke it at any time before it’s completed in order to cancel the run.

Run the test

Clicking the Run button initiates the testing process, simulating code execution based on the current configuration. The button is located on the configuration row in the left panel and appears when hovering over the row.

You can find the results of your test under the Test result section when clicking on the test configuration row.


Version history

In the Version history tab, you can view the history of changes made to an action, compare them to the current state, and restore older versions. Each version includes the date and time of the changes, the name of the user who made them, and the version ID.

Every time you make changes in an action, the editor creates a new draft you can work on. This draft has no version ID and is turned into a new version when you save your changes. In draft mode, you can freely navigate between tabs—even run tests from the Testing tab—without losing your unsaved changes. The draft remains active until you choose to save or discard it.

When you click on a version, the code editor on the right splits into two columns: the selected version's code appears on the left, and the current version's code appears on the right. You can also choose to view code versions in the Unified mode, which will compare the selected version and the current version in one unified layout. When viewing both versions in either manner, you can make changes to the current version as needed.

To restore an earlier version:

  1. Select the version you want to return to.
  2. Click Restore.
  3. In the pop-up, click Restore.

📘

Will restoring a version overwrite the current one?

No—restoring a previous version doesn't erase your history. When you restore an earlier version, a new entry is added to the version history, which becomes your new current version. All past versions remain accessible, and you can view or restore any of them at any time.

📘

Versions from removed members

Versions made by Team Admins who are no longer a part of the team will still be visible in the history. They will be listed as Deleted user.

Settings

In the Settings tab, you can update the action's name and description.

Configurations

Under the Configurations tab, you can manage a few additional settings to manage the various limits of action execution:

  • Allocated memory - The amount of memory that this action can use up. Any executions that exceed this limit will fail automatically.
  • Execution duration - The amount of time that this action can take to be executed. Any actions that exceed this duration limit will fail automatically.
  • Concurrency - The maximum number of executions that can take place simultaneously. Any actions that exceed this limit will be held in a queue in the Received state for up to 3 hours. If they aren’t executed before then, they’ll automatically fail.