tasx 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tasx-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 tiptreesystems
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
tasx-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.3
2
+ Name: tasx
3
+ Version: 0.0.1
4
+ Summary: Official client for The Agent Service eXchange (TASX)
5
+ License: MIT
6
+ Author: Nasim Rahaman
7
+ Author-email: nasim@tiptreesystems.com
8
+ Requires-Python: >=3.10,<4.0
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Dist: fastapi (>=0.110.1,<0.111.0)
16
+ Requires-Dist: httpx (>=0.26.0,<0.27.0)
17
+ Requires-Dist: loguru (>=0.7.2,<0.8.0)
18
+ Requires-Dist: pydantic (>=2.7.0,<2.8.0)
19
+ Requires-Dist: starlette
20
+ Requires-Dist: uvicorn[standard] (>=0.29.0,<0.30.0)
21
+ Project-URL: Documentation, https://docs.tasx.tiptreesystems.com
22
+ Project-URL: Homepage, https://github.com/tiptreesystems/tasx
23
+ Project-URL: Repository, https://github.com/tiptreesystems/tasx
24
+ Description-Content-Type: text/markdown
25
+
26
+ # TASX Client SDK
27
+
28
+ ## Installation
29
+
30
+ ```
31
+ pip install tasx
32
+ ```
33
+
34
+ ## Getting Started
35
+
36
+ Import the TASX library and initialize the client:
37
+
38
+ ```python
39
+ import tasx
40
+
41
+ client = tasx.get_client(
42
+ api_base="tasx.tiptreesystems.com/api/v1",
43
+ api_key="your_api_key_here"
44
+ )
45
+ ```
46
+
47
+ Note: The API base and key can also be set via environment variables.
48
+
49
+ ## Task Management
50
+
51
+ ### Creating a new task
52
+
53
+ ```python
54
+ task = client.create_task(
55
+ title="My New Task",
56
+ description="This is a test task",
57
+ status="pending"
58
+ )
59
+ ```
60
+
61
+ ### Retrieving a task
62
+
63
+ ```python
64
+ task = client.get_task(task_id)
65
+ ```
66
+
67
+ ### Updating a task
68
+
69
+ ```python
70
+ updated_task = client.update_task(
71
+ task_id,
72
+ status="in_progress"
73
+ )
74
+ ```
75
+
76
+ ### Deleting a task
77
+
78
+ ```python
79
+ client.delete_task(task_id)
80
+ ```
81
+
82
+ ## Search Functionality
83
+
84
+ ```python
85
+ import tasx.enums
86
+
87
+ import tasx.interface_models
88
+
89
+ search_results = client.search_tasks(
90
+ query="test",
91
+ limit=10,
92
+ sort_by=tasx.SortBy.CREATED_AT,
93
+ sort_order=tasx.enums.SortOrder.DESC
94
+ )
95
+
96
+ for task in search_results.items:
97
+ print(f"Task: {task.name}, Status: {task.status}")
98
+ ```
99
+
100
+ ## Error Handling
101
+
102
+ ```python
103
+ from tasx.exceptions import TasxAPIError, TaskNotFoundError
104
+
105
+ try:
106
+ task = client.get_task(task_id)
107
+ except TaskNotFoundError:
108
+ print(f"Task {task_id} not found")
109
+ except TasxAPIError as e:
110
+ print(f"API error occurred: {e}")
111
+ ```
112
+
113
+ ## Asynchronous Support
114
+
115
+ TASX also supports asynchronous operations:
116
+
117
+ ```python
118
+ import asyncio
119
+ import tasx
120
+
121
+
122
+ async def main():
123
+ async_client = await tasx.get_async_client(
124
+ api_base="tasx.tiptreesystems.com/api/v1",
125
+ api_key="your_api_key_here"
126
+ )
127
+
128
+ task = await async_client.create_task(
129
+ title="Async Task",
130
+ description="This is an asynchronous task"
131
+ )
132
+
133
+ search_results = await async_client.search_tasks(query="async")
134
+ for task in search_results.items:
135
+ print(f"Found task: {task.name}")
136
+
137
+
138
+ if __name__ == "__main__":
139
+ asyncio.run(main())
140
+ ```
141
+
142
+ For more detailed documentation, please refer to the [TASX API Documentation](https://docs.tasx.tiptreesystems.com).
tasx-0.0.1/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # TASX Client SDK
2
+
3
+ ## Installation
4
+
5
+ ```
6
+ pip install tasx
7
+ ```
8
+
9
+ ## Getting Started
10
+
11
+ Import the TASX library and initialize the client:
12
+
13
+ ```python
14
+ import tasx
15
+
16
+ client = tasx.get_client(
17
+ api_base="tasx.tiptreesystems.com/api/v1",
18
+ api_key="your_api_key_here"
19
+ )
20
+ ```
21
+
22
+ Note: The API base and key can also be set via environment variables.
23
+
24
+ ## Task Management
25
+
26
+ ### Creating a new task
27
+
28
+ ```python
29
+ task = client.create_task(
30
+ title="My New Task",
31
+ description="This is a test task",
32
+ status="pending"
33
+ )
34
+ ```
35
+
36
+ ### Retrieving a task
37
+
38
+ ```python
39
+ task = client.get_task(task_id)
40
+ ```
41
+
42
+ ### Updating a task
43
+
44
+ ```python
45
+ updated_task = client.update_task(
46
+ task_id,
47
+ status="in_progress"
48
+ )
49
+ ```
50
+
51
+ ### Deleting a task
52
+
53
+ ```python
54
+ client.delete_task(task_id)
55
+ ```
56
+
57
+ ## Search Functionality
58
+
59
+ ```python
60
+ import tasx.enums
61
+
62
+ import tasx.interface_models
63
+
64
+ search_results = client.search_tasks(
65
+ query="test",
66
+ limit=10,
67
+ sort_by=tasx.SortBy.CREATED_AT,
68
+ sort_order=tasx.enums.SortOrder.DESC
69
+ )
70
+
71
+ for task in search_results.items:
72
+ print(f"Task: {task.name}, Status: {task.status}")
73
+ ```
74
+
75
+ ## Error Handling
76
+
77
+ ```python
78
+ from tasx.exceptions import TasxAPIError, TaskNotFoundError
79
+
80
+ try:
81
+ task = client.get_task(task_id)
82
+ except TaskNotFoundError:
83
+ print(f"Task {task_id} not found")
84
+ except TasxAPIError as e:
85
+ print(f"API error occurred: {e}")
86
+ ```
87
+
88
+ ## Asynchronous Support
89
+
90
+ TASX also supports asynchronous operations:
91
+
92
+ ```python
93
+ import asyncio
94
+ import tasx
95
+
96
+
97
+ async def main():
98
+ async_client = await tasx.get_async_client(
99
+ api_base="tasx.tiptreesystems.com/api/v1",
100
+ api_key="your_api_key_here"
101
+ )
102
+
103
+ task = await async_client.create_task(
104
+ title="Async Task",
105
+ description="This is an asynchronous task"
106
+ )
107
+
108
+ search_results = await async_client.search_tasks(query="async")
109
+ for task in search_results.items:
110
+ print(f"Found task: {task.name}")
111
+
112
+
113
+ if __name__ == "__main__":
114
+ asyncio.run(main())
115
+ ```
116
+
117
+ For more detailed documentation, please refer to the [TASX API Documentation](https://docs.tasx.tiptreesystems.com).
@@ -0,0 +1,24 @@
1
+ [tool.poetry]
2
+ name = "tasx"
3
+ version = "0.0.1"
4
+ description = "Official client for The Agent Service eXchange (TASX)"
5
+ authors = ["Nasim Rahaman <nasim@tiptreesystems.com>", "Martin Weiss <martin@tiptreesystems.com>"]
6
+ readme = "README.md"
7
+ packages = [{include = "tasx"}]
8
+ license = "MIT"
9
+ homepage = "https://github.com/tiptreesystems/tasx"
10
+ repository = "https://github.com/tiptreesystems/tasx"
11
+ documentation = "https://docs.tasx.tiptreesystems.com"
12
+
13
+ [tool.poetry.dependencies]
14
+ python = "^3.10"
15
+ pydantic = "~2.7.0"
16
+ httpx = "~0.26.0"
17
+ loguru = "~0.7.2"
18
+ fastapi = "~0.110.1"
19
+ starlette = "*"
20
+ uvicorn = { extras = ["standard"], version = "~0.29.0" }
21
+
22
+ [build-system]
23
+ requires = ["poetry-core"]
24
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,4 @@
1
+ from .tasx_client import TasxClient
2
+
3
+ __all__ = ["TasxClient"]
4
+
@@ -0,0 +1,101 @@
1
+ from urllib.parse import urlparse
2
+
3
+ import httpx
4
+ from typing import Optional, Any
5
+
6
+ from pydantic import BaseModel
7
+
8
+ from common.api_utils import APIConnectionError
9
+ from common.auth_utils import (
10
+ imbue_header_with_service_type,
11
+ imbue_header_with_service_key,
12
+ imbue_header_with_access_token,
13
+ )
14
+
15
+
16
+ class ProviderSpecificConfig(BaseModel):
17
+ base_url: str | None = None
18
+ api_key: str | None = None
19
+
20
+
21
+ class BaseTasxClient:
22
+ def __init__(
23
+ self,
24
+ base_url: str,
25
+ api_key: Optional[str] = None,
26
+ service_type: str | None = None,
27
+ service_key: str | None = None,
28
+ provider_configs: dict[str, ProviderSpecificConfig] | None = None,
29
+ handle_ngrok: bool = True,
30
+ ):
31
+ self.base_url = base_url
32
+ self.api_key = api_key
33
+ self.service_type = service_type
34
+ self.service_key = service_key
35
+ self.provider_configs = provider_configs or {}
36
+ self.handle_ngrok = handle_ngrok
37
+
38
+ def get_base_url_for_provider(self, provider_name: str, default: Any = None) -> str:
39
+ config = self.provider_configs.get(provider_name)
40
+ return config.base_url if config else default
41
+
42
+ def get_api_key_for_provider(self, provider_name: str, default: Any = None) -> str:
43
+ config = self.provider_configs.get(provider_name)
44
+ return config.api_key if config else default
45
+
46
+ def configure_provider(
47
+ self,
48
+ provider_name: str,
49
+ base_url: str | None = None,
50
+ api_key: str | None = None,
51
+ ) -> "BaseTasxClient":
52
+ self.provider_configs[provider_name] = ProviderSpecificConfig(
53
+ base_url=base_url, api_key=api_key
54
+ )
55
+ return self
56
+
57
+ async def _make_request(
58
+ self,
59
+ method: str,
60
+ path: str,
61
+ base_url: str | None = None,
62
+ api_key: str | None = None,
63
+ **kwargs,
64
+ ) -> dict:
65
+ # Build the url
66
+ if base_url is None:
67
+ base_url = self.base_url
68
+
69
+ url = f"{base_url}{path}"
70
+
71
+ headers = {}
72
+ # Use provided api_key if available, otherwise fall back to default
73
+ if api_key:
74
+ headers = imbue_header_with_access_token(api_key, headers)
75
+ elif self.api_key:
76
+ headers = imbue_header_with_access_token(self.api_key, headers)
77
+
78
+ if self.service_type:
79
+ headers = imbue_header_with_service_type(self.service_type, headers)
80
+
81
+ if self.service_key:
82
+ headers = imbue_header_with_service_key(self.service_key, headers)
83
+
84
+ if self.handle_ngrok:
85
+ netloc = urlparse(url).netloc
86
+ if "ngrok" in netloc:
87
+ headers["ngrok-skip-browser-warning"] = "true"
88
+
89
+ if "headers" in kwargs:
90
+ headers.update(kwargs.pop("headers"))
91
+
92
+ async with httpx.AsyncClient(timeout=60.0) as client:
93
+ try:
94
+ response = await client.request(method, url, headers=headers, **kwargs)
95
+ except httpx.ConnectError as e:
96
+ raise APIConnectionError(f"Failed to connect to {url}") from e
97
+
98
+ return await self._handle_response(response, path)
99
+
100
+ async def _handle_response(self, response: httpx.Response, path: str) -> dict:
101
+ raise NotImplementedError("Subclasses must implement _handle_response")
@@ -0,0 +1,30 @@
1
+ from enum import Enum
2
+
3
+
4
+ class SortBy(str, Enum):
5
+ CREATED_AT = "created_at"
6
+ UPDATED_AT = "updated_at"
7
+
8
+
9
+ class SortOrder(str, Enum):
10
+ ASC = "asc"
11
+ DESC = "desc"
12
+
13
+
14
+ class TaskRunSortBy(str, Enum):
15
+ CREATED_AT = "created_at"
16
+ UPDATED_AT = "updated_at"
17
+
18
+
19
+ class TaskRunStatus(str, Enum):
20
+ PENDING = "pending"
21
+ RUNNING = "running"
22
+ WAITING_ON_AGENT = "waiting_on_agent"
23
+ WAITING_ON_TASK = "waiting_on_task"
24
+ SUCCESS = "success"
25
+ FAILED = "failed"
26
+
27
+
28
+ class TaskMessageType(str, Enum):
29
+ AGENT_TO_TASK = "agent_to_task"
30
+ TASK_TO_AGENT = "task_to_agent"
@@ -0,0 +1,16 @@
1
+ class TasxRegistryAPIError(Exception):
2
+ """General exception for TASX Registry API errors."""
3
+ pass
4
+
5
+
6
+ class TasxRunnerAPIError(Exception):
7
+ pass
8
+
9
+
10
+ class TaskNotFoundError(TasxRegistryAPIError):
11
+ """Exception raised when a task is not found."""
12
+ pass
13
+
14
+
15
+ class TaskRunNotFoundError(TasxRunnerAPIError):
16
+ pass