> ## Documentation Index
> Fetch the complete documentation index at: https://developer.watson-orchestrate.ibm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Importing Python toolkits

After you create your Python tools, import them as a Python toolkit. A Python toolkit groups related tools so you can deploy and run them together in a single Python process. To meet this goal, design every tool in the toolkit to be thread-safe and reentrant. This approach gives you faster execution because the tools share the same process.

When you run Python tools outside a toolkit (as standalone Python tools), the system starts a lightweight process each time the tool runs. This design supports tools that use non-thread-safe operations, but it increases execution time by approximately 100-300ms per invocation compared to a toolkit.

> [!NOTE]
>
> **When to use Python toolkits vs standalone Python tools:**
>
> * **Use Python toolkits** when you have multiple related tools that are thread-safe, called frequently, or share dependencies
> * **Use standalone Python tools** when tools use non-thread-safe operations, are called infrequently, or need process isolation
>
> For detailed guidance, see [Choosing a tool type](https://developer.watson-orchestrate.ibm.com/tools/toolkits/choosing_tool_type.md).

To create a Python toolkit, place all required Python tools in one folder. Each tool can include one or more Python files. In those files, define your functions and apply the `@tool` decorator so watsonx Orchestrate exposes each function as a usable tool.

You can place tools that multiple agents use into a single toolkit. When you update tools inside a toolkit, redeploy all related agents to the live environment so you use the updated versions. Choose the number of tools in each toolkit based on the level of concurrent requests you expect. For more information, see [CPU and memory allocation for Python toolkits](#cpu-and-memory-allocation-for-python-toolkits).

### CPU and memory allocation for Python toolkits

**Draft environment:**

* All imported Python toolkits and Python tools run in a single Kubernetes deployment container per tenant
* Process overheads per tool call exist in draft (approximately 100-300ms per invocation)
* Container resources: 2 vCPUs, 2 GB of memory, and 5 workers
* Deployment supports two replicas

**Live environment (Premium plan):**

* You can import up to five Python toolkits per tenant
* Each toolkit runs in its own dedicated Kubernetes deployment container
* **No process overheads per tool call** — tools run in a persistent process
* Container resources per toolkit: 2 vCPUs, 2 GB of memory, and 5 workers
* Each deployment supports two replicas

**Live environment (Non-Premium plan):**

* `--tier` is not enabled by default for non-premium plans. Contact support to request access.

> [!TIP]
>
> **Performance optimization:** In live premium environments, Python toolkits eliminate process startup overhead, reducing tool execution time by 100-300ms per call compared to standalone Python tools. For frequently called tools (>10 calls/minute), this can significantly improve agent response times.

### Add Python toolkits using the ADK CLI

Use the `orchestrate toolkits add` command to add a Python toolkit.

```bash BASH theme={null}
orchestrate toolkits add \
  --kind python \
  --name <toolkit-name> \
  --description <toolkit-description> \
  --tier <deployment-tier> \
  --package-root <toolkit-path>
```

> [!NOTE]
>
> **Note:**
>
> `--tier` is required when importing a Python toolkit.
>
> * Premium plan customers: `--tier` is enabled by default.
> * Non-Premium plan customers: `--tier` is not enabled by default. To request access, open a support case.

**command flags**

**kind** *required*

The type of toolkit to import. For Python toolkits, use
`python`.

**name** *required*

The name of the toolkit.

**description** *required*

The description for the toolkit.

**package-root** *required*

The path for the toolkit.

**app-id**

The `app_id` to of a connection to associate with this toolkit. **Only `key_value` connections are supported.** Each key and value within the connection will be exposed as environment variables to the mcp server. For more information, see [Connections](https://developer.watson-orchestrate.ibm.com/connections/overview.md).

**tier** `string` *required*

The dedicated deployment tier for the Python toolkit. Required when `--kind` is `python`. Premium plan customers only — contact support to request access.

### Import Python toolkits from a file

You can also import a Python toolkit from a YAML file. This file defines the same configuration options as the add command and fits well into import scripts and CI/CD pipelines.

Use the `orchestrate toolkits import` command to import a toolkit from a file.

```bash BASH theme={null}
orchestrate toolkits import -f <path to spec> --app-id <connection>
```

**command flags**

**-f, --file** *required*

Path to the YAML specification file that defines the toolkit.

**app-id**

The `app_id` to of a connection to associate with this toolkit. **Only `key_value` connections are supported.** Each key and value within the connection will be exposed as environment variables to the mcp server. For more information, see [Connections](https://developer.watson-orchestrate.ibm.com/connections/overview.md).

For the YAML file, configure the following:

**spec\_version** `string` *required*

The version of the YAML specification.

**kind** `string` *required*

The type of toolkit. For Python toolkits, use `python`.

**name** `string` *required*

The name of the toolkit.

**description** `string`

The description of the toolkit.

**environment** `object`

Key-value pairs for the toolkit.

**Example:**

```yaml toolkit_name.yaml theme={null}
spec_version: v1
kind: python
name: toolkit_name
description: A toolkit sample
environment:
    key1: value1
```

### Configure Python toolkits to use only PyPI

You can restrict Python toolkit dependency resolution to PyPI only by setting the primary package index in the `requirements.txt` file of your toolkit.

Consider a PyPI-only configuration if:

* You want to avoid dependency on `test.pypi.org`.
* You want to prevent toolkit startup failures caused by TestPyPI outages.
* You do not use pre-release packages.

To configure your toolkit to use only PyPI:

1. Add the following line as the first line of your `requirements.txt` file:

   ```text theme={null}
   --index-url https://pypi.org/simple
   ```

   Alternatively, you can use:

   ```text theme={null}
   -i https://pypi.org/simple
   ```

2. Reimport the toolkit after you make the change.

This configuration:

* Forces dependency resolution through PyPI only.
* Bypasses TestPyPI completely.
* Uses the existing runtime custom-index detection behavior.
* Does not require a runtime code change.

**Sample `requirements.txt`:**

```text theme={null}
--index-url=https://pypi.org/simple
ibm-watsonx-orchestrate==2.19.0
```

> [!WARNING]
>
> Do not use this configuration if you use ADK development workflows or packages that are published only to TestPyPI. Such workflows depend on access to TestPyPI and might stop working if restricted to PyPI only.

### Thread-safety requirements

All tools in a Python toolkit must be thread-safe because they run in a shared process with concurrent requests. A tool is thread-safe when multiple threads can call it simultaneously without causing race conditions or data corruption.

**Thread-safe patterns:**

* No global mutable state
* Use immutable data structures
* Use thread-safe libraries

**Non-thread-safe patterns to avoid:**

* Global variables that change
* File system writes
* Non-thread-safe libraries
* Shared database connections without pooling

For detailed guidance on thread-safety and migration from standalone tools, see [Migrating to Python toolkits](https://developer.watson-orchestrate.ibm.com/tools/toolkits/migrating_to_toolkits.md).
