> For the complete documentation index, see [llms.txt](https://docs.shimoku.com/dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.shimoku.com/dev/releases/2023/v.0.16.md).

# v.0.16

2023.02.14

{% hint style="danger" %}
This version has been deprecated. If used with the current API version it can produce unexpected behaviour or errors.
{% endhint %}

{% hint style="danger" %}
The package shimoku-api-python is no longer maintained
{% endhint %}

{% hint style="info" %}
To get the new version 🤖
{% endhint %}

```
pip install --upgrade shimoku-api-python
```

This is a small but very important version, as it includes the tools necessary for handling generic AI and complex tasks!

### Fixes

* The SDK has been adapted to python 3.9, there was an async feature that was only available on python 3.10 >=, but now it  has been resolved, so there are no compatibility issues with version 3.9.

### Improvements

* The Shimoku module now includes an exciting new feature - activities and runs! This addition allows users to trigger webhooks through Shimoku's API, making it easier than ever to create complex AI and data workflows. For example, you can now create a complete lead scoring prediction page, with your data, with just a single line of code.&#x20;

  The process of linking a webhook to an activity will be handled internally for the time being, but if you have a specific task in mind, don't hesitate to reach out to us!

  With this new feature, you can create multiple runs for each activity, each run being a single execution with unique settings. You can also keep track of everything with run logs. The Shimoku module provides several methods to make the most of activities and runs, including:

  * Get the activities available in your business using `get_business_activities`
  * Interact with a specific business using `set_business`
  * Create a new activity using `create_activity`
  * Update an existing activity using `update_activity`
  * Delete an activity using `delete_activity`
  * Create a new run from an activity and execute it using `execute_activity`
  * Retrieve an activity from your business using `get_activity`
  * Get all activities from the app using `get_activities`
  * Create a new run for an activity using `create_run`
  * Execute a run for an activity using `execute_run`
  * Create a new run log to keep track of everything using `create_run_log`

  In the next example it will be shown how to use these methods to create and manipulate runs and activities:

  ```python
  s = Shimoku.Client(
      access_token=api_key,
      universe_id=universe_id,
      environment=environment,
      verbosity=verbose,
      async_execution=async_execution,
      business_id=business_id,
  )

  menu_path = 'test_activity'
  activity_name = 'test_activity'

  # To create an activity the location and the activity name is needed,
  # the returned value is a dictionary
  activity = s.activity.create_activity(menu_path, activity_name)

  # To create a run just pass the location, the activity name and its settings
  # the returned value is a dictionary
  settings = {'Test': 'settings', 'Settings': 'test'}
  run = s.activity.create_run(menu_path, activity_name, settings)

  # When creating a run you can copy the settings of another run by passing the id
  run_1 = s.activity.create_run(menu_path, activity_name, settings=run['id'])

  # For the creation a log you have to provide the path, the activity, the run id
  # and the information that you want to store.
  # the severity parameter can only have so many values (['INFO', 'DEBUG', 'ERROR', 'CRITICAL'])
  log = s.activity.create_run_log(menu_path, activity_name, run_id=run['id'],
      message='test message', severity='INFO', tags=['tag1', 'tag2', 'tag3'])

  # to retrieve an activity that already exists use the method get_activity, passing
  # the same parameters as for create_activity
  # you can specify how many runs to get, by default it will retrieve one run
  activity = s.activity.get_activity(menu_path, activity_name, how_many_runs=2)

  # the runs are returned by ascending order of their last log
  [run_1, run] = activity['runs']

  # this way you can retrieve the logs of a run
  logs = run['logs']

  # This way you can delete an activity
  s.activity.delete_activity(menu_path, activity_name)
  ```

  In order to execute an activity it has to be linked to a webhook, the next example expects that the activity in use has a webhook attached:

  ```python
  # The function execute activity creates a run and then executes the run
  # the return value is the dictionary of the run
  run = s.activity.execute_activity(menu_path, activity_name, settings)

  # You can pass settings the same way as when creating a run
  run_1 = s.activity.execute_activity(menu_path, activity_name, settings=run['id'])

  # Another way of executing a run is with it's id
  run_2 = s.activity.create_run(menu_path, activity_name, settings=run['id'])
  s.activity.execute_run(menu_path, activity_name, run_id=run['id']
  ```

  When a run gets executed the API will automatically add a log indicating that the webhook has been called

  <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>The webhook will no longer be attached after deleting an activity, we do not recommend deleting activities.</p></div>

  <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>A run can only be executed once.</p></div>

  It has also been added the option to create a button in the dashboard to dinamically execute the activity. To use it call `s.activity.button_execute_activity` passing it with the traditional information of the `s.plt.*` methods. Like the other execute methods settings can be provided. It has a parameter named `align` which can be set with one of the follow options:

  &#x20;                                              `start, center, right, stretch`

  By default it will use `stretch`.

  The next example shows how to call this method in various ways:

  ```python
   s.activity.button_execute_activity(
          menu_path=menu_path, activity_name=activity_name, order=0, 
          label='test_button', cols_size=12, align='start'
  )
  s.activity.button_execute_activity(
      menu_path=menu_path, activity_name=activity_name, order=1, 
      label='test_button', cols_size=12, align='center'
  )
  s.activity.button_execute_activity(
      menu_path=menu_path, activity_name=activity_name, order=2, 
      label='test_button',rows_size=2, cols_size=12, align='right'
  )

  for i in range(6):
      s.activity.button_execute_activity(
          menu_path=menu_path, activity_name=activity_name, order=3+i, 
          label='test_button', rows_size=2, cols_size=12-i*2, align='stretch', 
          padding=f'0,{i},0,{i}'
      )

  s.activity.button_execute_activity(
      menu_path=menu_path, activity_name=activity_name, order=9, 
      label='test_button', cols_size=12, align='center'
  )
  ```

  The result in the dashboard is:

  <figure><img src="https://3782181538-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUlHTfmIZY46Z1EDfyGMz%2Fuploads%2FFKvrNPhwS6nk6gs64UMC%2Fimage.png?alt=media&amp;token=3bc97c23-2f68-4fbd-9412-e094001bc59c" alt=""><figcaption><p>Different button sizes and positions</p></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.shimoku.com/dev/releases/2023/v.0.16.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
