kensho-kfinance 2.9.0__py3-none-any.whl → 3.0.1__py3-none-any.whl

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.

Potentially problematic release.


This version of kensho-kfinance might be problematic. Click here for more details.

Files changed (135) hide show
  1. {kensho_kfinance-2.9.0.dist-info → kensho_kfinance-3.0.1.dist-info}/METADATA +1 -1
  2. kensho_kfinance-3.0.1.dist-info/RECORD +111 -0
  3. kfinance/CHANGELOG.md +6 -0
  4. kfinance/__init__.py +1 -0
  5. kfinance/client/README.md +9 -0
  6. kfinance/{batch_request_handling.py → client/batch_request_handling.py} +63 -27
  7. kfinance/{fetch.py → client/fetch.py} +23 -29
  8. kfinance/{kfinance.py → client/kfinance.py} +37 -33
  9. kfinance/{meta_classes.py → client/meta_classes.py} +26 -35
  10. kfinance/{decimal_with_unit.py → client/models/decimal_with_unit.py} +1 -1
  11. kfinance/{tests → client/models/tests}/test_decimal_with_unit.py +1 -1
  12. kfinance/client/permission_models.py +16 -0
  13. kfinance/client/tests/__init__.py +0 -0
  14. kfinance/{tests → client/tests}/test_batch_requests.py +8 -6
  15. kfinance/{tests → client/tests}/test_client.py +25 -19
  16. kfinance/{tests → client/tests}/test_fetch.py +11 -29
  17. kfinance/{tests → client/tests}/test_group_objects.py +1 -1
  18. kfinance/{tests → client/tests}/test_objects.py +33 -29
  19. kfinance/{tests/conftest.py → conftest.py} +14 -2
  20. kfinance/domains/README.md +14 -0
  21. kfinance/domains/__init__.py +0 -0
  22. kfinance/domains/business_relationships/__init__.py +0 -0
  23. kfinance/{models → domains/business_relationships}/business_relationship_models.py +10 -0
  24. kfinance/domains/business_relationships/business_relationship_tools.py +74 -0
  25. kfinance/domains/business_relationships/tests/__init__.py +0 -0
  26. kfinance/domains/business_relationships/tests/test_business_relationship_tools.py +55 -0
  27. kfinance/domains/capitalizations/__init__.py +0 -0
  28. kfinance/{models → domains/capitalizations}/capitalization_models.py +24 -17
  29. kfinance/domains/capitalizations/capitalization_tools.py +89 -0
  30. kfinance/domains/capitalizations/tests/__init__.py +0 -0
  31. kfinance/{tests/test_models → domains/capitalizations/tests}/test_capitalization_models.py +8 -10
  32. kfinance/domains/capitalizations/tests/test_capitalization_tools.py +85 -0
  33. kfinance/domains/companies/__init__.py +0 -0
  34. kfinance/domains/companies/company_identifiers.py +175 -0
  35. kfinance/domains/companies/company_models.py +27 -0
  36. kfinance/domains/companies/company_tools.py +66 -0
  37. kfinance/domains/companies/tests/__init__.py +0 -0
  38. kfinance/domains/companies/tests/test_company_tools.py +26 -0
  39. kfinance/domains/competitors/__init__.py +0 -0
  40. kfinance/{models → domains/competitors}/competitor_models.py +7 -0
  41. kfinance/domains/competitors/competitor_tools.py +62 -0
  42. kfinance/domains/competitors/tests/__init__.py +0 -0
  43. kfinance/domains/competitors/tests/test_competitor_tools.py +45 -0
  44. kfinance/domains/cusip_and_isin/__init__.py +0 -0
  45. kfinance/domains/cusip_and_isin/cusip_and_isin_tools.py +80 -0
  46. kfinance/domains/cusip_and_isin/tests/__init__.py +0 -0
  47. kfinance/domains/cusip_and_isin/tests/test_cusip_and_isin_tools.py +57 -0
  48. kfinance/domains/earnings/__init__.py +0 -0
  49. kfinance/domains/earnings/earning_models.py +41 -0
  50. kfinance/domains/earnings/earning_tools.py +174 -0
  51. kfinance/domains/earnings/tests/__init__.py +0 -0
  52. kfinance/domains/earnings/tests/test_earnings_tools.py +195 -0
  53. kfinance/domains/line_items/__init__.py +0 -0
  54. kfinance/domains/line_items/line_item_tools.py +117 -0
  55. kfinance/domains/line_items/tests/__init__.py +0 -0
  56. kfinance/domains/line_items/tests/test_line_item_tools.py +86 -0
  57. kfinance/domains/mergers_and_acquisitions/__init__.py +0 -0
  58. kfinance/domains/mergers_and_acquisitions/merger_and_acquisition_tools.py +176 -0
  59. kfinance/domains/mergers_and_acquisitions/tests/__init__.py +0 -0
  60. kfinance/domains/mergers_and_acquisitions/tests/test_merger_and_acquisition_tools.py +124 -0
  61. kfinance/domains/prices/__init__.py +0 -0
  62. kfinance/{models → domains/prices}/price_models.py +1 -1
  63. kfinance/domains/prices/price_tools.py +165 -0
  64. kfinance/domains/prices/tests/__init__.py +0 -0
  65. kfinance/{tests/test_models → domains/prices/tests}/test_price_models.py +2 -2
  66. kfinance/domains/prices/tests/test_price_tools.py +141 -0
  67. kfinance/domains/segments/__init__.py +0 -0
  68. kfinance/domains/segments/segment_tools.py +91 -0
  69. kfinance/domains/segments/tests/__init__.py +0 -0
  70. kfinance/domains/segments/tests/test_segment_tools.py +80 -0
  71. kfinance/domains/statements/__init__.py +0 -0
  72. kfinance/domains/statements/statement_tools.py +116 -0
  73. kfinance/domains/statements/tests/__init__.py +0 -0
  74. kfinance/domains/statements/tests/test_statement_tools.py +73 -0
  75. kfinance/integrations/README.md +8 -0
  76. kfinance/integrations/__init__.py +0 -0
  77. kfinance/integrations/mcp/__init__.py +0 -0
  78. kfinance/{mcp.py → integrations/mcp/mcp.py} +2 -2
  79. kfinance/integrations/tests/__init__.py +0 -0
  80. kfinance/{tests → integrations/tests}/test_example_notebook.py +4 -4
  81. kfinance/{tool_calling → integrations/tool_calling}/README.md +2 -2
  82. kfinance/integrations/tool_calling/__init__.py +0 -0
  83. kfinance/integrations/tool_calling/all_tools.py +55 -0
  84. kfinance/{tool_calling → integrations/tool_calling}/prompts.py +3 -2
  85. kfinance/integrations/tool_calling/static_tools/README.md +4 -0
  86. kfinance/integrations/tool_calling/static_tools/__init__.py +0 -0
  87. kfinance/{tool_calling → integrations/tool_calling/static_tools}/get_latest.py +3 -3
  88. kfinance/{tool_calling → integrations/tool_calling/static_tools}/get_n_quarters_ago.py +3 -3
  89. kfinance/integrations/tool_calling/static_tools/tests/__init__.py +0 -0
  90. kfinance/integrations/tool_calling/static_tools/tests/test_get_lastest.py +30 -0
  91. kfinance/integrations/tool_calling/static_tools/tests/test_get_n_quarters_ago.py +24 -0
  92. kfinance/integrations/tool_calling/tests/__init__.py +0 -0
  93. kfinance/integrations/tool_calling/tests/test_tool_calling_models.py +69 -0
  94. kfinance/{tool_calling/shared_models.py → integrations/tool_calling/tool_calling_models.py} +37 -7
  95. kfinance/models/permission_models.py +1 -0
  96. kfinance/version.py +2 -2
  97. kensho_kfinance-2.9.0.dist-info/RECORD +0 -70
  98. kfinance/models/id_models.py +0 -7
  99. kfinance/prompt.py +0 -526
  100. kfinance/pydantic_models.py +0 -33
  101. kfinance/tests/test_tools.py +0 -804
  102. kfinance/tool_calling/__init__.py +0 -53
  103. kfinance/tool_calling/get_advisors_for_company_in_transaction_from_identifier.py +0 -42
  104. kfinance/tool_calling/get_business_relationship_from_identifier.py +0 -30
  105. kfinance/tool_calling/get_capitalization_from_identifier.py +0 -35
  106. kfinance/tool_calling/get_competitors_from_identifier.py +0 -25
  107. kfinance/tool_calling/get_cusip_from_ticker.py +0 -20
  108. kfinance/tool_calling/get_earnings.py +0 -33
  109. kfinance/tool_calling/get_financial_line_item_from_identifier.py +0 -48
  110. kfinance/tool_calling/get_financial_statement_from_identifier.py +0 -44
  111. kfinance/tool_calling/get_history_metadata_from_identifier.py +0 -17
  112. kfinance/tool_calling/get_info_from_identifier.py +0 -16
  113. kfinance/tool_calling/get_isin_from_ticker.py +0 -20
  114. kfinance/tool_calling/get_latest_earnings.py +0 -30
  115. kfinance/tool_calling/get_merger_info_from_transaction_id.py +0 -69
  116. kfinance/tool_calling/get_mergers_from_identifier.py +0 -44
  117. kfinance/tool_calling/get_next_earnings.py +0 -30
  118. kfinance/tool_calling/get_prices_from_identifier.py +0 -46
  119. kfinance/tool_calling/get_segments_from_identifier.py +0 -44
  120. kfinance/tool_calling/get_transcript.py +0 -23
  121. kfinance/tool_calling/resolve_identifier.py +0 -18
  122. {kensho_kfinance-2.9.0.dist-info → kensho_kfinance-3.0.1.dist-info}/WHEEL +0 -0
  123. {kensho_kfinance-2.9.0.dist-info → kensho_kfinance-3.0.1.dist-info}/licenses/AUTHORS.md +0 -0
  124. {kensho_kfinance-2.9.0.dist-info → kensho_kfinance-3.0.1.dist-info}/licenses/LICENSE +0 -0
  125. {kensho_kfinance-2.9.0.dist-info → kensho_kfinance-3.0.1.dist-info}/top_level.txt +0 -0
  126. /kfinance/{models → client}/__init__.py +0 -0
  127. /kfinance/{models → client}/industry_models.py +0 -0
  128. /kfinance/{tests → client/models}/__init__.py +0 -0
  129. /kfinance/{models → client/models}/currency_models.py +0 -0
  130. /kfinance/{models → client/models}/date_and_period_models.py +0 -0
  131. /kfinance/{tests/test_models → client/models/tests}/__init__.py +0 -0
  132. /kfinance/{server_thread.py → client/server_thread.py} +0 -0
  133. /kfinance/{models → domains/line_items}/line_item_models.py +0 -0
  134. /kfinance/{models → domains/segments}/segment_models.py +0 -0
  135. /kfinance/{models → domains/statements}/statement_models.py +0 -0
@@ -1,53 +0,0 @@
1
- from typing import Type
2
-
3
- from kfinance.tool_calling.get_business_relationship_from_identifier import (
4
- GetBusinessRelationshipFromIdentifier,
5
- )
6
- from kfinance.tool_calling.get_capitalization_from_identifier import GetCapitalizationFromIdentifier
7
- from kfinance.tool_calling.get_competitors_from_identifier import GetCompetitorsFromIdentifier
8
- from kfinance.tool_calling.get_cusip_from_ticker import GetCusipFromTicker
9
- from kfinance.tool_calling.get_earnings import GetEarnings
10
- from kfinance.tool_calling.get_financial_line_item_from_identifier import (
11
- GetFinancialLineItemFromIdentifier,
12
- )
13
- from kfinance.tool_calling.get_financial_statement_from_identifier import (
14
- GetFinancialStatementFromIdentifier,
15
- )
16
- from kfinance.tool_calling.get_history_metadata_from_identifier import (
17
- GetHistoryMetadataFromIdentifier,
18
- )
19
- from kfinance.tool_calling.get_info_from_identifier import GetInfoFromIdentifier
20
- from kfinance.tool_calling.get_isin_from_ticker import GetIsinFromTicker
21
- from kfinance.tool_calling.get_latest import GetLatest
22
- from kfinance.tool_calling.get_latest_earnings import GetLatestEarnings
23
- from kfinance.tool_calling.get_n_quarters_ago import GetNQuartersAgo
24
- from kfinance.tool_calling.get_next_earnings import GetNextEarnings
25
- from kfinance.tool_calling.get_prices_from_identifier import GetPricesFromIdentifier
26
- from kfinance.tool_calling.get_segments_from_identifier import (
27
- GetSegmentsFromIdentifier,
28
- )
29
- from kfinance.tool_calling.get_transcript import GetTranscript
30
- from kfinance.tool_calling.resolve_identifier import ResolveIdentifier
31
- from kfinance.tool_calling.shared_models import KfinanceTool
32
-
33
-
34
- ALL_TOOLS: list[Type[KfinanceTool]] = [
35
- GetLatest,
36
- GetNQuartersAgo,
37
- GetIsinFromTicker,
38
- GetCusipFromTicker,
39
- GetInfoFromIdentifier,
40
- GetEarnings,
41
- GetLatestEarnings,
42
- GetNextEarnings,
43
- GetTranscript,
44
- GetHistoryMetadataFromIdentifier,
45
- GetPricesFromIdentifier,
46
- GetCapitalizationFromIdentifier,
47
- GetFinancialStatementFromIdentifier,
48
- GetFinancialLineItemFromIdentifier,
49
- GetBusinessRelationshipFromIdentifier,
50
- ResolveIdentifier,
51
- GetSegmentsFromIdentifier,
52
- GetCompetitorsFromIdentifier,
53
- ]
@@ -1,42 +0,0 @@
1
- from typing import Type
2
-
3
- from pydantic import BaseModel, Field
4
-
5
- from kfinance.kfinance import Company, ParticipantInMerger
6
- from kfinance.models.permission_models import Permission
7
- from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
8
-
9
-
10
- class GetAdvisorsForCompanyInTransactionFromIdentifierArgs(ToolArgsWithIdentifier):
11
- transaction_id: int | None = Field(description="The ID of the merger.", default=None)
12
-
13
-
14
- class GetAdvisorsForCompanyInTransactionFromIdentifier(KfinanceTool):
15
- name: str = "get_advisors_for_company_in_transaction_from_identifier"
16
- description: str = 'Get the companies advising a company in a given transaction. For example, "Who advised S&P Global during their purchase of Kensho?"'
17
- args_schema: Type[BaseModel] = GetAdvisorsForCompanyInTransactionFromIdentifierArgs
18
- accepted_permissions: set[Permission] | None = {Permission.MergersPermission}
19
-
20
- def _run(self, identifier: str, transaction_id: int) -> list:
21
- ticker = self.kfinance_client.ticker(identifier)
22
- participant_in_merger = ParticipantInMerger(
23
- kfinance_api_client=ticker.kfinance_api_client,
24
- transaction_id=transaction_id,
25
- company=Company(
26
- kfinance_api_client=ticker.kfinance_api_client,
27
- company_id=ticker.company.company_id,
28
- ),
29
- )
30
- advisors = participant_in_merger.advisors
31
-
32
- if advisors:
33
- return [
34
- {
35
- "advisor_company_id": advisor.company.company_id,
36
- "advisor_company_name": advisor.company.name,
37
- "advisor_type_name": advisor.advisor_type_name,
38
- }
39
- for advisor in advisors
40
- ]
41
- else:
42
- return []
@@ -1,30 +0,0 @@
1
- from typing import Type
2
-
3
- from pydantic import BaseModel
4
-
5
- from kfinance.kfinance import BusinessRelationships
6
- from kfinance.models.business_relationship_models import BusinessRelationshipType
7
- from kfinance.models.permission_models import Permission
8
- from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
9
-
10
-
11
- class GetBusinessRelationshipFromIdentifierArgs(ToolArgsWithIdentifier):
12
- # no description because the description for enum fields comes from the enum docstring.
13
- business_relationship: BusinessRelationshipType
14
-
15
-
16
- class GetBusinessRelationshipFromIdentifier(KfinanceTool):
17
- name: str = "get_business_relationship_from_identifier"
18
- description: str = 'Get the current and previous company IDs that are relationship_type of a given identifier. For example, "What are the current distributors of SPGI?" or "What are the previous borrowers of JPM?"'
19
- args_schema: Type[BaseModel] = GetBusinessRelationshipFromIdentifierArgs
20
- accepted_permissions: set[Permission] | None = {Permission.RelationshipPermission}
21
-
22
- def _run(self, identifier: str, business_relationship: BusinessRelationshipType) -> dict:
23
- ticker = self.kfinance_client.ticker(identifier)
24
- business_relationship_obj: BusinessRelationships = getattr(
25
- ticker, business_relationship.value
26
- )
27
- return {
28
- "current": [company.company_id for company in business_relationship_obj.current],
29
- "previous": [company.company_id for company in business_relationship_obj.previous],
30
- }
@@ -1,35 +0,0 @@
1
- from datetime import date
2
-
3
- from pydantic import Field
4
-
5
- from kfinance.models.capitalization_models import Capitalization
6
- from kfinance.models.permission_models import Permission
7
- from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
8
-
9
-
10
- class GetCapitalizationFromIdentifierArgs(ToolArgsWithIdentifier):
11
- # no description because the description for enum fields comes from the enum docstring.
12
- capitalization: Capitalization
13
- start_date: date | None = Field(
14
- description="The start date for historical capitalization retrieval", default=None
15
- )
16
- end_date: date | None = Field(
17
- description="The end date for historical capitalization retrieval", default=None
18
- )
19
-
20
-
21
- class GetCapitalizationFromIdentifier(KfinanceTool):
22
- name: str = "get_capitalization_from_identifier"
23
- description: str = "Get the historical market cap, tev (Total Enterprise Value), or shares outstanding of an identifier between inclusive start_date and inclusive end date. When requesting the most recent values, leave start_date and end_date empty."
24
- args_schema = GetCapitalizationFromIdentifierArgs
25
- accepted_permissions: set[Permission] | None = {Permission.PricingPermission}
26
-
27
- def _run(
28
- self,
29
- identifier: str,
30
- capitalization: Capitalization,
31
- start_date: str | None = None,
32
- end_date: str | None = None,
33
- ) -> dict:
34
- ticker = self.kfinance_client.ticker(identifier)
35
- return getattr(ticker, capitalization.value)(start_date=start_date, end_date=end_date)
@@ -1,25 +0,0 @@
1
- from kfinance.models.competitor_models import CompetitorSource
2
- from kfinance.models.permission_models import Permission
3
- from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
4
-
5
-
6
- class GetCompetitorsFromIdentifierArgs(ToolArgsWithIdentifier):
7
- # no description because the description for enum fields comes from the enum docstring.
8
- competitor_source: CompetitorSource
9
-
10
-
11
- class GetCompetitorsFromIdentifier(KfinanceTool):
12
- name: str = "get_competitors_from_identifier"
13
- description: str = "Retrieves a list of company_id and company_name that are competitors for a given company, optionally filtered by the source of the competitor information."
14
- args_schema = GetCompetitorsFromIdentifierArgs
15
- accepted_permissions: set[Permission] | None = {Permission.CompetitorsPermission}
16
-
17
- def _run(
18
- self,
19
- identifier: str,
20
- competitor_source: CompetitorSource,
21
- ) -> dict:
22
- ticker = self.kfinance_client.ticker(identifier)
23
- return self.kfinance_client.kfinance_api_client.fetch_competitors(
24
- company_id=ticker.company_id, competitor_source=competitor_source
25
- )
@@ -1,20 +0,0 @@
1
- from typing import Type
2
-
3
- from pydantic import BaseModel, Field
4
-
5
- from kfinance.models.permission_models import Permission
6
- from kfinance.tool_calling.shared_models import KfinanceTool
7
-
8
-
9
- class GetCusipFromTickerArgs(BaseModel):
10
- ticker_str: str = Field(description="The ticker")
11
-
12
-
13
- class GetCusipFromTicker(KfinanceTool):
14
- name: str = "get_cusip_from_ticker"
15
- description: str = "Get the CUSIP associated with a ticker."
16
- args_schema: Type[BaseModel] = GetCusipFromTickerArgs
17
- accepted_permissions: set[Permission] | None = {Permission.IDPermission}
18
-
19
- def _run(self, ticker_str: str) -> str:
20
- return self.kfinance_client.ticker(ticker_str).cusip
@@ -1,33 +0,0 @@
1
- from typing import Type
2
-
3
- from pydantic import BaseModel
4
-
5
- from kfinance.kfinance import NoEarningsDataError
6
- from kfinance.models.permission_models import Permission
7
- from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
8
-
9
-
10
- class GetEarnings(KfinanceTool):
11
- name: str = "get_earnings"
12
- description: str = "Get all earnings for a given identifier. Returns a list of dictionaries, each with 'name' (str), 'key_dev_id' (int), and 'datetime' (str in ISO 8601 format with UTC timezone) attributes."
13
- args_schema: Type[BaseModel] = ToolArgsWithIdentifier
14
- accepted_permissions: set[Permission] | None = {
15
- Permission.EarningsPermission,
16
- Permission.TranscriptsPermission,
17
- }
18
-
19
- def _run(self, identifier: str) -> list[dict]:
20
- ticker = self.kfinance_client.ticker(identifier)
21
- earnings = ticker.company.earnings()
22
-
23
- if not earnings:
24
- raise NoEarningsDataError(f"Earnings for {identifier} not found")
25
-
26
- return [
27
- {
28
- "name": earnings_item.name,
29
- "key_dev_id": earnings_item.key_dev_id,
30
- "datetime": earnings_item.datetime.isoformat(),
31
- }
32
- for earnings_item in earnings
33
- ]
@@ -1,48 +0,0 @@
1
- from typing import Literal, Type
2
-
3
- from pydantic import BaseModel, Field
4
-
5
- from kfinance.models.date_and_period_models import PeriodType
6
- from kfinance.models.line_item_models import LINE_ITEM_NAMES_AND_ALIASES
7
- from kfinance.models.permission_models import Permission
8
- from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier, ValidQuarter
9
-
10
-
11
- class GetFinancialLineItemFromIdentifierArgs(ToolArgsWithIdentifier):
12
- # Note: mypy will not enforce this literal because of the type: ignore.
13
- # But pydantic still uses the literal to check for allowed values and only includes
14
- # allowed values in generated schemas.
15
- line_item: Literal[tuple(LINE_ITEM_NAMES_AND_ALIASES)] = Field( # type: ignore[valid-type]
16
- description="The type of financial line_item requested"
17
- )
18
- period_type: PeriodType | None = Field(default=None, description="The period type")
19
- start_year: int | None = Field(default=None, description="The starting year for the data range")
20
- end_year: int | None = Field(default=None, description="The ending year for the data range")
21
- start_quarter: ValidQuarter | None = Field(default=None, description="Starting quarter")
22
- end_quarter: ValidQuarter | None = Field(default=None, description="Ending quarter")
23
-
24
-
25
- class GetFinancialLineItemFromIdentifier(KfinanceTool):
26
- name: str = "get_financial_line_item_from_identifier"
27
- description: str = "Get the financial line item associated with an identifier."
28
- args_schema: Type[BaseModel] = GetFinancialLineItemFromIdentifierArgs
29
- accepted_permissions: set[Permission] | None = {Permission.StatementsPermission}
30
-
31
- def _run(
32
- self,
33
- identifier: str,
34
- line_item: str,
35
- period_type: PeriodType | None = None,
36
- start_year: int | None = None,
37
- end_year: int | None = None,
38
- start_quarter: Literal[1, 2, 3, 4] | None = None,
39
- end_quarter: Literal[1, 2, 3, 4] | None = None,
40
- ) -> str:
41
- ticker = self.kfinance_client.ticker(identifier)
42
- return getattr(ticker, line_item)(
43
- period_type=period_type,
44
- start_year=start_year,
45
- end_year=end_year,
46
- start_quarter=start_quarter,
47
- end_quarter=end_quarter,
48
- ).to_markdown()
@@ -1,44 +0,0 @@
1
- from typing import Literal, Type
2
-
3
- from pydantic import BaseModel, Field
4
-
5
- from kfinance.models.date_and_period_models import PeriodType
6
- from kfinance.models.permission_models import Permission
7
- from kfinance.models.statement_models import StatementType
8
- from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier, ValidQuarter
9
-
10
-
11
- class GetFinancialStatementFromIdentifierArgs(ToolArgsWithIdentifier):
12
- # no description because the description for enum fields comes from the enum docstring.
13
- statement: StatementType
14
- period_type: PeriodType | None = Field(default=None, description="The period type")
15
- start_year: int | None = Field(default=None, description="The starting year for the data range")
16
- end_year: int | None = Field(default=None, description="The ending year for the data range")
17
- start_quarter: ValidQuarter | None = Field(default=None, description="Starting quarter")
18
- end_quarter: ValidQuarter | None = Field(default=None, description="Ending quarter")
19
-
20
-
21
- class GetFinancialStatementFromIdentifier(KfinanceTool):
22
- name: str = "get_financial_statement_from_identifier"
23
- description: str = "Get the financial statement associated with an identifier."
24
- args_schema: Type[BaseModel] = GetFinancialStatementFromIdentifierArgs
25
- accepted_permissions: set[Permission] | None = {Permission.StatementsPermission}
26
-
27
- def _run(
28
- self,
29
- identifier: str,
30
- statement: StatementType,
31
- period_type: PeriodType | None = None,
32
- start_year: int | None = None,
33
- end_year: int | None = None,
34
- start_quarter: Literal[1, 2, 3, 4] | None = None,
35
- end_quarter: Literal[1, 2, 3, 4] | None = None,
36
- ) -> str:
37
- ticker = self.kfinance_client.ticker(identifier)
38
- return getattr(ticker, statement.value)(
39
- period_type=period_type,
40
- start_year=start_year,
41
- end_year=end_year,
42
- start_quarter=start_quarter,
43
- end_quarter=end_quarter,
44
- ).to_markdown()
@@ -1,17 +0,0 @@
1
- from typing import Type
2
-
3
- from pydantic import BaseModel
4
-
5
- from kfinance.models.permission_models import Permission
6
- from kfinance.models.price_models import HistoryMetadata
7
- from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
8
-
9
-
10
- class GetHistoryMetadataFromIdentifier(KfinanceTool):
11
- name: str = "get_history_metadata_from_identifier"
12
- description: str = "Get the history metadata associated with an identifier. History metadata includes currency, symbol, exchange name, instrument type, and first trade date."
13
- args_schema: Type[BaseModel] = ToolArgsWithIdentifier
14
- accepted_permissions: set[Permission] | None = None
15
-
16
- def _run(self, identifier: str) -> HistoryMetadata:
17
- return self.kfinance_client.ticker(identifier).history_metadata
@@ -1,16 +0,0 @@
1
- from typing import Type
2
-
3
- from pydantic import BaseModel
4
-
5
- from kfinance.models.permission_models import Permission
6
- from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
7
-
8
-
9
- class GetInfoFromIdentifier(KfinanceTool):
10
- name: str = "get_info_from_identifier"
11
- description: str = "Get the information associated with an identifier. Info includes company name, status, type, simple industry, number of employees (if available), founding date, webpage, HQ address, HQ city, HQ zip code, HQ state, HQ country, and HQ country iso code."
12
- args_schema: Type[BaseModel] = ToolArgsWithIdentifier
13
- accepted_permissions: set[Permission] | None = None
14
-
15
- def _run(self, identifier: str) -> str:
16
- return str(self.kfinance_client.ticker(identifier).info)
@@ -1,20 +0,0 @@
1
- from typing import Type
2
-
3
- from pydantic import BaseModel, Field
4
-
5
- from kfinance.models.permission_models import Permission
6
- from kfinance.tool_calling.shared_models import KfinanceTool
7
-
8
-
9
- class GetIsinFromTickerArgs(BaseModel):
10
- ticker_str: str = Field(description="The ticker")
11
-
12
-
13
- class GetIsinFromTicker(KfinanceTool):
14
- name: str = "get_isin_from_ticker"
15
- description: str = "Get the ISIN associated with a ticker."
16
- args_schema: Type[BaseModel] = GetIsinFromTickerArgs
17
- accepted_permissions: set[Permission] | None = {Permission.IDPermission}
18
-
19
- def _run(self, ticker_str: str) -> str:
20
- return self.kfinance_client.ticker(ticker_str).isin
@@ -1,30 +0,0 @@
1
- from typing import Type
2
-
3
- from pydantic import BaseModel
4
-
5
- from kfinance.kfinance import NoEarningsDataError
6
- from kfinance.models.permission_models import Permission
7
- from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
8
-
9
-
10
- class GetLatestEarnings(KfinanceTool):
11
- name: str = "get_latest_earnings"
12
- description: str = "Get the latest earnings for a given identifier. Returns a dictionary with 'name' (str), 'key_dev_id' (int), and 'datetime' (str in ISO 8601 format with UTC timezone) attributes."
13
- args_schema: Type[BaseModel] = ToolArgsWithIdentifier
14
- accepted_permissions: set[Permission] | None = {
15
- Permission.EarningsPermission,
16
- Permission.TranscriptsPermission,
17
- }
18
-
19
- def _run(self, identifier: str) -> dict:
20
- ticker = self.kfinance_client.ticker(identifier)
21
- latest_earnings = ticker.company.latest_earnings
22
-
23
- if latest_earnings is None:
24
- raise NoEarningsDataError(f"Latest earnings for {identifier} not found")
25
-
26
- return {
27
- "name": latest_earnings.name,
28
- "key_dev_id": latest_earnings.key_dev_id,
29
- "datetime": latest_earnings.datetime.isoformat(),
30
- }
@@ -1,69 +0,0 @@
1
- from typing import Type
2
-
3
- from pydantic import BaseModel, Field
4
-
5
- from kfinance.kfinance import MergerOrAcquisition
6
- from kfinance.models.permission_models import Permission
7
- from kfinance.tool_calling.shared_models import KfinanceTool
8
-
9
-
10
- class GetMergerInfoFromTransactionIdArgs(BaseModel):
11
- transaction_id: int | None = Field(description="The ID of the merger.", default=None)
12
-
13
-
14
- class GetMergerInfoFromTransactionId(KfinanceTool):
15
- name: str = "get_merger_info_from_transaction_id"
16
- description: str = 'Get the timeline, the participants, and the consideration of the merger or acquisition from the given transaction ID. For example, "How much was Ben & Jerrys purchased for?" or "What was the price per share for LinkedIn?" or "When did S&P purchase Kensho?"'
17
- args_schema: Type[BaseModel] = GetMergerInfoFromTransactionIdArgs
18
- accepted_permissions: set[Permission] | None = {Permission.MergersPermission}
19
-
20
- def _run(self, transaction_id: int) -> dict:
21
- merger_or_acquisition = MergerOrAcquisition(
22
- kfinance_api_client=self.kfinance_client.kfinance_api_client,
23
- transaction_id=transaction_id,
24
- merger_title=None,
25
- closed_date=None,
26
- )
27
- merger_timeline = merger_or_acquisition.get_timeline
28
- merger_participants = merger_or_acquisition.get_participants
29
- merger_consideration = merger_or_acquisition.get_consideration
30
-
31
- return {
32
- "timeline": [
33
- {"status": timeline["status"], "date": timeline["date"].strftime("%Y-%m-%d")}
34
- for timeline in merger_timeline.to_dict(orient="records")
35
- ]
36
- if merger_timeline is not None
37
- else None,
38
- "participants": {
39
- "target": {
40
- "company_id": merger_participants["target"].company.company_id,
41
- "company_name": merger_participants["target"].company.name,
42
- },
43
- "buyers": [
44
- {"company_id": buyer.company.company_id, "company_name": buyer.company.name}
45
- for buyer in merger_participants["buyers"]
46
- ],
47
- "sellers": [
48
- {"company_id": seller.company.company_id, "company_name": seller.company.name}
49
- for seller in merger_participants["sellers"]
50
- ],
51
- }
52
- if merger_participants is not None
53
- else None,
54
- "consideration": {
55
- "currency_name": merger_consideration["currency_name"],
56
- "current_calculated_gross_total_transaction_value": merger_consideration[
57
- "current_calculated_gross_total_transaction_value"
58
- ],
59
- "current_calculated_implied_equity_value": merger_consideration[
60
- "current_calculated_implied_equity_value"
61
- ],
62
- "current_calculated_implied_enterprise_value": merger_consideration[
63
- "current_calculated_implied_enterprise_value"
64
- ],
65
- "details": merger_consideration["details"].to_dict(orient="records"),
66
- }
67
- if merger_consideration is not None
68
- else None,
69
- }
@@ -1,44 +0,0 @@
1
- from typing import Type
2
-
3
- from pydantic import BaseModel
4
-
5
- from kfinance.models.permission_models import Permission
6
- from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
7
-
8
-
9
- class GetMergersFromIdentifier(KfinanceTool):
10
- name: str = "get_mergers_from_identifier"
11
- description: str = 'Get the transaction IDs that involve the given identifier. For example, "Which companies did Microsoft purchase?" or "Which company bought Ben & Jerrys?"'
12
- args_schema: Type[BaseModel] = ToolArgsWithIdentifier
13
- accepted_permissions: set[Permission] | None = {Permission.MergersPermission}
14
-
15
- def _run(self, identifier: str) -> dict:
16
- ticker = self.kfinance_client.ticker(identifier)
17
- mergers_and_acquisitions = ticker.company.mergers_and_acquisitions
18
-
19
- return {
20
- "target": [
21
- {
22
- "transaction_id": merger_or_acquisition.transaction_id,
23
- "merger_title": merger_or_acquisition.merger_title,
24
- "closed_date": merger_or_acquisition.closed_date,
25
- }
26
- for merger_or_acquisition in mergers_and_acquisitions["target"]
27
- ],
28
- "buyer": [
29
- {
30
- "transaction_id": merger_or_acquisition.transaction_id,
31
- "merger_title": merger_or_acquisition.merger_title,
32
- "closed_date": merger_or_acquisition.closed_date,
33
- }
34
- for merger_or_acquisition in mergers_and_acquisitions["buyer"]
35
- ],
36
- "seller": [
37
- {
38
- "transaction_id": merger_or_acquisition.transaction_id,
39
- "merger_title": merger_or_acquisition.merger_title,
40
- "closed_date": merger_or_acquisition.closed_date,
41
- }
42
- for merger_or_acquisition in mergers_and_acquisitions["seller"]
43
- ],
44
- }
@@ -1,30 +0,0 @@
1
- from typing import Type
2
-
3
- from pydantic import BaseModel
4
-
5
- from kfinance.kfinance import NoEarningsDataError
6
- from kfinance.models.permission_models import Permission
7
- from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
8
-
9
-
10
- class GetNextEarnings(KfinanceTool):
11
- name: str = "get_next_earnings"
12
- description: str = "Get the next earnings for a given identifier. Returns a dictionary with 'name' (str), 'key_dev_id' (int), and 'datetime' (str in ISO 8601 format with UTC timezone) attributes."
13
- args_schema: Type[BaseModel] = ToolArgsWithIdentifier
14
- accepted_permissions: set[Permission] | None = {
15
- Permission.EarningsPermission,
16
- Permission.TranscriptsPermission,
17
- }
18
-
19
- def _run(self, identifier: str) -> dict:
20
- ticker = self.kfinance_client.ticker(identifier)
21
- next_earnings = ticker.company.next_earnings
22
-
23
- if next_earnings is None:
24
- raise NoEarningsDataError(f"Next earnings for {identifier} not found")
25
-
26
- return {
27
- "name": next_earnings.name,
28
- "key_dev_id": next_earnings.key_dev_id,
29
- "datetime": next_earnings.datetime.isoformat(),
30
- }
@@ -1,46 +0,0 @@
1
- from datetime import date
2
- from typing import Type
3
-
4
- from pydantic import BaseModel, Field
5
-
6
- from kfinance.models.date_and_period_models import Periodicity
7
- from kfinance.models.permission_models import Permission
8
- from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
9
-
10
-
11
- class GetPricesFromIdentifierArgs(ToolArgsWithIdentifier):
12
- start_date: date | None = Field(
13
- description="The start date for historical price retrieval", default=None
14
- )
15
- end_date: date | None = Field(
16
- description="The end date for historical price retrieval", default=None
17
- )
18
- # no description because the description for enum fields comes from the enum docstring.
19
- periodicity: Periodicity = Field(default=Periodicity.day)
20
- adjusted: bool = Field(
21
- description="Whether to retrieve adjusted prices that account for corporate actions such as dividends and splits.",
22
- default=True,
23
- )
24
-
25
-
26
- class GetPricesFromIdentifier(KfinanceTool):
27
- name: str = "get_prices_from_identifier"
28
- description: str = "Get the historical open, high, low, and close prices, and volume of an identifier between inclusive start_date and inclusive end date. When requesting the most recent values, leave start_date and end_date empty."
29
- args_schema: Type[BaseModel] = GetPricesFromIdentifierArgs
30
- accepted_permissions: set[Permission] | None = {Permission.PricingPermission}
31
-
32
- def _run(
33
- self,
34
- identifier: str,
35
- start_date: date | None = None,
36
- end_date: date | None = None,
37
- periodicity: Periodicity = Periodicity.day,
38
- adjusted: bool = True,
39
- ) -> dict:
40
- ticker = self.kfinance_client.ticker(identifier)
41
- return ticker.history(
42
- start_date=start_date.isoformat() if start_date else None,
43
- end_date=end_date.isoformat() if end_date else None,
44
- periodicity=periodicity,
45
- adjusted=adjusted,
46
- ).model_dump(mode="json")
@@ -1,44 +0,0 @@
1
- from typing import Literal, Type
2
-
3
- from pydantic import BaseModel, Field
4
-
5
- from kfinance.models.date_and_period_models import PeriodType
6
- from kfinance.models.permission_models import Permission
7
- from kfinance.models.segment_models import SegmentType
8
- from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier, ValidQuarter
9
-
10
-
11
- class GetSegmentsFromIdentifierArgs(ToolArgsWithIdentifier):
12
- # no description because the description for enum fields comes from the enum docstring.
13
- segment_type: SegmentType
14
- period_type: PeriodType | None = Field(default=None, description="The period type")
15
- start_year: int | None = Field(default=None, description="The starting year for the data range")
16
- end_year: int | None = Field(default=None, description="The ending year for the data range")
17
- start_quarter: ValidQuarter | None = Field(default=None, description="Starting quarter")
18
- end_quarter: ValidQuarter | None = Field(default=None, description="Ending quarter")
19
-
20
-
21
- class GetSegmentsFromIdentifier(KfinanceTool):
22
- name: str = "get_segments_from_identifier"
23
- description: str = "Get the templated segments associated with an identifier."
24
- args_schema: Type[BaseModel] = GetSegmentsFromIdentifierArgs
25
- accepted_permissions: set[Permission] | None = {Permission.SegmentsPermission}
26
-
27
- def _run(
28
- self,
29
- identifier: str,
30
- segment_type: SegmentType,
31
- period_type: PeriodType | None = None,
32
- start_year: int | None = None,
33
- end_year: int | None = None,
34
- start_quarter: Literal[1, 2, 3, 4] | None = None,
35
- end_quarter: Literal[1, 2, 3, 4] | None = None,
36
- ) -> str:
37
- ticker = self.kfinance_client.ticker(identifier)
38
- return getattr(ticker, segment_type.value + "_segments")(
39
- period_type=period_type,
40
- start_year=start_year,
41
- end_year=end_year,
42
- start_quarter=start_quarter,
43
- end_quarter=end_quarter,
44
- )