tako-sdk 0.1.4__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.
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.4
2
+ Name: tako-sdk
3
+ Version: 0.1.4
4
+ Summary: A Python SDK for interacting with the Tako API
5
+ Author: Tako
6
+ Author-email: support@trytako.com
7
+ License: MIT
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: pydantic==2.8.2
11
+ Requires-Dist: pytest==7.4.3
12
+ Requires-Dist: requests==2.32.3
13
+ Dynamic: author
14
+ Dynamic: author-email
15
+ Dynamic: description
16
+ Dynamic: description-content-type
17
+ Dynamic: license
18
+ Dynamic: requires-dist
19
+ Dynamic: requires-python
20
+ Dynamic: summary
21
+
22
+ # Tako Python SDK
23
+
24
+ The Tako Python SDK is a Python library that makes it easy for applications to use the Tako Knowledge Search API
25
+
26
+ ## Requirements
27
+
28
+ The Tako Python SDK supports Python 3.9+
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ pip install tako-sdk
34
+ ```
35
+
36
+ ## Testing
37
+ ```bash
38
+ export TAKO_API_KEY=<your-tako-server-api-key>
39
+ export TAKO_SERVER_URL=<tako-server-url>
40
+ pytest tests/integration/ -v
41
+ ```
42
+
43
+ ## Contributions
44
+
45
+ This repo is currently maintained by Tako developers. As we evolve this repo, contributors outside of
46
+ Tako will be welcome and developer guides added.
47
+
48
+ ## Support
49
+
50
+ For support, please [create an issue](https://github.com/[organization]/tako-sdk/issues) in our GitHub repository.
@@ -0,0 +1,29 @@
1
+ # Tako Python SDK
2
+
3
+ The Tako Python SDK is a Python library that makes it easy for applications to use the Tako Knowledge Search API
4
+
5
+ ## Requirements
6
+
7
+ The Tako Python SDK supports Python 3.9+
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pip install tako-sdk
13
+ ```
14
+
15
+ ## Testing
16
+ ```bash
17
+ export TAKO_API_KEY=<your-tako-server-api-key>
18
+ export TAKO_SERVER_URL=<tako-server-url>
19
+ pytest tests/integration/ -v
20
+ ```
21
+
22
+ ## Contributions
23
+
24
+ This repo is currently maintained by Tako developers. As we evolve this repo, contributors outside of
25
+ Tako will be welcome and developer guides added.
26
+
27
+ ## Support
28
+
29
+ For support, please [create an issue](https://github.com/[organization]/tako-sdk/issues) in our GitHub repository.
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,24 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ # Read README.md
4
+ with open("README.md", "r", encoding="utf-8") as fh:
5
+ long_description = fh.read()
6
+
7
+ setup(
8
+ name="tako-sdk",
9
+ version="0.1.4",
10
+ author="Tako",
11
+ author_email="support@trytako.com",
12
+ description="A Python SDK for interacting with the Tako API",
13
+ long_description=long_description,
14
+ long_description_content_type="text/markdown",
15
+ package_dir={"": "src"},
16
+ packages=find_packages(where="src"),
17
+ python_requires=">=3.9",
18
+ install_requires=[
19
+ "pydantic==2.8.2",
20
+ "pytest==7.4.3",
21
+ "requests==2.32.3",
22
+ ],
23
+ license="MIT",
24
+ )
File without changes
@@ -0,0 +1,52 @@
1
+ from typing import List, Optional
2
+ import requests
3
+
4
+ from tako.types.common.errors import BaseAPIError
5
+ from tako.types.common.exceptions import raise_exception_from_error
6
+ from tako.types.knowledge_search.types import KnowledgeSearchResults, KnowledgeSearchSourceIndex
7
+
8
+ DEFAULT_SERVER_URL = "https://trytako.com/"
9
+ DEFAULT_API_VERSION = "v1"
10
+
11
+ class TakoClient:
12
+ def __init__(self, api_key: str, server_url: Optional[str] = None, api_version: Optional[str] = None):
13
+ assert api_key is not None, "API key is required"
14
+ self.api_key = api_key
15
+ self.server_url = server_url or DEFAULT_SERVER_URL
16
+ self.api_version = api_version or DEFAULT_API_VERSION
17
+
18
+ def knowledge_search(self, text: str, source_indexes: Optional[List[KnowledgeSearchSourceIndex]] = None) -> KnowledgeSearchResults:
19
+ """
20
+ Search for knowledge cards based on a text query.
21
+
22
+ Args:
23
+ text: The text to search for.
24
+ source_indexes: The source indexes to search for.
25
+
26
+ Returns:
27
+ A list of knowledge search results.
28
+
29
+ Raises:
30
+ APIException: If the API returns an error.
31
+ """
32
+ url = f"{self.server_url}/api/{self.api_version}/knowledge_search"
33
+ payload = {
34
+ "inputs": {
35
+ "text": text,
36
+ },
37
+ }
38
+ if source_indexes:
39
+ payload["source_indexes"] = source_indexes
40
+
41
+ response = requests.post(url, json=payload, headers={"Authorization": f"Bearer {self.api_key}"})
42
+ if response.status_code != 200:
43
+ raise_exception_from_error(BaseAPIError.model_validate(response.json()))
44
+ return KnowledgeSearchResults.model_validate(response.json())
45
+
46
+ def get_image(self, card_id: str) -> bytes:
47
+ url = f"{self.server_url}/api/{self.api_version}/image/{card_id}"
48
+ response = requests.get(url, headers={"Authorization": f"Bearer {self.api_key}"})
49
+ return response.content
50
+
51
+
52
+
File without changes
File without changes
@@ -0,0 +1,46 @@
1
+ from enum import Enum
2
+ from typing import Union
3
+
4
+ from pydantic import BaseModel
5
+
6
+ class APIErrorType(str, Enum):
7
+ BAD_REQUEST = "BAD_REQUEST"
8
+ AUTHENTICATION_ERROR = "AUTHENTICATION_ERROR"
9
+ INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"
10
+ RELEVANT_RESULTS_NOT_FOUND = "RELEVANT_RESULTS_NOT_FOUND"
11
+ RATE_LIMIT_EXCEEDED = "RATE_LIMIT_EXCEEDED"
12
+ PAYMENT_REQUIRED = "PAYMENT_REQUIRED"
13
+
14
+
15
+ class BaseAPIError(BaseModel):
16
+ error_message: str
17
+ error_type: APIErrorType
18
+
19
+
20
+ class AuthenticationError(BaseAPIError):
21
+ error_type: APIErrorType = APIErrorType.AUTHENTICATION_ERROR
22
+
23
+
24
+ class BadRequestError(BaseAPIError):
25
+ error_type: APIErrorType = APIErrorType.BAD_REQUEST
26
+
27
+
28
+ class InternalServerError(BaseAPIError):
29
+ error_type: APIErrorType = APIErrorType.INTERNAL_SERVER_ERROR
30
+
31
+
32
+ class RelevantResultsNotFoundError(BaseAPIError):
33
+ error_type: APIErrorType = APIErrorType.RELEVANT_RESULTS_NOT_FOUND
34
+
35
+
36
+ class RateLimitExceededError(BaseAPIError):
37
+ error_type: APIErrorType = APIErrorType.RATE_LIMIT_EXCEEDED
38
+
39
+
40
+ class PaymentRequiredError(BaseAPIError):
41
+ error_type: APIErrorType = APIErrorType.PAYMENT_REQUIRED
42
+
43
+
44
+ APIError = Union[PaymentRequiredError, RateLimitExceededError, RelevantResultsNotFoundError, InternalServerError, AuthenticationError, BadRequestError]
45
+
46
+
@@ -0,0 +1,78 @@
1
+ from typing import Union
2
+ from tako.types.common.errors import (
3
+ APIErrorType,
4
+ BaseAPIError,
5
+ RateLimitExceededError,
6
+ RelevantResultsNotFoundError,
7
+ PaymentRequiredError,
8
+ AuthenticationError,
9
+ BadRequestError,
10
+ InternalServerError
11
+ )
12
+
13
+ class RelevantResultsNotFoundException(Exception):
14
+ def __init__(self, error: RelevantResultsNotFoundError):
15
+ self.error = error
16
+
17
+ def __str__(self):
18
+ return self.error.error_message
19
+
20
+ class RateLimitExceededException(Exception):
21
+ def __init__(self, error: RateLimitExceededError):
22
+ self.error = error
23
+
24
+ def __str__(self):
25
+ return self.error.error_message
26
+
27
+ class PaymentRequiredException(Exception):
28
+ def __init__(self, error: PaymentRequiredError):
29
+ self.error = error
30
+
31
+ def __str__(self):
32
+ return self.error.error_message
33
+
34
+ class AuthenticationErrorException(Exception):
35
+ def __init__(self, error: AuthenticationError):
36
+ self.error = error
37
+
38
+ def __str__(self):
39
+ return self.error.error_message
40
+
41
+ class BadRequestException(Exception):
42
+ def __init__(self, error: BadRequestError):
43
+ self.error = error
44
+
45
+ def __str__(self):
46
+ return self.error.error_message
47
+
48
+ class InternalServerErrorException(Exception):
49
+ def __init__(self, error: InternalServerError):
50
+ self.error = error
51
+
52
+ def __str__(self):
53
+ return self.error.error_message
54
+
55
+
56
+ APIException = Union[PaymentRequiredException, RateLimitExceededException, RelevantResultsNotFoundException, InternalServerErrorException, AuthenticationErrorException, BadRequestException]
57
+
58
+ def raise_exception_from_error(error: BaseAPIError):
59
+ """
60
+ Raise the appropriate exception based on the error type.
61
+
62
+ Python 3.9 does not support match statements so we need to do it this way.
63
+ """
64
+ if error.error_type == APIErrorType.PAYMENT_REQUIRED:
65
+ raise PaymentRequiredException(error)
66
+ elif error.error_type == APIErrorType.RATE_LIMIT_EXCEEDED:
67
+ raise RateLimitExceededException(error)
68
+ elif error.error_type == APIErrorType.RELEVANT_RESULTS_NOT_FOUND:
69
+ raise RelevantResultsNotFoundException(error)
70
+ elif error.error_type == APIErrorType.INTERNAL_SERVER_ERROR:
71
+ raise InternalServerErrorException(error)
72
+ elif error.error_type == APIErrorType.AUTHENTICATION_ERROR:
73
+ raise AuthenticationErrorException(error)
74
+ elif error.error_type == APIErrorType.BAD_REQUEST:
75
+ raise BadRequestException(error)
76
+ else:
77
+ raise ValueError(f"Unknown error type: {error.error_type}")
78
+
@@ -0,0 +1,143 @@
1
+ from enum import Enum
2
+ from typing import List, Optional
3
+
4
+ from pydantic import BaseModel, Field
5
+
6
+ ####
7
+ # This file contains the types for the knowledge search API
8
+ ####
9
+
10
+
11
+ class KnowledgeSearchSourceIndex(str, Enum):
12
+ TAKO = "tako"
13
+ WEB = "web"
14
+
15
+
16
+ class KnowledgeSearchInputs(BaseModel):
17
+ text: Optional[str] = Field(
18
+ description="Natural language search query string. This can be a direct knowledge query, "
19
+ "or long form text, for which relevant knowledge cards should be returned.",
20
+ examples=[
21
+ "AMD vs. Nvidia headcount since 2013",
22
+ "What is the population of the United States?",
23
+ ],
24
+ )
25
+
26
+
27
+ class KnowledgeCardSource(BaseModel):
28
+ source_name: Optional[str] = Field(
29
+ description="The name of the source",
30
+ examples=["S&P Global", "The World Bank"],
31
+ )
32
+ source_description: Optional[str] = Field(
33
+ description="The description of the source",
34
+ examples=[
35
+ "S&P Global is a US-based financial data and analytics company that provides "
36
+ "products and services to the financial industry.",
37
+ "The World Bank is an international financial institution that provides "
38
+ "financial and technical assistance to developing countries to help them "
39
+ "achieve sustainable economic growth and improve living conditions.",
40
+ ],
41
+ )
42
+ source_index: KnowledgeSearchSourceIndex = Field(
43
+ description="The index of the source",
44
+ examples=[KnowledgeSearchSourceIndex.TAKO, KnowledgeSearchSourceIndex.WEB],
45
+ )
46
+ url: Optional[str] = Field(
47
+ description="The URL of the source",
48
+ examples=["https://xignite.com", "https://stats.com"],
49
+ )
50
+
51
+ def __hash__(self) -> int:
52
+ return hash(
53
+ (self.source_name, self.source_description, self.source_index, self.url)
54
+ )
55
+
56
+
57
+ class KnowledgeCardMethodology(BaseModel):
58
+ methodology_name: Optional[str] = Field(
59
+ description="The name of the methodology",
60
+ examples=["Change me"], # TODO
61
+ )
62
+ methodology_description: Optional[str] = Field(
63
+ description="The description of the methodology",
64
+ examples=["Change me"], # TODO
65
+ )
66
+
67
+ def __hash__(self) -> int:
68
+ return hash((self.methodology_name, self.methodology_description))
69
+
70
+
71
+ class KnowledgeCard(BaseModel):
72
+ card_id: Optional[str] = Field(
73
+ description="The unique ID of the knowledge card",
74
+ examples=["08OoYXQeAjCs_8ybek96"],
75
+ )
76
+ title: Optional[str] = Field(
77
+ description="The title of the knowledge card",
78
+ examples=["Nvidia, Advanced Micro Devices - Full Time Employees"],
79
+ )
80
+ description: Optional[str] = Field(
81
+ description="The description of the knowledge card",
82
+ examples=[
83
+ "This is a time series bar chart showing 2 series between 12:00AM UTC-04:00 on "
84
+ "04/01/2013 and 08:55PM UTC on 04/30/2025. Nvidia Full Time Employees latest "
85
+ "value was at 12:00AM UTC on 12-31-2024, and had a final value of 36.0K "
86
+ "Employees, or 308.72% growth since 12:00AM UTC on 12-31-2013, with a maximum "
87
+ "value of 36.0K Employees at 12:00AM UTC on 12-31-2024 and a minimum value of "
88
+ "8.81K Employees at 12:00AM UTC on 12-31-2013; Advanced Micro Devices Full Time "
89
+ "Employees latest value was at 12:00AM UTC on 12-31-2024, and had a final value "
90
+ "of 28.0K Employees, or 162.39% growth since 12:00AM UTC on 12-31-2013, with a "
91
+ "maximum value of 28.0K Employees at 12:00AM UTC on 12-31-2024 and a minimum "
92
+ "value of 8.2K Employees at 12:00AM UTC on 12-31-2016. The source of the data "
93
+ "is S&P Global. S&P Global is a US-based financial data and analytics company "
94
+ "that provides products and services to the financial industry.",
95
+ ],
96
+ )
97
+ webpage_url: Optional[str] = Field(
98
+ description="URL of a webpage hosting the interactive knowledge card",
99
+ examples=["https://trytako.com/card/08OoYXQeAjCs_8ybek96/"],
100
+ )
101
+ image_url: Optional[str] = Field(
102
+ description="URL of a static image of the knowledge card",
103
+ examples=["https://trytako.com/api/v1/image/08OoYXQeAjCs_8ybek96/"],
104
+ )
105
+ embed_url: Optional[str] = Field(
106
+ description="URL of an embeddable iframe of the knowledge card",
107
+ examples=["https://trytako.com/embed/08OoYXQeAjCs_8ybek96/"],
108
+ )
109
+ sources: Optional[List[KnowledgeCardSource]] = Field(
110
+ description="The sources of the knowledge card",
111
+ )
112
+ methodologies: Optional[List[KnowledgeCardMethodology]] = Field(
113
+ description="The methodologies of the knowledge card",
114
+ )
115
+ source_indexes: Optional[List[KnowledgeSearchSourceIndex]] = Field(
116
+ description="The source indexes of the knowledge card",
117
+ )
118
+
119
+
120
+ class KnowledgeSearchOutputs(BaseModel):
121
+ knowledge_cards: Optional[List[KnowledgeCard]] = None
122
+
123
+
124
+ class KnowledgeSearchResults(BaseModel):
125
+ outputs: Optional[KnowledgeSearchOutputs] = None
126
+ request_id: Optional[str] = None
127
+
128
+
129
+ class KnowledgeSearchRequest(BaseModel):
130
+ inputs: Optional[KnowledgeSearchInputs] = Field(
131
+ description="The inputs for the knowledge search request"
132
+ )
133
+
134
+ # Priority order of potential source indexes to search
135
+ # Once relevant results are found in a source index, the search will stop
136
+ # and results from remaining source indexes will not be searched
137
+ source_indexes: Optional[List[KnowledgeSearchSourceIndex]] = Field(
138
+ description="The priority order of potential source indexes to search."
139
+ "Once relevant results are found in a source index, the search will stop"
140
+ "and results from remaining source indexes will not be searched."
141
+ "Valid values are: tako, web",
142
+ default=[KnowledgeSearchSourceIndex.TAKO],
143
+ )
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.4
2
+ Name: tako-sdk
3
+ Version: 0.1.4
4
+ Summary: A Python SDK for interacting with the Tako API
5
+ Author: Tako
6
+ Author-email: support@trytako.com
7
+ License: MIT
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: pydantic==2.8.2
11
+ Requires-Dist: pytest==7.4.3
12
+ Requires-Dist: requests==2.32.3
13
+ Dynamic: author
14
+ Dynamic: author-email
15
+ Dynamic: description
16
+ Dynamic: description-content-type
17
+ Dynamic: license
18
+ Dynamic: requires-dist
19
+ Dynamic: requires-python
20
+ Dynamic: summary
21
+
22
+ # Tako Python SDK
23
+
24
+ The Tako Python SDK is a Python library that makes it easy for applications to use the Tako Knowledge Search API
25
+
26
+ ## Requirements
27
+
28
+ The Tako Python SDK supports Python 3.9+
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ pip install tako-sdk
34
+ ```
35
+
36
+ ## Testing
37
+ ```bash
38
+ export TAKO_API_KEY=<your-tako-server-api-key>
39
+ export TAKO_SERVER_URL=<tako-server-url>
40
+ pytest tests/integration/ -v
41
+ ```
42
+
43
+ ## Contributions
44
+
45
+ This repo is currently maintained by Tako developers. As we evolve this repo, contributors outside of
46
+ Tako will be welcome and developer guides added.
47
+
48
+ ## Support
49
+
50
+ For support, please [create an issue](https://github.com/[organization]/tako-sdk/issues) in our GitHub repository.
@@ -0,0 +1,15 @@
1
+ README.md
2
+ setup.py
3
+ src/tako/__init__.py
4
+ src/tako/client.py
5
+ src/tako/types/__init__.py
6
+ src/tako/types/common/__init__.py
7
+ src/tako/types/common/errors.py
8
+ src/tako/types/common/exceptions.py
9
+ src/tako/types/knowledge_search/__init__.py
10
+ src/tako/types/knowledge_search/types.py
11
+ src/tako_sdk.egg-info/PKG-INFO
12
+ src/tako_sdk.egg-info/SOURCES.txt
13
+ src/tako_sdk.egg-info/dependency_links.txt
14
+ src/tako_sdk.egg-info/requires.txt
15
+ src/tako_sdk.egg-info/top_level.txt
@@ -0,0 +1,3 @@
1
+ pydantic==2.8.2
2
+ pytest==7.4.3
3
+ requests==2.32.3