Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
mdx 90 lines 3.95 KB
Raw
1 ---
2 title: "Python SDK Reference"
3 description: "API reference for the Composio Python SDK"
4 ---
5
6 # Python SDK Reference
7
8 Complete API reference for the `composio` Python package.
9
10 ## Installation
11
12 <PackageInstall ecosystem="python" packages="composio" />
13
14 ## Classes
15
16 | Class | Description |
17 |-------|-------------|
18 | [`Composio`](/reference/sdk-reference/python/composio) | Composio SDK for Python. Generic parameters: TTool: The individual tool type re... |
19 | [`Tools`](/reference/sdk-reference/python/tools) | Tools class definition This class is used to manage tools in the Composio SDK. ... |
20 | [`Toolkits`](/reference/sdk-reference/python/toolkits) | Toolkits are a collectiono of tools that can be used to perform various tasks. T... |
21 | [`Triggers`](/reference/sdk-reference/python/triggers) | Triggers (instance) class |
22 | [`ConnectedAccounts`](/reference/sdk-reference/python/connected-accounts) | Manage connected accounts. This class is used to manage connected accounts in t... |
23 | [`AuthConfigs`](/reference/sdk-reference/python/auth-configs) | Manage authentication configurations. |
24 | [`MCP`](/reference/sdk-reference/python/mcp) | MCP (Model Control Protocol) class. Provides enhanced MCP server operations Thi... |
25 | [`Session`](/reference/sdk-reference/python/session) | A Composio session — the object returned by `composio.create(...)` / `composio.u... |
26
27 ## Quick Start
28
29 ```python
30 from composio import Composio
31
32 composio = Composio(api_key="your-api-key")
33
34 # Get tools for a user
35 tools = composio.tools.get("user-123", toolkits=["github"])
36
37 # Execute a tool
38 result = composio.tools.execute(
39 "GITHUB_GET_REPOS",
40 arguments={"owner": "composio"},
41 user_id="user-123"
42 )
43 ```
44
45 ## Decorators
46
47 ### before_execute
48
49 [View source](https://github.com/composiohq/composio/blob/next/python/composio/core/models/_modifiers.py#L288)
50
51 ```python
52 @before_execute(modifier: BeforeExecute | None = ..., tools: List[str] | None = ..., toolkits: List[str] | None = ...)
53 def my_modifier(...):
54 ...
55 ```
56
57 ### after_execute
58
59 Build an execution-result modifier. Your callback receives `(tool, toolkit, response)` and returns a `ToolExecutionResponse` dictionary. Check `response["successful"]`, not the session model's `result_type` attribute. Session adapters retain `log_id` and `result_type` as dictionary keys. Serialize with `json.dumps(response)` if needed; it is not a provider message. Register this on tool execution or `session.tools(modifiers=[...])`. Calling `session.execute` directly does not invoke it.
60
61 [View source](https://github.com/composiohq/composio/blob/next/python/composio/core/models/_modifiers.py#L239)
62
63 ```python
64 @after_execute(modifier: AfterExecute | None = ..., tools: List[str] | None = ..., toolkits: List[str] | None = ...)
65 def my_modifier(...):
66 ...
67 ```
68
69 ### before_file_upload
70
71 Build a `Modifier` for the file-upload hook (same scoping pattern as `before_execute`). Your callable may take **either**: - a single `context` argument (`BeforeFileUploadContext`) — the preferred form, exposes `context["source"]` (`"path"` or `"url"`), or - three positional arguments `(path, tool, toolkit)` — legacy form, kept for back-compat. Return a new path/URL string to substitute, or `False` to abort the upload (raises `FileUploadAbortedError`). Pass the returned `Modifier` in `modifiers=[...]` on `composio.core.models.tools.Tools.execute` or `tools.get`. Multiple such modifiers are composed in list order.
72
73 [View source](https://github.com/composiohq/composio/blob/next/python/composio/core/models/_modifiers.py#L327)
74
75 ```python
76 @before_file_upload(modifier: BeforeFileUploadLike | None = ..., tools: List[str] | None = ..., toolkits: List[str] | None = ...)
77 def my_modifier(...):
78 ...
79 ```
80
81 ### schema_modifier
82
83 [View source](https://github.com/composiohq/composio/blob/next/python/composio/core/models/_modifiers.py#L385)
84
85 ```python
86 @schema_modifier(modifier: SchemaModifier | None = ..., tools: List[str] | None = ..., toolkits: List[str] | None = ...)
87 def my_modifier(...):
88 ...
89 ```
90