Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
misc: move auth fields helpers to `toolkits` names
angrybayblade committed
Jun 18, 2025 at 17:48 UTC
edfadf11423fdc125394f2fe01d0d62670356858
6 files changed
+102
-79
python/composio/client/types.py
+29
@@ -33,6 +33,34 @@ Tool: t.TypeAlias = tool_list_response.Item
33
ToolkitMinimal: t.TypeAlias = tool_list_response.ItemToolkit
34
AuthConfig: t.TypeAlias = connected_account_create_params.AuthConfig
35
36
+Oauth1L: t.TypeAlias = t.Literal["OAUTH1"]
37
+Oauth2L: t.TypeAlias = t.Literal["OAUTH2"]
38
+ApiKeyL: t.TypeAlias = t.Literal["API_KEY"]
39
+BasicL: t.TypeAlias = t.Literal["BASIC"]
40
+NoAuthL: t.TypeAlias = t.Literal["NO_AUTH"]
41
+SnowflakeL: t.TypeAlias = t.Literal["SNOWFLAKE"]
42
+CalcomAuthL: t.TypeAlias = t.Literal["CALCOM_AUTH"]
43
+BearerTokenL: t.TypeAlias = t.Literal["BEARER_TOKEN"]
44
+BillcomAuthL: t.TypeAlias = t.Literal["BILLCOM_AUTH"]
45
+ComposioLinkL: t.TypeAlias = t.Literal["COMPOSIO_LINK"]
46
+BasicWithJwtL: t.TypeAlias = t.Literal["BASIC_WITH_JWT"]
47
+GoogleServiceAccountL: t.TypeAlias = t.Literal["GOOGLE_SERVICE_ACCOUNT"]
48
+
49
+AuthSchemeL: t.TypeAlias = t.Literal[
50
+ Oauth1L,
51
+ Oauth2L,
52
+ ApiKeyL,
53
+ BasicL,
54
+ NoAuthL,
55
+ SnowflakeL,
56
+ CalcomAuthL,
57
+ BearerTokenL,
58
+ BillcomAuthL,
59
+ ComposioLinkL,
60
+ BasicWithJwtL,
61
+ GoogleServiceAccountL,
62
+]
63
+
64
__all__ = (
65
"auth_config_create_params",
66
"auth_config_create_response",
@@ -59,4 +87,5 @@ __all__ = (
87
"ToolkitMinimal",
88
"AuthConfig",
89
"NotGiven",
90
+ "AuthSchemeL",
91
)
python/composio/core/models/auth_configs.py
-24
@@ -4,7 +4,6 @@ import typing as t
4
5
import typing_extensions as te
6
7
-from composio import exceptions
7
from composio.client.types import (
8
auth_config_create_params,
9
auth_config_create_response,
@@ -12,13 +11,9 @@ from composio.client.types import (
11
auth_config_list_response,
12
auth_config_retrieve_response,
13
auth_config_update_params,
15
- toolkit_retrieve_response,
14
)
15
from composio.core.models.base import Resource
16
19
-if t.TYPE_CHECKING:
20
- from .connected_accounts import AuthSchemeL
21
-
17
18
class AuthConfigs(Resource):
19
"""
@@ -145,22 +140,3 @@ class AuthConfigs(Resource):
140
:return: The disabled auth config.
141
"""
142
return self.__update_status(nanoid, "DISABLED")
148
-
149
- def get_required_fields(
150
- self,
151
- toolkit: str,
152
- auth_scheme: AuthSchemeL,
153
- ) -> t.List[
154
- toolkit_retrieve_response.AuthConfigDetailFieldsAuthConfigCreationRequired
155
- ]:
156
- """
157
- Get the required property for a given toolkit and auth scheme.
158
- """
159
- info = self._client.toolkits.retrieve(slug=toolkit)
160
- for auth_detail in info.auth_config_details or []:
161
- if auth_detail.mode == auth_scheme:
162
- return auth_detail.fields.auth_config_creation.required
163
-
164
- raise exceptions.InvalidParams(
165
- f"auth config details not found with {toolkit=} and {auth_scheme=}"
166
- )
python/composio/core/models/connected_accounts.py
-48
@@ -10,39 +10,10 @@ from composio.client.types import (
10
connected_account_create_params,
11
connected_account_retrieve_response,
12
connected_account_update_status_response,
13
- toolkit_retrieve_response,
13
)
14
15
from .base import Resource
16
18
-Oauth1L: t.TypeAlias = t.Literal["OAUTH1"]
19
-Oauth2L: t.TypeAlias = t.Literal["OAUTH2"]
20
-ApiKeyL: t.TypeAlias = t.Literal["API_KEY"]
21
-BasicL: t.TypeAlias = t.Literal["BASIC"]
22
-NoAuthL: t.TypeAlias = t.Literal["NO_AUTH"]
23
-SnowflakeL: t.TypeAlias = t.Literal["SNOWFLAKE"]
24
-CalcomAuthL: t.TypeAlias = t.Literal["CALCOM_AUTH"]
25
-BearerTokenL: t.TypeAlias = t.Literal["BEARER_TOKEN"]
26
-BillcomAuthL: t.TypeAlias = t.Literal["BILLCOM_AUTH"]
27
-ComposioLinkL: t.TypeAlias = t.Literal["COMPOSIO_LINK"]
28
-BasicWithJwtL: t.TypeAlias = t.Literal["BASIC_WITH_JWT"]
29
-GoogleServiceAccountL: t.TypeAlias = t.Literal["GOOGLE_SERVICE_ACCOUNT"]
30
-
31
-AuthSchemeL: t.TypeAlias = t.Literal[
32
- Oauth1L,
33
- Oauth2L,
34
- ApiKeyL,
35
- BasicL,
36
- NoAuthL,
37
- SnowflakeL,
38
- CalcomAuthL,
39
- BearerTokenL,
40
- BillcomAuthL,
41
- ComposioLinkL,
42
- BasicWithJwtL,
43
- GoogleServiceAccountL,
44
-]
45
-
17
18
class ConnectionRequest(Resource):
19
"""
@@ -384,24 +355,5 @@ class ConnectedAccounts:
355
client=self._client,
356
)
357
387
- def get_required_fields(
388
- self,
389
- toolkit: str,
390
- auth_scheme: AuthSchemeL,
391
- ) -> t.List[
392
- toolkit_retrieve_response.AuthConfigDetailFieldsConnectedAccountInitiationRequired
393
- ]:
394
- """
395
- Get the required property for a given toolkit and auth scheme.
396
- """
397
- info = self._client.toolkits.retrieve(slug=toolkit)
398
- for auth_detail in info.auth_config_details or []:
399
- if auth_detail.mode == auth_scheme:
400
- return auth_detail.fields.connected_account_initiation.required
401
-
402
- raise exceptions.InvalidParams(
403
- f"auth config details not found with {toolkit=} and {auth_scheme=}"
404
- )
405
-
358
359
auth_scheme = AuthScheme()
python/composio/core/models/toolkits.py
+71
-5
@@ -2,8 +2,10 @@ from __future__ import annotations
2
3
import typing as t
4
5
+from composio import exceptions
6
from composio.client import HttpClient
7
from composio.client.types import (
8
+ AuthSchemeL,
9
toolkit_list_params,
10
toolkit_list_response,
11
toolkit_retrieve_response,
@@ -12,6 +14,13 @@ from composio.core.models.connected_accounts import ConnectedAccounts
14
15
from .base import Resource
16
17
+AuthFieldsT: t.TypeAlias = t.List[
18
+ toolkit_retrieve_response.AuthConfigDetailFieldsConnectedAccountInitiationRequired
19
+ | toolkit_retrieve_response.AuthConfigDetailFieldsConnectedAccountInitiationOptional
20
+ | toolkit_retrieve_response.AuthConfigDetailFieldsAuthConfigCreationRequired
21
+ | toolkit_retrieve_response.AuthConfigDetailFieldsAuthConfigCreationOptional
22
+]
23
+
24
25
class Toolkits(Resource):
26
"""
@@ -32,17 +41,14 @@ class Toolkits(Resource):
41
"""Get all toolkits."""
42
43
@t.overload
35
- def get(
36
- self,
37
- slug: t.Optional[str] = None,
38
- ) -> toolkit_retrieve_response.ToolkitRetrieveResponse:
44
+ def get(self, slug: str) -> toolkit_retrieve_response.ToolkitRetrieveResponse:
45
"""Get a toolkit by slug."""
46
47
@t.overload
48
def get(
49
self,
50
*,
45
- query: t.Optional[toolkit_list_params.ToolkitListParams] = None,
51
+ query: toolkit_list_params.ToolkitListParams,
52
) -> list[toolkit_list_response.Item]:
53
"""Get a list of toolkits by query."""
54
@@ -98,3 +104,63 @@ class Toolkits(Resource):
104
toolkit=toolkit,
105
),
106
)
107
+
108
+ def get_connected_account_initiation_fields(
109
+ self,
110
+ toolkit: str,
111
+ auth_scheme: AuthSchemeL,
112
+ required_only: bool = False,
113
+ ) -> AuthFieldsT:
114
+ """
115
+ Get the required property for a given toolkit and auth scheme.
116
+ """
117
+ details = self._client.toolkits.retrieve(slug=toolkit).auth_config_details or []
118
+ for auth_detail in details:
119
+ if auth_detail.mode != auth_scheme:
120
+ continue
121
+
122
+ if required_only:
123
+ return t.cast(
124
+ AuthFieldsT,
125
+ auth_detail.fields.connected_account_initiation.required,
126
+ )
127
+
128
+ return t.cast(
129
+ AuthFieldsT,
130
+ auth_detail.fields.connected_account_initiation.required
131
+ + auth_detail.fields.connected_account_initiation.optional,
132
+ )
133
+
134
+ raise exceptions.InvalidParams(
135
+ f"auth config details not found with {toolkit=} and {auth_scheme=}"
136
+ )
137
+
138
+ def get_auth_config_creation_fields(
139
+ self,
140
+ toolkit: str,
141
+ auth_scheme: AuthSchemeL,
142
+ required_only: bool = False,
143
+ ) -> AuthFieldsT:
144
+ """
145
+ Get the required property for a given toolkit and auth scheme.
146
+ """
147
+ info = self._client.toolkits.retrieve(slug=toolkit)
148
+ for auth_detail in info.auth_config_details or []:
149
+ if auth_detail.mode != auth_scheme:
150
+ continue
151
+
152
+ if required_only:
153
+ return t.cast(
154
+ AuthFieldsT,
155
+ auth_detail.fields.auth_config_creation.required,
156
+ )
157
+
158
+ return t.cast(
159
+ AuthFieldsT,
160
+ auth_detail.fields.auth_config_creation.required
161
+ + auth_detail.fields.auth_config_creation.optional,
162
+ )
163
+
164
+ raise exceptions.InvalidParams(
165
+ f"auth config details not found with {toolkit=} and {auth_scheme=}"
166
+ )
python/examples/auth_configs.py
+1
-1
@@ -32,7 +32,7 @@ auth_config = composio.auth_configs.create(
32
print(auth_config)
33
34
# When creating an auth config, you can check for required fields
35
-required_fields = composio.auth_configs.get_required_fields(
35
+required_fields = composio.toolkits.get_auth_config_creation_fields(
36
toolkit="NOTION",
37
auth_scheme="OAUTH2",
38
)
python/examples/connected_accounts.py
+1
-1
@@ -31,7 +31,7 @@ connection_request = composio.connected_accounts.initiate(
31
print(connection_request)
32
33
# When creating a connected account, you can check for required fields
34
-required_fields = composio.connected_accounts.get_required_fields(
34
+required_fields = composio.toolkits.get_connected_account_initiation_fields(
35
toolkit="NOTION",
36
auth_scheme="API_KEY",
37
)