Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 22, 20:45 UTC
Fix python sdk type issues (#1949)
Musthaq Ahamad committed
Sep 17, 2025 at 00:50 UTC
b750b06c60553576b02f7d18598e228d9ecb574d
37 files changed
+1181
-64
.github/workflows/py.test.yml
new
+172
@@ -0,0 +1,172 @@
1
+name: Test Python SDK
2
+
3
+on:
4
+ push:
5
+ branches: [main, next]
6
+ paths:
7
+ - "python/**/*.py"
8
+ - ".github/workflows/py.test.yml"
9
+ - "python/pyproject.toml"
10
+ - "python/requirements*.txt"
11
+ pull_request:
12
+ branches: [main, next]
13
+ paths:
14
+ - "python/**/*.py"
15
+ - ".github/workflows/py.test.yml"
16
+ - "python/pyproject.toml"
17
+ - "python/requirements*.txt"
18
+
19
+jobs:
20
+ test:
21
+ name: Test Python SDK
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ matrix:
25
+ python-version: ["3.10", "3.11", "3.12"]
26
+
27
+ steps:
28
+ - name: Checkout Code
29
+ uses: actions/checkout@v4
30
+
31
+ - name: Set up Python ${{ matrix.python-version }}
32
+ uses: actions/setup-python@v5
33
+ with:
34
+ python-version: ${{ matrix.python-version }}
35
+
36
+ - name: Cache pip dependencies
37
+ uses: actions/cache@v4
38
+ with:
39
+ path: ~/.cache/pip
40
+ key: pip-${{ matrix.python-version }}-${{ hashFiles('python/pyproject.toml') }}
41
+ restore-keys: |
42
+ pip-${{ matrix.python-version }}-
43
+
44
+ - name: Install UV
45
+ run: pip install uv
46
+
47
+ - name: Install Dependencies
48
+ run: |
49
+ cd python/
50
+ uv venv --python ${{ matrix.python-version }}
51
+ source .venv/bin/activate
52
+ uv pip install -e .
53
+ uv pip install pytest pytest-mock
54
+
55
+ - name: Run Import Tests
56
+ run: |
57
+ cd python/
58
+ source .venv/bin/activate
59
+ python -c "from composio import Composio; print('✓ Basic import successful')"
60
+
61
+ - name: Run Unit Tests
62
+ run: |
63
+ cd python/
64
+ source .venv/bin/activate
65
+ python -m pytest tests/ -v --tb=short
66
+
67
+ - name: Test Package Installation
68
+ run: |
69
+ cd python/
70
+ # Test that the package can be installed and imported in a fresh environment
71
+ uv venv test-env --python ${{ matrix.python-version }}
72
+ source test-env/bin/activate
73
+ uv pip install -e .
74
+ python -c "
75
+ from composio import Composio, ToolkitVersionParam
76
+ from composio.types import Modifiers
77
+ from composio.core.types import ToolkitVersion
78
+ print('✓ All critical imports successful')
79
+ "
80
+
81
+ test-circular-imports:
82
+ name: Test Circular Import Prevention
83
+ runs-on: ubuntu-latest
84
+
85
+ steps:
86
+ - name: Checkout Code
87
+ uses: actions/checkout@v4
88
+
89
+ - name: Set up Python
90
+ uses: actions/setup-python@v5
91
+ with:
92
+ python-version: "3.11"
93
+
94
+ - name: Install UV
95
+ run: pip install uv
96
+
97
+ - name: Install Dependencies
98
+ run: |
99
+ cd python/
100
+ uv venv --python 3.11
101
+ source .venv/bin/activate
102
+ uv pip install -e .
103
+
104
+ - name: Test Circular Import Prevention
105
+ run: |
106
+ cd python/
107
+ source .venv/bin/activate
108
+ python -c "
109
+ # Test various import combinations that previously caused circular imports
110
+ import sys
111
+
112
+ # Test 1: Basic imports
113
+ from composio import Composio
114
+ print('✓ Basic Composio import')
115
+
116
+ # Test 2: Import toolkit version types
117
+ from composio import ToolkitVersionParam
118
+ from composio.core.types import ToolkitVersion
119
+ print('✓ Toolkit version types import')
120
+
121
+ # Test 3: Import from types module
122
+ from composio.types import Modifiers
123
+ print('✓ Types module import')
124
+
125
+ # Test 4: Import core models
126
+ from composio.core.models.tools import Tools
127
+ print('✓ Core models import')
128
+
129
+ # Test 5: Cross-module imports that caused the original circular import
130
+ from composio.core.models.tools import Modifiers as CoreModifiers
131
+ from composio.types import Modifiers as TypesModifiers
132
+ assert CoreModifiers is TypesModifiers
133
+ print('✓ Cross-module import consistency')
134
+
135
+ print('✓ All circular import prevention tests passed!')
136
+ "
137
+
138
+ lint-and-format:
139
+ name: Lint and Format Check
140
+ runs-on: ubuntu-latest
141
+
142
+ steps:
143
+ - name: Checkout Code
144
+ uses: actions/checkout@v4
145
+
146
+ - name: Set up Python
147
+ uses: actions/setup-python@v5
148
+ with:
149
+ python-version: "3.11"
150
+
151
+ - name: Install UV
152
+ run: pip install uv
153
+
154
+ - name: Install Dependencies
155
+ run: |
156
+ cd python/
157
+ uv venv --python 3.11
158
+ source .venv/bin/activate
159
+ uv pip install -e .
160
+ uv pip install ruff
161
+
162
+ - name: Run Ruff Linter
163
+ run: |
164
+ cd python/
165
+ source .venv/bin/activate
166
+ ruff check --config config/ruff.toml composio/ tests/
167
+
168
+ - name: Run Ruff Formatter Check
169
+ run: |
170
+ cd python/
171
+ source .venv/bin/activate
172
+ ruff format --check --config config/ruff.toml composio/ tests/
python/composio/__init__.py
+2
-2
@@ -4,13 +4,13 @@ from .core.models.tools import (
4
before_execute,
5
schema_modifier,
6
)
7
-from .sdk import Composio
8
-from .types import (
7
+from .core.types import (
8
ToolkitLatestVersion,
9
ToolkitVersion,
10
ToolkitVersionParam,
11
ToolkitVersions,
12
)
13
+from .sdk import Composio
14
15
__all__ = (
16
"Composio",
python/composio/core/models/connected_accounts.py
+10
-10
@@ -351,7 +351,7 @@ class ConnectedAccounts:
351
redirect_url=getattr(response.connection_data.val, "redirect_url", None),
352
client=self._client,
353
)
354
-
354
+
355
def link(
356
self,
357
user_id: str,
@@ -361,33 +361,33 @@ class ConnectedAccounts:
361
) -> ConnectionRequest:
362
"""
363
Create a Composio Connect Link for a user to connect their account to a given auth config.
364
-
364
+
365
This method will return an external link which you can use for the user to connect their account.
366
367
:param user_id: The external user ID to create the connected account for.
368
:param auth_config_id: The auth config ID to create the connected account for.
369
:param callback_url: The URL to redirect the user to post connecting their account.
370
:return: Connection request object.
371
-
371
+
372
Example:
373
# Create a connection request and redirect the user to the redirect url
374
connection_request = composio.connected_accounts.link('user_123', 'auth_config_123')
375
redirect_url = connection_request.redirect_url
376
print(f"Visit: {redirect_url} to authenticate your account")
377
-
377
+
378
# Wait for the connection to be established
379
connected_account = connection_request.wait_for_connection()
380
-
380
+
381
Example with callback URL:
382
# Create a connection request with callback URL
383
connection_request = composio.connected_accounts.link(
384
- 'user_123',
384
+ 'user_123',
385
'auth_config_123',
386
callback_url='https://your-app.com/callback'
387
)
388
redirect_url = connection_request.redirect_url
389
print(f"Visit: {redirect_url} to authenticate your account")
390
-
390
+
391
# Wait for the connection to be established
392
connected_account = composio.connected_accounts.wait_for_connection(connection_request.id)
393
"""
@@ -396,14 +396,14 @@ class ConnectedAccounts:
396
"auth_config_id": auth_config_id,
397
"user_id": user_id,
398
}
399
-
399
+
400
# Add callback_url only if provided
401
if callback_url is not None:
402
payload["callback_url"] = callback_url
403
-
403
+
404
# Call the link creation endpoint
405
response = self._client.link.create(**payload)
406
-
406
+
407
return ConnectionRequest(
408
id=response.connected_account_id,
409
status="INITIATED",
python/composio/core/models/tools.py
+12
-5
@@ -23,8 +23,8 @@ from composio.core.provider.none_agentic import (
23
NonAgenticProvider,
24
NoneAgenticProviderExecuteFn,
25
)
26
+from composio.core.types import ToolkitVersionParam
27
from composio.exceptions import InvalidParams, NotFoundError
27
-from composio.types import ToolkitVersionParam
28
from composio.utils.toolkit_version import get_toolkit_version
29
30
from ._modifiers import (
@@ -72,7 +72,7 @@ class Tools(Resource, t.Generic[TProvider]):
72
self._custom_tools = CustomTools(client)
73
self._tool_schemas: t.Dict[str, Tool] = {}
74
self._file_helper = FileHelper(client=self._client, outdir=file_download_dir)
75
- self._toolkit_versions = toolkit_versions or "latest"
75
+ self._toolkit_versions = toolkit_versions
76
77
self.custom_tool = self._custom_tools.register
78
self.provider = provider
@@ -338,6 +338,15 @@ class Tools(Resource, t.Generic[TProvider]):
338
toolkit_versions: t.Optional[ToolkitVersionParam] = None,
339
) -> ToolExecutionResponse:
340
"""Execute a tool"""
341
+ # Get the tool to determine its toolkit
342
+ tool = self.get_raw_composio_tool_by_slug(slug)
343
+
344
+ # If version is not explicitly provided, resolve it from toolkit versions
345
+ # This matches the TypeScript behavior
346
+ if version is None and toolkit_versions is not None:
347
+ toolkit_slug = tool.toolkit.slug if tool.toolkit else "unknown"
348
+ version = get_toolkit_version(toolkit_slug, toolkit_versions)
349
+
350
return t.cast(
351
ToolExecutionResponse,
352
self._client.tools.execute(
@@ -361,9 +370,7 @@ class Tools(Resource, t.Generic[TProvider]):
370
user_id=user_id if user_id is not None else self._client.not_given,
371
text=text if text is not None else self._client.not_given,
372
version=version if version is not None else self._client.not_given,
364
- toolkit_versions=toolkit_versions
365
- if toolkit_versions is not None
366
- else self._client.not_given,
373
+ # Note: We don't pass toolkit_versions to the API, we resolve the specific version above
374
).model_dump(
375
exclude={
376
"log_id",
python/composio/core/types.py
new
+20
@@ -0,0 +1,20 @@
1
+"""Core types for Composio SDK."""
2
+
3
+import typing as t
4
+
5
+import typing_extensions as te
6
+
7
+# Tool versioning types
8
+ToolkitLatestVersion = te.Literal["latest"]
9
+ToolkitVersion = str # Can be "latest" or any version string like "20250906_01"
10
+ToolkitVersions = t.Dict[str, ToolkitVersion]
11
+ToolkitVersionParam = t.Union[
12
+ str, ToolkitVersions, None
13
+] # String can be any global version
14
+
15
+__all__ = [
16
+ "ToolkitLatestVersion",
17
+ "ToolkitVersion",
18
+ "ToolkitVersions",
19
+ "ToolkitVersionParam",
20
+]
python/composio/sdk.py
+2
-2
@@ -17,7 +17,7 @@ from composio.core.models import (
17
from composio.core.models.base import allow_tracking
18
from composio.core.provider import TProvider
19
from composio.core.provider._openai import OpenAIProvider
20
-from composio.types import ToolkitVersionParam
20
+from composio.core.types import ToolkitVersionParam
21
from composio.utils.logging import WithLogger
22
from composio.utils.toolkit_version import get_toolkit_versions
23
@@ -66,7 +66,7 @@ class Composio(t.Generic[TProvider], WithLogger):
66
if not api_key:
67
raise exceptions.ApiKeyNotProvidedError()
68
69
- # Process toolkit versions
69
+ # Process toolkit versions with environment variable support
70
toolkit_versions = get_toolkit_versions(kwargs.get("toolkit_versions"))
71
72
allow_tracking.set(kwargs.get("allow_tracking", True))
python/composio/types.py
+6
-12
@@ -1,7 +1,3 @@
1
-import typing as t
2
-
3
-import typing_extensions as te
4
-
1
from composio.client.types import Tool
2
from composio.core.models.connected_accounts import auth_scheme
3
from composio.core.models.custom_tools import ExecuteRequestFn
@@ -12,14 +8,12 @@ from composio.core.models.tools import (
8
)
9
from composio.core.models.triggers import TriggerEvent
10
from composio.core.provider.base import TTool, TToolCollection
15
-
16
-# Tool versioning types
17
-ToolkitLatestVersion = te.Literal["latest"]
18
-ToolkitVersion = str # Can be "latest" or any version string like "20250906_01"
19
-ToolkitVersions = t.Dict[str, ToolkitVersion]
20
-ToolkitVersionParam = t.Union[
21
- str, ToolkitVersions, None
22
-] # String can be any global version
11
+from composio.core.types import (
12
+ ToolkitLatestVersion,
13
+ ToolkitVersion,
14
+ ToolkitVersionParam,
15
+ ToolkitVersions,
16
+)
17
18
__all__ = [
19
# Existing types
python/composio/utils/toolkit_version.py
+1
-1
@@ -5,7 +5,7 @@ Utilities for handling toolkit versions.
5
import os
6
import typing as t
7
8
-from composio.types import ToolkitVersion, ToolkitVersionParam, ToolkitVersions
8
+from composio.core.types import ToolkitVersion, ToolkitVersionParam, ToolkitVersions
9
10
11
def get_toolkit_version(
python/providers/anthropic/pyproject.toml
+1
-1
@@ -1,6 +1,6 @@
1
[project]
2
name = "composio-anthropic"
3
-version = "0.8.11"
3
+version = "0.8.12"
4
description = "Use Composio to get an array of tools with your Anthropic LLMs."
5
readme = "README.md"
6
requires-python = ">=3.10,<4"
python/providers/anthropic/setup.py
+1
-1
@@ -8,7 +8,7 @@ from setuptools import setup
8
9
setup(
10
name="composio_anthropic",
11
- version="0.8.11",
11
+ version="0.8.12",
12
author="Composio",
13
author_email="tech@composio.dev",
14
description="Use Composio to get an array of tools with your Anthropic LLMs.",
python/providers/autogen/pyproject.toml
+1
-1
@@ -1,6 +1,6 @@
1
[project]
2
name = "composio-autogen"
3
-version = "0.8.11"
3
+version = "0.8.12"
4
description = "Use Composio to get an array of tools with your autogen agent."
5
readme = "README.md"
6
requires-python = ">=3.9,<4"
python/providers/autogen/setup.py
+1
-1
@@ -8,7 +8,7 @@ from setuptools import setup
8
9
setup(
10
name="composio_autogen",
11
- version="0.8.11",
11
+ version="0.8.12",
12
author="Composio",
13
author_email="tech@composio.dev",
14
description="Use Composio to get an array of tools with your Autogen agent.",
python/providers/crewai/pyproject.toml
+1
-1
@@ -1,6 +1,6 @@
1
[project]
2
name = "composio-crewai"
3
-version = "0.8.11"
3
+version = "0.8.12"
4
description = "Use Composio to get an array of tools with your CrewAI agent."
5
readme = "README.md"
6
requires-python = ">=3.9,<4"
python/providers/crewai/setup.py
+1
-1
@@ -6,7 +6,7 @@ from setuptools import setup
6
7
setup(
8
name="composio_crewai",
9
- version="0.8.11",
9
+ version="0.8.12",
10
author="Composio",
11
author_email="tech@composio.dev",
12
description="Use Composio to get an array of tools with your CrewAI agent.",
python/providers/gemini/pyproject.toml
+1
-1
@@ -1,6 +1,6 @@
1
[project]
2
name = "composio-gemini"
3
-version = "0.8.11"
3
+version = "0.8.12"
4
description = "Use Composio to get an array of tools with your Gemini agent."
5
readme = "README.md"
6
requires-python = ">=3.9,<4"
python/providers/gemini/setup.py
+1
-1
@@ -8,7 +8,7 @@ from setuptools import setup
8
9
setup(
10
name="composio_gemini",
11
- version="0.8.11",
11
+ version="0.8.12",
12
author="Composio",
13
author_email="tech@composio.dev",
14
description="Use Composio to get an array of tools with your Gemini agent.",
python/providers/google/pyproject.toml
+1
-1
@@ -1,6 +1,6 @@
1
[project]
2
name = "composio-google"
3
-version = "0.8.11"
3
+version = "0.8.12"
4
description = "Use Composio to get an array of tools with your Google AI Python Gemini model."
5
readme = "README.md"
6
requires-python = ">=3.9,<4"
python/providers/google/setup.py
+1
-1
@@ -8,7 +8,7 @@ from setuptools import setup
8
9
setup(
10
name="composio_google",
11
- version="0.8.11",
11
+ version="0.8.12",
12
author="Composio",
13
author_email="tech@composio.dev",
14
description="Use Composio to get an array of tools with your Google AI Python Gemini model.",
python/providers/google_adk/pyproject.toml
+1
-1
@@ -1,6 +1,6 @@
1
[project]
2
name = "composio-google-adk"
3
-version = "0.8.11"
3
+version = "0.8.12"
4
description = "Use Composio to get an array of tools with your Google AI Python Gemini model."
5
readme = "README.md"
6
requires-python = ">=3.9,<4"
python/providers/google_adk/setup.py
+1
-1
@@ -8,7 +8,7 @@ from setuptools import setup
8
9
setup(
10
name="composio_google_adk",
11
- version="0.8.11",
11
+ version="0.8.12",
12
author="Composio",
13
author_email="tech@composio.dev",
14
description="Use Composio to get an array of tools with your Google AI Python Gemini model.",
python/providers/langchain/pyproject.toml
+1
-1
@@ -1,6 +1,6 @@
1
[project]
2
name = "composio-langchain"
3
-version = "0.8.11"
3
+version = "0.8.12"
4
description = "Use Composio to get an array of tools with your Langchain agent."
5
readme = "README.md"
6
requires-python = ">=3.9,<4"
python/providers/langchain/setup.py
+1
-1
@@ -8,7 +8,7 @@ from setuptools import setup
8
9
setup(
10
name="composio_langchain",
11
- version="0.8.11",
11
+ version="0.8.12",
12
author="composio",
13
author_email="tech@composio.dev",
14
description="Use Composio to get an array of tools with your Langchain agent.",
python/providers/langgraph/pyproject.toml
+1
-1
@@ -1,6 +1,6 @@
1
[project]
2
name = "composio-langgraph"
3
-version = "0.8.11"
3
+version = "0.8.12"
4
description = "Use Composio to get array of tools with LangGraph Agent Workflows."
5
readme = "README.md"
6
requires-python = ">=3.9,<4"
python/providers/langgraph/setup.py
+1
-1
@@ -8,7 +8,7 @@ from setuptools import setup
8
9
setup(
10
name="composio_langgraph",
11
- version="0.8.11",
11
+ version="0.8.12",
12
author="composio",
13
author_email="tech@composio.dev",
14
description="Use Composio to get array of tools with LangGraph Agent Workflows",
python/providers/llamaindex/pyproject.toml
+1
-1
@@ -1,6 +1,6 @@
1
[project]
2
name = "composio-llamaindex"
3
-version = "0.8.11"
3
+version = "0.8.12"
4
description = "Use Composio to get array of tools with LlamaIndex Agent Workflows."
5
readme = "README.md"
6
requires-python = ">=3.9,<4"
python/providers/llamaindex/setup.py
+1
-1
@@ -8,7 +8,7 @@ from setuptools import setup
8
9
setup(
10
name="composio_llamaindex",
11
- version="0.8.11",
11
+ version="0.8.12",
12
author="composio",
13
author_email="tech@composio.dev",
14
description="Use Composio to get array of tools with LlamaIndex Agent Workflows",
python/providers/openai/pyproject.toml
+1
-1
@@ -1,6 +1,6 @@
1
[project]
2
name = "composio-openai"
3
-version = "0.8.11"
3
+version = "0.8.12"
4
description = "Use Composio to get an array of tools with your OpenAI Function Call."
5
readme = "README.md"
6
requires-python = ">=3.9,<4"
python/providers/openai/setup.py
+1
-1
@@ -8,7 +8,7 @@ from setuptools import setup
8
9
setup(
10
name="composio_openai",
11
- version="0.8.11",
11
+ version="0.8.12",
12
author="Composio",
13
author_email="tech@composio.dev",
14
description="Use Composio to get an array of tools with your OpenAI Function Call.",
python/providers/openai_agents/pyproject.toml
+1
-1
@@ -1,6 +1,6 @@
1
[project]
2
name = "composio-openai-agents"
3
-version = "0.8.11"
3
+version = "0.8.12"
4
description = "Use Composio to get array of strongly typed tools for OpenAI Agents"
5
readme = "README.md"
6
requires-python = ">=3.9,<4"
python/providers/openai_agents/setup.py
+1
-1
@@ -8,7 +8,7 @@ from setuptools import find_packages, setup
8
9
setup(
10
name="composio_openai_agents",
11
- version="0.8.11",
11
+ version="0.8.12",
12
author="Composio",
13
author_email="tech@composio.dev",
14
description="Use Composio to get array of strongly typed tools for OpenAI Agents",
python/pyproject.toml
+1
-1
@@ -1,6 +1,6 @@
1
[project]
2
name = "composio"
3
-version = "0.8.13"
3
+version = "0.8.14"
4
description = "SDK for integrating Composio with your applications."
5
readme = "README.md"
6
requires-python = ">=3.10,<4"
python/tests/test_core_types.py
new
+120
@@ -0,0 +1,120 @@
1
+"""Test core types module."""
2
+
3
+from composio.core.types import (
4
+ ToolkitLatestVersion,
5
+ ToolkitVersion,
6
+ ToolkitVersionParam,
7
+ ToolkitVersions,
8
+)
9
+
10
+
11
+class TestCoreTypes:
12
+ """Test cases for core types."""
13
+
14
+ def test_toolkit_latest_version_literal(self):
15
+ """Test ToolkitLatestVersion is a literal type."""
16
+ # Should be a Literal["latest"]
17
+ assert hasattr(ToolkitLatestVersion, "__origin__")
18
+
19
+ def test_toolkit_version_is_string(self):
20
+ """Test ToolkitVersion is string type."""
21
+ assert ToolkitVersion is str
22
+
23
+ def test_toolkit_versions_is_dict(self):
24
+ """Test ToolkitVersions is dict type."""
25
+ # Should be Dict[str, ToolkitVersion]
26
+ assert hasattr(ToolkitVersions, "__origin__")
27
+ assert ToolkitVersions.__origin__ is dict
28
+
29
+ def test_toolkit_version_param_is_union(self):
30
+ """Test ToolkitVersionParam is union type."""
31
+ # Should be Union[str, ToolkitVersions, None]
32
+ assert hasattr(ToolkitVersionParam, "__origin__")
33
+
34
+ def test_toolkit_version_param_accepts_string(self):
35
+ """Test ToolkitVersionParam accepts string."""
36
+ version: ToolkitVersionParam = "latest"
37
+ assert version == "latest"
38
+
39
+ version = "v1.0.0"
40
+ assert version == "v1.0.0"
41
+
42
+ def test_toolkit_version_param_accepts_dict(self):
43
+ """Test ToolkitVersionParam accepts dictionary."""
44
+ version: ToolkitVersionParam = {"github": "v1.0.0", "slack": "latest"}
45
+ assert isinstance(version, dict)
46
+ assert version["github"] == "v1.0.0"
47
+ assert version["slack"] == "latest"
48
+
49
+ def test_toolkit_version_param_accepts_none(self):
50
+ """Test ToolkitVersionParam accepts None."""
51
+ version: ToolkitVersionParam = None
52
+ assert version is None
53
+
54
+ def test_all_types_exported(self):
55
+ """Test that all types are properly exported."""
56
+ from composio.core.types import __all__
57
+
58
+ expected_exports = {
59
+ "ToolkitLatestVersion",
60
+ "ToolkitVersion",
61
+ "ToolkitVersions",
62
+ "ToolkitVersionParam",
63
+ }
64
+
65
+ assert set(__all__) == expected_exports
66
+
67
+ def test_types_importable_from_main_package(self):
68
+ """Test that types are importable from main package."""
69
+ from composio import (
70
+ ToolkitLatestVersion,
71
+ ToolkitVersion,
72
+ ToolkitVersionParam,
73
+ ToolkitVersions,
74
+ )
75
+
76
+ # Should be the same objects
77
+ from composio.core.types import (
78
+ ToolkitLatestVersion as CoreToolkitLatestVersion,
79
+ )
80
+ from composio.core.types import (
81
+ ToolkitVersion as CoreToolkitVersion,
82
+ )
83
+ from composio.core.types import (
84
+ ToolkitVersionParam as CoreToolkitVersionParam,
85
+ )
86
+ from composio.core.types import (
87
+ ToolkitVersions as CoreToolkitVersions,
88
+ )
89
+
90
+ assert ToolkitLatestVersion is CoreToolkitLatestVersion
91
+ assert ToolkitVersion is CoreToolkitVersion
92
+ assert ToolkitVersionParam is CoreToolkitVersionParam
93
+ assert ToolkitVersions is CoreToolkitVersions
94
+
95
+ def test_types_importable_from_types_module(self):
96
+ """Test that types are importable from types module."""
97
+ # Should be the same objects as core types
98
+ from composio.core.types import (
99
+ ToolkitLatestVersion as CoreToolkitLatestVersion,
100
+ )
101
+ from composio.core.types import (
102
+ ToolkitVersion as CoreToolkitVersion,
103
+ )
104
+ from composio.core.types import (
105
+ ToolkitVersionParam as CoreToolkitVersionParam,
106
+ )
107
+ from composio.core.types import (
108
+ ToolkitVersions as CoreToolkitVersions,
109
+ )
110
+ from composio.types import (
111
+ ToolkitLatestVersion,
112
+ ToolkitVersion,
113
+ ToolkitVersionParam,
114
+ ToolkitVersions,
115
+ )
116
+
117
+ assert ToolkitLatestVersion is CoreToolkitLatestVersion
118
+ assert ToolkitVersion is CoreToolkitVersion
119
+ assert ToolkitVersionParam is CoreToolkitVersionParam
120
+ assert ToolkitVersions is CoreToolkitVersions
python/tests/test_imports.py
new
+130
@@ -0,0 +1,130 @@
1
+"""Test imports to ensure no circular import issues."""
2
+
3
+import pytest
4
+
5
+
6
+def test_basic_import():
7
+ """Test basic import of Composio class."""
8
+ from composio import Composio
9
+
10
+ assert Composio is not None
11
+
12
+
13
+def test_import_all_public_exports():
14
+ """Test importing all public exports from composio package."""
15
+ from composio import (
16
+ Composio,
17
+ ToolkitLatestVersion,
18
+ ToolkitVersion,
19
+ ToolkitVersionParam,
20
+ ToolkitVersions,
21
+ __version__,
22
+ after_execute,
23
+ before_execute,
24
+ schema_modifier,
25
+ )
26
+
27
+ assert Composio is not None
28
+ assert after_execute is not None
29
+ assert before_execute is not None
30
+ assert schema_modifier is not None
31
+ assert ToolkitLatestVersion is not None
32
+ assert ToolkitVersion is not None
33
+ assert ToolkitVersionParam is not None
34
+ assert ToolkitVersions is not None
35
+ assert __version__ is not None
36
+
37
+
38
+def test_import_types():
39
+ """Test importing types from different modules."""
40
+ from composio.types import (
41
+ ExecuteRequestFn,
42
+ Modifiers,
43
+ Tool,
44
+ ToolExecuteParams,
45
+ ToolExecutionResponse,
46
+ ToolkitLatestVersion,
47
+ ToolkitVersion,
48
+ ToolkitVersionParam,
49
+ ToolkitVersions,
50
+ TriggerEvent,
51
+ TTool,
52
+ TToolCollection,
53
+ auth_scheme,
54
+ )
55
+
56
+ assert Tool is not None
57
+ assert TTool is not None
58
+ assert TToolCollection is not None
59
+ assert ToolExecuteParams is not None
60
+ assert ToolExecutionResponse is not None
61
+ assert ExecuteRequestFn is not None
62
+ assert TriggerEvent is not None
63
+ assert Modifiers is not None
64
+ assert auth_scheme is not None
65
+ assert ToolkitLatestVersion is not None
66
+ assert ToolkitVersion is not None
67
+ assert ToolkitVersions is not None
68
+ assert ToolkitVersionParam is not None
69
+
70
+
71
+def test_import_core_types():
72
+ """Test importing core types directly."""
73
+ from composio.core.types import (
74
+ ToolkitLatestVersion,
75
+ ToolkitVersion,
76
+ ToolkitVersionParam,
77
+ ToolkitVersions,
78
+ )
79
+
80
+ assert ToolkitLatestVersion is not None
81
+ assert ToolkitVersion is not None
82
+ assert ToolkitVersions is not None
83
+ assert ToolkitVersionParam is not None
84
+
85
+
86
+def test_import_core_models():
87
+ """Test importing core models."""
88
+ from composio.core.models import (
89
+ AuthConfigs,
90
+ ConnectedAccounts,
91
+ Toolkits,
92
+ Tools,
93
+ Triggers,
94
+ )
95
+
96
+ assert AuthConfigs is not None
97
+ assert ConnectedAccounts is not None
98
+ assert Toolkits is not None
99
+ assert Tools is not None
100
+ assert Triggers is not None
101
+
102
+
103
+def test_import_sdk():
104
+ """Test importing SDK directly."""
105
+ from composio.sdk import Composio
106
+
107
+ assert Composio is not None
108
+
109
+
110
+def test_import_exceptions():
111
+ """Test importing exceptions."""
112
+ from composio import exceptions
113
+
114
+ assert exceptions is not None
115
+ assert hasattr(exceptions, "ApiKeyNotProvidedError")
116
+
117
+
118
+def test_circular_import_prevention():
119
+ """Test that circular imports are prevented."""
120
+ # This test passes if no ImportError is raised during import
121
+ try:
122
+ from composio import Composio # noqa: F401
123
+ from composio.core.models.tools import Tools # noqa: F401
124
+ from composio.core.types import ToolkitVersion # noqa: F401
125
+ from composio.types import ToolkitVersionParam # noqa: F401
126
+
127
+ # If we get here, no circular import occurred
128
+ assert True
129
+ except ImportError as e:
130
+ pytest.fail(f"Circular import detected: {e}")
python/tests/test_sdk.py
new
+207
@@ -0,0 +1,207 @@
1
+"""Test SDK functionality."""
2
+
3
+import os
4
+from unittest.mock import patch
5
+
6
+import pytest
7
+
8
+from composio import Composio, exceptions
9
+from composio.core.types import ToolkitVersionParam
10
+
11
+
12
+class TestComposioSDK:
13
+ """Test cases for Composio SDK."""
14
+
15
+ def test_sdk_requires_api_key(self):
16
+ """Test that SDK requires an API key."""
17
+ with patch.dict(os.environ, {}, clear=True):
18
+ with pytest.raises(exceptions.ApiKeyNotProvidedError):
19
+ Composio()
20
+
21
+ def test_sdk_accepts_api_key_from_env(self):
22
+ """Test that SDK accepts API key from environment."""
23
+ with patch.dict(os.environ, {"COMPOSIO_API_KEY": "test-key"}):
24
+ with patch("composio.core.models.Tools"):
25
+ with patch("composio.core.models.Toolkits"):
26
+ with patch("composio.core.models.Triggers"):
27
+ with patch("composio.core.models.AuthConfigs"):
28
+ with patch("composio.core.models.ConnectedAccounts"):
29
+ sdk = Composio()
30
+ assert sdk is not None
31
+
32
+ def test_sdk_accepts_api_key_as_parameter(self):
33
+ """Test that SDK accepts API key as parameter."""
34
+ with patch("composio.core.models.Tools"):
35
+ with patch("composio.core.models.Toolkits"):
36
+ with patch("composio.core.models.Triggers"):
37
+ with patch("composio.core.models.AuthConfigs"):
38
+ with patch("composio.core.models.ConnectedAccounts"):
39
+ sdk = Composio(api_key="test-key")
40
+ assert sdk is not None
41
+
42
+ def test_sdk_config_types(self):
43
+ """Test SDK configuration types."""
44
+ from composio.sdk import SDKConfig
45
+
46
+ # Test that SDKConfig is a TypedDict
47
+ assert hasattr(SDKConfig, "__annotations__")
48
+
49
+ # Test that all expected fields are present
50
+ expected_fields = {
51
+ "environment",
52
+ "api_key",
53
+ "base_url",
54
+ "timeout",
55
+ "max_retries",
56
+ "allow_tracking",
57
+ "file_download_dir",
58
+ "toolkit_versions",
59
+ }
60
+ assert set(SDKConfig.__annotations__.keys()) == expected_fields
61
+
62
+ def test_toolkit_version_param_types(self):
63
+ """Test toolkit version parameter types."""
64
+ from composio.core.types import (
65
+ ToolkitLatestVersion,
66
+ ToolkitVersion,
67
+ ToolkitVersions,
68
+ )
69
+
70
+ # Test that types are defined correctly
71
+ assert ToolkitLatestVersion is not None
72
+ assert ToolkitVersion is not None
73
+ assert ToolkitVersions is not None
74
+ assert ToolkitVersionParam is not None
75
+
76
+ def test_sdk_has_required_attributes(self):
77
+ """Test that SDK has required attributes after initialization."""
78
+ with patch.dict(os.environ, {"COMPOSIO_API_KEY": "test-key"}):
79
+ with patch("composio.core.models.Tools"):
80
+ with patch("composio.core.models.Toolkits"):
81
+ with patch("composio.core.models.Triggers"):
82
+ with patch("composio.core.models.AuthConfigs"):
83
+ with patch("composio.core.models.ConnectedAccounts"):
84
+ sdk = Composio()
85
+
86
+ # Check that all required attributes are present
87
+ assert hasattr(sdk, "tools")
88
+ assert hasattr(sdk, "toolkits")
89
+ assert hasattr(sdk, "triggers")
90
+ assert hasattr(sdk, "auth_configs")
91
+ assert hasattr(sdk, "connected_accounts")
92
+ assert hasattr(sdk, "provider")
93
+ assert hasattr(sdk, "client")
94
+
95
+ def test_sdk_default_provider(self):
96
+ """Test that SDK uses default provider."""
97
+ with patch.dict(os.environ, {"COMPOSIO_API_KEY": "test-key"}):
98
+ with patch("composio.core.models.Tools"):
99
+ with patch("composio.core.models.Toolkits"):
100
+ with patch("composio.core.models.Triggers"):
101
+ with patch("composio.core.models.AuthConfigs"):
102
+ with patch("composio.core.models.ConnectedAccounts"):
103
+ sdk = Composio()
104
+
105
+ # Check that provider is set
106
+ assert sdk.provider is not None
107
+ assert hasattr(sdk.provider, "name")
108
+
109
+ def test_toolkit_versions_processing(self):
110
+ """Test toolkit versions parameter processing."""
111
+ with patch.dict(os.environ, {"COMPOSIO_API_KEY": "test-key"}):
112
+ with patch("composio.core.models.Tools"):
113
+ with patch("composio.core.models.Toolkits"):
114
+ with patch("composio.core.models.Triggers"):
115
+ with patch("composio.core.models.AuthConfigs"):
116
+ with patch("composio.core.models.ConnectedAccounts"):
117
+ with patch(
118
+ "composio.sdk.get_toolkit_versions"
119
+ ) as mock_get_versions:
120
+ mock_get_versions.return_value = "latest"
121
+
122
+ # Test with string version
123
+ Composio(toolkit_versions="v1.0.0")
124
+ mock_get_versions.assert_called_once()
125
+
126
+ # Reset mock for next test
127
+ mock_get_versions.reset_mock()
128
+
129
+ # Test with dict version
130
+ versions_dict = {
131
+ "github": "v1.0.0",
132
+ "slack": "latest",
133
+ }
134
+ Composio(toolkit_versions=versions_dict)
135
+ mock_get_versions.assert_called_once()
136
+
137
+ # Reset mock for next test
138
+ mock_get_versions.reset_mock()
139
+
140
+ # Test with None (default)
141
+ Composio()
142
+ mock_get_versions.assert_called_once()
143
+
144
+ def test_sdk_env_var_integration(self):
145
+ """Test that SDK properly integrates with environment variables for toolkit versions."""
146
+ with patch.dict(
147
+ os.environ,
148
+ {
149
+ "COMPOSIO_API_KEY": "test-key",
150
+ "COMPOSIO_TOOLKIT_VERSION_GITHUB": "v1.0.0",
151
+ "COMPOSIO_TOOLKIT_VERSION_SLACK": "v2.0.0",
152
+ },
153
+ ):
154
+ with patch("composio.sdk.Tools") as mock_tools_class:
155
+ with patch("composio.sdk.Toolkits"):
156
+ with patch("composio.sdk.Triggers"):
157
+ with patch("composio.sdk.AuthConfigs"):
158
+ with patch("composio.sdk.ConnectedAccounts"):
159
+ # Create SDK instance without explicit toolkit versions
160
+ Composio()
161
+
162
+ # Verify that Tools was initialized with processed versions
163
+ mock_tools_class.assert_called_once()
164
+ call_args = mock_tools_class.call_args
165
+
166
+ # The toolkit_versions should be a dict from env vars
167
+ toolkit_versions = call_args.kwargs.get(
168
+ "toolkit_versions"
169
+ )
170
+ expected = {"github": "v1.0.0", "slack": "v2.0.0"}
171
+ assert toolkit_versions == expected
172
+
173
+ def test_sdk_user_override_env_vars(self):
174
+ """Test that user-provided toolkit versions override environment variables."""
175
+ with patch.dict(
176
+ os.environ,
177
+ {
178
+ "COMPOSIO_API_KEY": "test-key",
179
+ "COMPOSIO_TOOLKIT_VERSION_GITHUB": "env_version",
180
+ "COMPOSIO_TOOLKIT_VERSION_SLACK": "env_slack",
181
+ },
182
+ ):
183
+ with patch("composio.sdk.Tools") as mock_tools_class:
184
+ with patch("composio.sdk.Toolkits"):
185
+ with patch("composio.sdk.Triggers"):
186
+ with patch("composio.sdk.AuthConfigs"):
187
+ with patch("composio.sdk.ConnectedAccounts"):
188
+ # User provides override
189
+ user_versions = {
190
+ "github": "user_override",
191
+ "jira": "user_jira",
192
+ }
193
+ Composio(toolkit_versions=user_versions)
194
+
195
+ # Verify Tools was initialized with merged versions
196
+ mock_tools_class.assert_called_once()
197
+ call_args = mock_tools_class.call_args
198
+
199
+ toolkit_versions = call_args.kwargs.get(
200
+ "toolkit_versions"
201
+ )
202
+ expected = {
203
+ "github": "user_override", # User override
204
+ "slack": "env_slack", # From env
205
+ "jira": "user_jira", # User provided
206
+ }
207
+ assert toolkit_versions == expected
python/tests/test_tool_execution.py
new
+293
@@ -0,0 +1,293 @@
1
+"""Test tool execution with toolkit versions."""
2
+
3
+from unittest.mock import Mock, patch
4
+
5
+from composio.client.types import Tool, tool_list_response
6
+from composio.core.models.tools import Tools
7
+
8
+
9
+class TestToolExecution:
10
+ """Test cases for tool execution with toolkit versions."""
11
+
12
+ def create_mock_tool(self, slug: str, toolkit_slug: str) -> Tool:
13
+ """Create a mock tool for testing."""
14
+ return Tool(
15
+ name=f"Test {slug}",
16
+ slug=slug,
17
+ description="Test tool",
18
+ input_parameters={},
19
+ output_parameters={},
20
+ available_versions=["v1.0.0"],
21
+ version="v1.0.0",
22
+ scopes=[],
23
+ toolkit=tool_list_response.ItemToolkit(
24
+ name=toolkit_slug.title(), slug=toolkit_slug, logo=""
25
+ ),
26
+ deprecated=tool_list_response.ItemDeprecated(
27
+ available_versions=["v1.0.0"],
28
+ displayName=f"Test {slug}",
29
+ version="v1.0.0",
30
+ toolkit=tool_list_response.ItemDeprecatedToolkit(logo=""),
31
+ is_deprecated=False,
32
+ ),
33
+ no_auth=False,
34
+ tags=[],
35
+ )
36
+
37
+ def test_tool_execution_uses_toolkit_version(self):
38
+ """Test that tool execution resolves toolkit version correctly."""
39
+ # Mock client and provider
40
+ mock_client = Mock()
41
+ mock_provider = Mock()
42
+ mock_provider.name = "test_provider"
43
+
44
+ # Create toolkit versions configuration
45
+ toolkit_versions = {"github": "v2.0.0", "slack": "v1.5.0"}
46
+
47
+ # Create Tools instance
48
+ tools = Tools(
49
+ client=mock_client,
50
+ provider=mock_provider,
51
+ toolkit_versions=toolkit_versions,
52
+ )
53
+
54
+ # Create a mock GitHub tool
55
+ github_tool = self.create_mock_tool("GITHUB_GET_REPOS", "github")
56
+
57
+ # Mock the get_raw_composio_tool_by_slug method
58
+ with patch.object(
59
+ tools, "get_raw_composio_tool_by_slug", return_value=github_tool
60
+ ):
61
+ # Mock the client's execute method
62
+ mock_execute_response = Mock()
63
+ mock_execute_response.model_dump.return_value = {
64
+ "data": {"result": "success"},
65
+ "error": None,
66
+ "successful": True,
67
+ }
68
+ mock_client.tools.execute.return_value = mock_execute_response
69
+
70
+ # Execute the tool
71
+ tools._execute_tool(
72
+ slug="GITHUB_GET_REPOS",
73
+ arguments={"owner": "test", "repo": "test"},
74
+ toolkit_versions=toolkit_versions,
75
+ )
76
+
77
+ # Verify that the client was called with the resolved version
78
+ mock_client.tools.execute.assert_called_once()
79
+ call_args = mock_client.tools.execute.call_args
80
+
81
+ # Should have called with version="v2.0.0" (resolved from github toolkit)
82
+ assert call_args.kwargs["version"] == "v2.0.0"
83
+
84
+ def test_tool_execution_with_explicit_version(self):
85
+ """Test that explicit version overrides toolkit version."""
86
+ # Mock client and provider
87
+ mock_client = Mock()
88
+ mock_provider = Mock()
89
+ mock_provider.name = "test_provider"
90
+
91
+ # Create toolkit versions configuration
92
+ toolkit_versions = {
93
+ "github": "v2.0.0",
94
+ }
95
+
96
+ # Create Tools instance
97
+ tools = Tools(
98
+ client=mock_client,
99
+ provider=mock_provider,
100
+ toolkit_versions=toolkit_versions,
101
+ )
102
+
103
+ # Create a mock GitHub tool
104
+ github_tool = self.create_mock_tool("GITHUB_GET_REPOS", "github")
105
+
106
+ # Mock the get_raw_composio_tool_by_slug method
107
+ with patch.object(
108
+ tools, "get_raw_composio_tool_by_slug", return_value=github_tool
109
+ ):
110
+ # Mock the client's execute method
111
+ mock_execute_response = Mock()
112
+ mock_execute_response.model_dump.return_value = {
113
+ "data": {"result": "success"},
114
+ "error": None,
115
+ "successful": True,
116
+ }
117
+ mock_client.tools.execute.return_value = mock_execute_response
118
+
119
+ # Execute the tool with explicit version
120
+ tools._execute_tool(
121
+ slug="GITHUB_GET_REPOS",
122
+ arguments={"owner": "test", "repo": "test"},
123
+ version="v3.0.0", # Explicit version should take precedence
124
+ toolkit_versions=toolkit_versions,
125
+ )
126
+
127
+ # Verify that the client was called with the explicit version
128
+ mock_client.tools.execute.assert_called_once()
129
+ call_args = mock_client.tools.execute.call_args
130
+
131
+ # Should have called with explicit version, not resolved from toolkit
132
+ assert call_args.kwargs["version"] == "v3.0.0"
133
+
134
+ def test_tool_execution_unknown_toolkit_fallback(self):
135
+ """Test that unknown toolkit falls back to 'latest'."""
136
+ # Mock client and provider
137
+ mock_client = Mock()
138
+ mock_provider = Mock()
139
+ mock_provider.name = "test_provider"
140
+
141
+ # Create toolkit versions configuration that doesn't include the tool's toolkit
142
+ toolkit_versions = {
143
+ "slack": "v1.5.0" # No github version specified
144
+ }
145
+
146
+ # Create Tools instance
147
+ tools = Tools(
148
+ client=mock_client,
149
+ provider=mock_provider,
150
+ toolkit_versions=toolkit_versions,
151
+ )
152
+
153
+ # Create a mock GitHub tool (not in toolkit_versions)
154
+ github_tool = self.create_mock_tool("GITHUB_GET_REPOS", "github")
155
+
156
+ # Mock the get_raw_composio_tool_by_slug method
157
+ with patch.object(
158
+ tools, "get_raw_composio_tool_by_slug", return_value=github_tool
159
+ ):
160
+ # Mock the client's execute method
161
+ mock_execute_response = Mock()
162
+ mock_execute_response.model_dump.return_value = {
163
+ "data": {"result": "success"},
164
+ "error": None,
165
+ "successful": True,
166
+ }
167
+ mock_client.tools.execute.return_value = mock_execute_response
168
+
169
+ # Execute the tool
170
+ tools._execute_tool(
171
+ slug="GITHUB_GET_REPOS",
172
+ arguments={"owner": "test", "repo": "test"},
173
+ toolkit_versions=toolkit_versions,
174
+ )
175
+
176
+ # Verify that the client was called with "latest" (fallback)
177
+ mock_client.tools.execute.assert_called_once()
178
+ call_args = mock_client.tools.execute.call_args
179
+
180
+ # Should have called with "latest" since github is not in toolkit_versions
181
+ assert call_args.kwargs["version"] == "latest"
182
+
183
+ def test_tool_execution_with_global_version_string(self):
184
+ """Test that global version string is used for all toolkits."""
185
+ # Mock client and provider
186
+ mock_client = Mock()
187
+ mock_provider = Mock()
188
+ mock_provider.name = "test_provider"
189
+
190
+ # Create global toolkit version (string)
191
+ toolkit_versions = "v3.0.0"
192
+
193
+ # Create Tools instance
194
+ tools = Tools(
195
+ client=mock_client,
196
+ provider=mock_provider,
197
+ toolkit_versions=toolkit_versions,
198
+ )
199
+
200
+ # Create a mock GitHub tool
201
+ github_tool = self.create_mock_tool("GITHUB_GET_REPOS", "github")
202
+
203
+ # Mock the get_raw_composio_tool_by_slug method
204
+ with patch.object(
205
+ tools, "get_raw_composio_tool_by_slug", return_value=github_tool
206
+ ):
207
+ # Mock the client's execute method
208
+ mock_execute_response = Mock()
209
+ mock_execute_response.model_dump.return_value = {
210
+ "data": {"result": "success"},
211
+ "error": None,
212
+ "successful": True,
213
+ }
214
+ mock_client.tools.execute.return_value = mock_execute_response
215
+
216
+ # Execute the tool
217
+ tools._execute_tool(
218
+ slug="GITHUB_GET_REPOS",
219
+ arguments={"owner": "test", "repo": "test"},
220
+ toolkit_versions=toolkit_versions,
221
+ )
222
+
223
+ # Verify that the client was called with the global version
224
+ mock_client.tools.execute.assert_called_once()
225
+ call_args = mock_client.tools.execute.call_args
226
+
227
+ # Should have called with the global version string
228
+ assert call_args.kwargs["version"] == "v3.0.0"
229
+
230
+ def test_tool_execution_matches_typescript_behavior(self):
231
+ """Test that Python execution matches TypeScript behavior exactly."""
232
+ # This test verifies the same logic as TypeScript:
233
+ # version: body.version ?? getToolkitVersion(tool.toolkit?.slug ?? 'unknown', this.toolkitVersions)
234
+
235
+ # Mock client and provider
236
+ mock_client = Mock()
237
+ mock_provider = Mock()
238
+ mock_provider.name = "test_provider"
239
+
240
+ # Create toolkit versions like TypeScript would have
241
+ toolkit_versions = {
242
+ "github": "20250906_01",
243
+ "slack": "latest",
244
+ "notion": "20250901_05",
245
+ }
246
+
247
+ # Create Tools instance
248
+ tools = Tools(
249
+ client=mock_client,
250
+ provider=mock_provider,
251
+ toolkit_versions=toolkit_versions,
252
+ )
253
+
254
+ # Test cases matching TypeScript behavior
255
+ test_cases = [
256
+ ("GITHUB_GET_REPOS", "github", "20250906_01"),
257
+ ("SLACK_SEND_MESSAGE", "slack", "latest"),
258
+ ("NOTION_CREATE_PAGE", "notion", "20250901_05"),
259
+ ("CUSTOM_TOOL", "unknown_toolkit", "latest"), # Unknown toolkit fallback
260
+ ]
261
+
262
+ for tool_slug, toolkit_slug, expected_version in test_cases:
263
+ # Create mock tool
264
+ mock_tool = self.create_mock_tool(tool_slug, toolkit_slug)
265
+
266
+ # Mock the get_raw_composio_tool_by_slug method
267
+ with patch.object(
268
+ tools, "get_raw_composio_tool_by_slug", return_value=mock_tool
269
+ ):
270
+ # Mock the client's execute method
271
+ mock_execute_response = Mock()
272
+ mock_execute_response.model_dump.return_value = {
273
+ "data": {"result": "success"},
274
+ "error": None,
275
+ "successful": True,
276
+ }
277
+ mock_client.tools.execute.return_value = mock_execute_response
278
+
279
+ # Execute the tool
280
+ tools._execute_tool(
281
+ slug=tool_slug,
282
+ arguments={"test": "data"},
283
+ toolkit_versions=toolkit_versions,
284
+ )
285
+
286
+ # Verify the version matches expected
287
+ call_args = mock_client.tools.execute.call_args
288
+ assert call_args.kwargs["version"] == expected_version, (
289
+ f"Tool {tool_slug} with toolkit {toolkit_slug} should use version {expected_version}"
290
+ )
291
+
292
+ # Reset mock for next iteration
293
+ mock_client.tools.execute.reset_mock()
python/tests/test_toolkit_version.py
new
+174
@@ -0,0 +1,174 @@
1
+"""Test toolkit version utilities."""
2
+
3
+import pytest
4
+
5
+from composio.core.types import ToolkitVersionParam
6
+from composio.utils.toolkit_version import get_toolkit_version, get_toolkit_versions
7
+
8
+
9
+class TestToolkitVersion:
10
+ """Test cases for toolkit version utilities."""
11
+
12
+ def test_get_toolkit_version_with_string(self):
13
+ """Test get_toolkit_version with string parameter."""
14
+ result = get_toolkit_version("github", "v1.0.0")
15
+ assert result == "v1.0.0"
16
+
17
+ def test_get_toolkit_version_with_dict(self):
18
+ """Test get_toolkit_version with dict parameter."""
19
+ versions = {"github": "v1.0.0", "slack": "v2.0.0"}
20
+ result = get_toolkit_version("github", versions)
21
+ assert result == "v1.0.0"
22
+
23
+ def test_get_toolkit_version_with_dict_missing_key(self):
24
+ """Test get_toolkit_version with dict parameter missing key."""
25
+ versions = {"slack": "v2.0.0"}
26
+ result = get_toolkit_version("github", versions)
27
+ assert result == "latest"
28
+
29
+ def test_get_toolkit_version_with_none(self):
30
+ """Test get_toolkit_version with None parameter."""
31
+ result = get_toolkit_version("github", None)
32
+ assert result == "latest"
33
+
34
+ def test_get_toolkit_version_with_env_var(self):
35
+ """Test get_toolkit_version with environment variable."""
36
+ with pytest.MonkeyPatch().context():
37
+ # The function doesn't directly use COMPOSIO_TOOLKIT_VERSION env var
38
+ # It only looks at the toolkit_versions parameter
39
+ result = get_toolkit_version("github", None)
40
+ assert result == "latest"
41
+
42
+ def test_get_toolkit_versions_with_string(self):
43
+ """Test get_toolkit_versions with string parameter."""
44
+ result = get_toolkit_versions("v1.0.0")
45
+ assert result == "v1.0.0"
46
+
47
+ def test_get_toolkit_versions_with_dict(self):
48
+ """Test get_toolkit_versions with dict parameter."""
49
+ versions = {"github": "v1.0.0", "slack": "v2.0.0"}
50
+ result = get_toolkit_versions(versions)
51
+ assert result == versions
52
+
53
+ def test_get_toolkit_versions_with_none(self):
54
+ """Test get_toolkit_versions with None parameter."""
55
+ result = get_toolkit_versions(None)
56
+ assert result == "latest"
57
+
58
+ def test_get_toolkit_versions_with_env_toolkit_specific(self):
59
+ """Test get_toolkit_versions with toolkit-specific environment variables."""
60
+ with pytest.MonkeyPatch().context() as m:
61
+ m.setenv("COMPOSIO_TOOLKIT_VERSION_GITHUB", "v2.0.0")
62
+ m.setenv("COMPOSIO_TOOLKIT_VERSION_SLACK", "v1.5.0")
63
+ result = get_toolkit_versions(None)
64
+ expected = {"github": "v2.0.0", "slack": "v1.5.0"}
65
+ assert result == expected
66
+
67
+ def test_get_toolkit_versions_env_and_user_override(self):
68
+ """Test that user-provided versions override environment variables."""
69
+ with pytest.MonkeyPatch().context() as m:
70
+ # Set environment variables
71
+ m.setenv("COMPOSIO_TOOLKIT_VERSION_GITHUB", "v1.0.0")
72
+ m.setenv("COMPOSIO_TOOLKIT_VERSION_SLACK", "v2.0.0")
73
+
74
+ # User overrides should take precedence
75
+ user_versions = {"github": "v3.0.0", "jira": "v4.0.0"}
76
+ result = get_toolkit_versions(user_versions)
77
+
78
+ expected = {
79
+ "github": "v3.0.0", # User override
80
+ "slack": "v2.0.0", # From env
81
+ "jira": "v4.0.0", # User provided
82
+ }
83
+ assert result == expected
84
+
85
+ def test_get_toolkit_version_with_env_specific_toolkit(self):
86
+ """Test get_toolkit_version works with environment-configured versions."""
87
+ with pytest.MonkeyPatch().context() as m:
88
+ m.setenv("COMPOSIO_TOOLKIT_VERSION_GITHUB", "v2.5.0")
89
+ m.setenv("COMPOSIO_TOOLKIT_VERSION_SLACK", "v1.8.0")
90
+
91
+ # Get versions from environment
92
+ env_versions = get_toolkit_versions(None)
93
+
94
+ # Test specific toolkit version retrieval
95
+ github_version = get_toolkit_version("github", env_versions)
96
+ slack_version = get_toolkit_version("slack", env_versions)
97
+ unknown_version = get_toolkit_version("unknown", env_versions)
98
+
99
+ assert github_version == "v2.5.0"
100
+ assert slack_version == "v1.8.0"
101
+ assert unknown_version == "latest"
102
+
103
+ def test_mixed_case_env_vars_normalized(self):
104
+ """Test that mixed case environment variable names are normalized."""
105
+ with pytest.MonkeyPatch().context() as m:
106
+ # Environment variables are typically uppercase
107
+ m.setenv("COMPOSIO_TOOLKIT_VERSION_GITHUB", "v1.0.0")
108
+ m.setenv("COMPOSIO_TOOLKIT_VERSION_OPENAI", "v2.0.0")
109
+
110
+ result = get_toolkit_versions(None)
111
+
112
+ # Should be normalized to lowercase
113
+ assert "github" in result
114
+ assert "openai" in result
115
+ assert result["github"] == "v1.0.0"
116
+ assert result["openai"] == "v2.0.0"
117
+
118
+ def test_user_dict_case_normalization(self):
119
+ """Test that user-provided dictionary keys are normalized to lowercase."""
120
+ user_versions = {"GitHub": "v1.0.0", "SLACK": "v2.0.0", "OpenAI": "v3.0.0"}
121
+
122
+ result = get_toolkit_versions(user_versions)
123
+
124
+ expected = {"github": "v1.0.0", "slack": "v2.0.0", "openai": "v3.0.0"}
125
+ assert result == expected
126
+
127
+ def test_priority_order_matches_typescript(self):
128
+ """Test that priority order matches TypeScript implementation.
129
+
130
+ Priority order should be:
131
+ 1. String global version (overrides everything)
132
+ 2. User-provided dict overrides env vars
133
+ 3. Environment variables
134
+ 4. Fallback to 'latest'
135
+ """
136
+ with pytest.MonkeyPatch().context() as m:
137
+ # Test 1: String global version overrides everything
138
+ m.setenv("COMPOSIO_TOOLKIT_VERSION_GITHUB", "env_version")
139
+ result = get_toolkit_versions("global_version")
140
+ assert result == "global_version"
141
+
142
+ # Test 2: User dict overrides env vars
143
+ m.setenv("COMPOSIO_TOOLKIT_VERSION_GITHUB", "env_version")
144
+ m.setenv("COMPOSIO_TOOLKIT_VERSION_SLACK", "env_slack")
145
+ user_dict = {"github": "user_override"}
146
+ result = get_toolkit_versions(user_dict)
147
+ expected = {
148
+ "github": "user_override", # User override
149
+ "slack": "env_slack", # From env
150
+ }
151
+ assert result == expected
152
+
153
+ # Test 3: Environment variables when no user input
154
+ result = get_toolkit_versions(None)
155
+ expected = {"github": "env_version", "slack": "env_slack"}
156
+ assert result == expected
157
+
158
+ def test_empty_user_dict_uses_env_vars(self):
159
+ """Test that empty user dict still uses environment variables."""
160
+ with pytest.MonkeyPatch().context() as m:
161
+ m.setenv("COMPOSIO_TOOLKIT_VERSION_GITHUB", "v1.0.0")
162
+
163
+ # Empty dict should still use env vars
164
+ result = get_toolkit_versions({})
165
+ expected = {"github": "v1.0.0"}
166
+ assert result == expected
167
+
168
+ def test_toolkit_version_param_type_annotation(self):
169
+ """Test ToolkitVersionParam type annotation."""
170
+ import typing
171
+
172
+ # Test that ToolkitVersionParam is a Union type
173
+ assert hasattr(ToolkitVersionParam, "__origin__")
174
+ assert ToolkitVersionParam.__origin__ is typing.Union
uv.lock
+9
-9
@@ -468,7 +468,7 @@ wheels = [
468
469
[[package]]
470
name = "composio"
471
-version = "0.8.11"
471
+version = "0.8.14"
472
source = { virtual = "python" }
473
dependencies = [
474
{ name = "composio-client" },
@@ -515,7 +515,7 @@ dev = [
515
516
[[package]]
517
name = "composio-anthropic"
518
-version = "0.8.9"
518
+version = "0.8.12"
519
source = { virtual = "python/providers/anthropic" }
520
dependencies = [
521
{ name = "anthropic" },
@@ -547,7 +547,7 @@ wheels = [
547
548
[[package]]
549
name = "composio-crewai"
550
-version = "0.8.9"
550
+version = "0.8.12"
551
source = { virtual = "python/providers/crewai" }
552
dependencies = [
553
{ name = "composio" },
@@ -562,7 +562,7 @@ requires-dist = [
562
563
[[package]]
564
name = "composio-gemini"
565
-version = "0.8.9"
565
+version = "0.8.12"
566
source = { virtual = "python/providers/gemini" }
567
dependencies = [
568
{ name = "composio" },
@@ -577,7 +577,7 @@ requires-dist = [
577
578
[[package]]
579
name = "composio-google"
580
-version = "0.8.9"
580
+version = "0.8.12"
581
source = { virtual = "python/providers/google" }
582
dependencies = [
583
{ name = "composio" },
@@ -592,7 +592,7 @@ requires-dist = [
592
593
[[package]]
594
name = "composio-google-adk"
595
-version = "0.8.9"
595
+version = "0.8.12"
596
source = { virtual = "python/providers/google_adk" }
597
dependencies = [
598
{ name = "composio" },
@@ -607,7 +607,7 @@ requires-dist = [
607
608
[[package]]
609
name = "composio-langchain"
610
-version = "0.8.9"
610
+version = "0.8.12"
611
source = { virtual = "python/providers/langchain" }
612
dependencies = [
613
{ name = "composio" },
@@ -622,7 +622,7 @@ requires-dist = [
622
623
[[package]]
624
name = "composio-openai"
625
-version = "0.8.9"
625
+version = "0.8.12"
626
source = { virtual = "python/providers/openai" }
627
dependencies = [
628
{ name = "composio" },
@@ -637,7 +637,7 @@ requires-dist = [
637
638
[[package]]
639
name = "composio-openai-agents"
640
-version = "0.8.9"
640
+version = "0.8.12"
641
source = { virtual = "python/providers/openai_agents" }
642
dependencies = [
643
{ name = "composio" },