kensho-kfinance 2.9.0__tar.gz → 3.0.0__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.
Potentially problematic release.
This version of kensho-kfinance might be problematic. Click here for more details.
- {kensho_kfinance-2.9.0/kensho_kfinance.egg-info → kensho_kfinance-3.0.0}/PKG-INFO +1 -1
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/docs/build_tool_calling_documentation.py +3 -2
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/example_notebooks/basic_usage.ipynb +5 -4
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/example_notebooks/tool_calling/langchain/anthropic_langchain_tool_calling.ipynb +2 -2
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/example_notebooks/tool_calling/langchain/google_gemini_langchain_tool_calling.ipynb +2 -2
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/example_notebooks/tool_calling/langchain/openai_langchain_tool_calling.ipynb +3 -2
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/example_notebooks/tool_calling/non-langchain/anthropic_tool_calling.ipynb +4 -3
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/example_notebooks/tool_calling/non-langchain/google_gemini_tool_calling.ipynb +2 -2
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/example_notebooks/tool_calling/non-langchain/openai_langchain_tool_calling.ipynb +2 -2
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0/kensho_kfinance.egg-info}/PKG-INFO +1 -1
- kensho_kfinance-3.0.0/kensho_kfinance.egg-info/SOURCES.txt +142 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/kfinance/CHANGELOG.md +3 -0
- kensho_kfinance-3.0.0/kfinance/__init__.py +1 -0
- kensho_kfinance-3.0.0/kfinance/client/README.md +9 -0
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client}/batch_request_handling.py +63 -27
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client}/fetch.py +23 -29
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client}/kfinance.py +37 -33
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client}/meta_classes.py +26 -35
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client/models}/decimal_with_unit.py +1 -1
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client/models}/tests/test_decimal_with_unit.py +1 -1
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client}/tests/test_batch_requests.py +8 -6
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client}/tests/test_client.py +25 -19
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client}/tests/test_fetch.py +11 -29
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client}/tests/test_group_objects.py +1 -1
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client}/tests/test_objects.py +33 -29
- {kensho_kfinance-2.9.0/kfinance/tests → kensho_kfinance-3.0.0/kfinance}/conftest.py +14 -2
- kensho_kfinance-3.0.0/kfinance/domains/README.md +14 -0
- kensho_kfinance-3.0.0/kfinance/domains/business_relationships/__init__.py +0 -0
- {kensho_kfinance-2.9.0/kfinance/models → kensho_kfinance-3.0.0/kfinance/domains/business_relationships}/business_relationship_models.py +10 -0
- kensho_kfinance-3.0.0/kfinance/domains/business_relationships/business_relationship_tools.py +74 -0
- kensho_kfinance-3.0.0/kfinance/domains/business_relationships/tests/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/business_relationships/tests/test_business_relationship_tools.py +55 -0
- kensho_kfinance-3.0.0/kfinance/domains/capitalizations/__init__.py +0 -0
- {kensho_kfinance-2.9.0/kfinance/models → kensho_kfinance-3.0.0/kfinance/domains/capitalizations}/capitalization_models.py +24 -17
- kensho_kfinance-3.0.0/kfinance/domains/capitalizations/capitalization_tools.py +89 -0
- kensho_kfinance-3.0.0/kfinance/domains/capitalizations/tests/__init__.py +0 -0
- {kensho_kfinance-2.9.0/kfinance/tests/test_models → kensho_kfinance-3.0.0/kfinance/domains/capitalizations/tests}/test_capitalization_models.py +8 -10
- kensho_kfinance-3.0.0/kfinance/domains/capitalizations/tests/test_capitalization_tools.py +85 -0
- kensho_kfinance-3.0.0/kfinance/domains/companies/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/companies/company_identifiers.py +175 -0
- kensho_kfinance-3.0.0/kfinance/domains/companies/company_models.py +27 -0
- kensho_kfinance-3.0.0/kfinance/domains/companies/company_tools.py +66 -0
- kensho_kfinance-3.0.0/kfinance/domains/companies/tests/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/companies/tests/test_company_tools.py +26 -0
- kensho_kfinance-3.0.0/kfinance/domains/competitors/__init__.py +0 -0
- {kensho_kfinance-2.9.0/kfinance/models → kensho_kfinance-3.0.0/kfinance/domains/competitors}/competitor_models.py +7 -0
- kensho_kfinance-3.0.0/kfinance/domains/competitors/competitor_tools.py +62 -0
- kensho_kfinance-3.0.0/kfinance/domains/competitors/tests/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/competitors/tests/test_competitor_tools.py +45 -0
- kensho_kfinance-3.0.0/kfinance/domains/cusip_and_isin/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/cusip_and_isin/cusip_and_isin_tools.py +80 -0
- kensho_kfinance-3.0.0/kfinance/domains/cusip_and_isin/tests/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/cusip_and_isin/tests/test_cusip_and_isin_tools.py +57 -0
- kensho_kfinance-3.0.0/kfinance/domains/earnings/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/earnings/earning_models.py +41 -0
- kensho_kfinance-3.0.0/kfinance/domains/earnings/earning_tools.py +174 -0
- kensho_kfinance-3.0.0/kfinance/domains/earnings/tests/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/earnings/tests/test_earnings_tools.py +195 -0
- kensho_kfinance-3.0.0/kfinance/domains/line_items/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/line_items/line_item_tools.py +114 -0
- kensho_kfinance-3.0.0/kfinance/domains/line_items/tests/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/line_items/tests/test_line_item_tools.py +86 -0
- kensho_kfinance-3.0.0/kfinance/domains/mergers_and_acquisitions/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/mergers_and_acquisitions/merger_and_acquisition_tools.py +176 -0
- kensho_kfinance-3.0.0/kfinance/domains/mergers_and_acquisitions/tests/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/mergers_and_acquisitions/tests/test_merger_and_acquisition_tools.py +124 -0
- kensho_kfinance-3.0.0/kfinance/domains/prices/__init__.py +0 -0
- {kensho_kfinance-2.9.0/kfinance/models → kensho_kfinance-3.0.0/kfinance/domains/prices}/price_models.py +1 -1
- kensho_kfinance-3.0.0/kfinance/domains/prices/price_tools.py +165 -0
- kensho_kfinance-3.0.0/kfinance/domains/prices/tests/__init__.py +0 -0
- {kensho_kfinance-2.9.0/kfinance/tests/test_models → kensho_kfinance-3.0.0/kfinance/domains/prices/tests}/test_price_models.py +2 -2
- kensho_kfinance-3.0.0/kfinance/domains/prices/tests/test_price_tools.py +141 -0
- kensho_kfinance-3.0.0/kfinance/domains/segments/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/segments/segment_tools.py +91 -0
- kensho_kfinance-3.0.0/kfinance/domains/segments/tests/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/segments/tests/test_segment_tools.py +80 -0
- kensho_kfinance-3.0.0/kfinance/domains/statements/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/statements/statement_tools.py +113 -0
- kensho_kfinance-3.0.0/kfinance/domains/statements/tests/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/domains/statements/tests/test_statement_tools.py +73 -0
- kensho_kfinance-3.0.0/kfinance/integrations/README.md +8 -0
- kensho_kfinance-3.0.0/kfinance/integrations/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/integrations/mcp/__init__.py +0 -0
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/integrations/mcp}/mcp.py +2 -2
- kensho_kfinance-3.0.0/kfinance/integrations/tests/__init__.py +0 -0
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/integrations}/tests/test_example_notebook.py +4 -4
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/integrations}/tool_calling/README.md +2 -2
- kensho_kfinance-3.0.0/kfinance/integrations/tool_calling/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/integrations/tool_calling/all_tools.py +55 -0
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/integrations}/tool_calling/prompts.py +3 -2
- kensho_kfinance-3.0.0/kfinance/integrations/tool_calling/static_tools/README.md +4 -0
- kensho_kfinance-3.0.0/kfinance/integrations/tool_calling/static_tools/__init__.py +0 -0
- {kensho_kfinance-2.9.0/kfinance/tool_calling → kensho_kfinance-3.0.0/kfinance/integrations/tool_calling/static_tools}/get_latest.py +3 -3
- {kensho_kfinance-2.9.0/kfinance/tool_calling → kensho_kfinance-3.0.0/kfinance/integrations/tool_calling/static_tools}/get_n_quarters_ago.py +3 -3
- kensho_kfinance-3.0.0/kfinance/integrations/tool_calling/static_tools/tests/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/integrations/tool_calling/static_tools/tests/test_get_lastest.py +30 -0
- kensho_kfinance-3.0.0/kfinance/integrations/tool_calling/static_tools/tests/test_get_n_quarters_ago.py +24 -0
- kensho_kfinance-3.0.0/kfinance/integrations/tool_calling/tests/__init__.py +0 -0
- kensho_kfinance-3.0.0/kfinance/integrations/tool_calling/tests/test_tool_calling_models.py +69 -0
- kensho_kfinance-2.9.0/kfinance/tool_calling/shared_models.py → kensho_kfinance-3.0.0/kfinance/integrations/tool_calling/tool_calling_models.py +37 -7
- kensho_kfinance-3.0.0/kfinance/py.typed +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/kfinance/version.py +2 -2
- kensho_kfinance-2.9.0/kensho_kfinance.egg-info/SOURCES.txt +0 -102
- kensho_kfinance-2.9.0/kfinance/models/id_models.py +0 -7
- kensho_kfinance-2.9.0/kfinance/prompt.py +0 -526
- kensho_kfinance-2.9.0/kfinance/pydantic_models.py +0 -33
- kensho_kfinance-2.9.0/kfinance/tests/test_tools.py +0 -804
- kensho_kfinance-2.9.0/kfinance/tool_calling/__init__.py +0 -53
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_advisors_for_company_in_transaction_from_identifier.py +0 -42
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_business_relationship_from_identifier.py +0 -30
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_capitalization_from_identifier.py +0 -35
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_competitors_from_identifier.py +0 -25
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_cusip_from_ticker.py +0 -20
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_earnings.py +0 -33
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_financial_line_item_from_identifier.py +0 -48
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_financial_statement_from_identifier.py +0 -44
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_history_metadata_from_identifier.py +0 -17
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_info_from_identifier.py +0 -16
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_isin_from_ticker.py +0 -20
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_latest_earnings.py +0 -30
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_merger_info_from_transaction_id.py +0 -69
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_mergers_from_identifier.py +0 -44
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_next_earnings.py +0 -30
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_prices_from_identifier.py +0 -46
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_segments_from_identifier.py +0 -44
- kensho_kfinance-2.9.0/kfinance/tool_calling/get_transcript.py +0 -23
- kensho_kfinance-2.9.0/kfinance/tool_calling/resolve_identifier.py +0 -18
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/.coveragerc +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/.github/workflows/ci-lint.yml +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/.github/workflows/ci-test.yml +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/.github/workflows/python-publish.yml +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/.gitignore +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/.readthedocs.yaml +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/AUTHORS.md +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/CODE_OF_CONDUCT.md +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/CONTRIBUTING.md +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/LICENSE +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/README.md +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/docs/conf.py +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/docs/index.rst +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/docs/kfinance.rst +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/docs/requirements.txt +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/docs/templates/apidoc/package.rst_t +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/docs/templates/apidoc/toc.rst_t +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/docs/tool_calling.rst +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/images/colab_logo_32px.png +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/justfile +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/kensho_kfinance.egg-info/dependency_links.txt +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/kensho_kfinance.egg-info/requires.txt +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/kensho_kfinance.egg-info/top_level.txt +0 -0
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client}/__init__.py +0 -0
- {kensho_kfinance-2.9.0/kfinance/models → kensho_kfinance-3.0.0/kfinance/client}/industry_models.py +0 -0
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client}/models/__init__.py +0 -0
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client}/models/currency_models.py +0 -0
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client}/models/date_and_period_models.py +0 -0
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client/models}/tests/__init__.py +0 -0
- {kensho_kfinance-2.9.0/kfinance/models → kensho_kfinance-3.0.0/kfinance/client}/permission_models.py +0 -0
- {kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client}/server_thread.py +0 -0
- {kensho_kfinance-2.9.0/kfinance/tests/test_models → kensho_kfinance-3.0.0/kfinance/client/tests}/__init__.py +0 -0
- /kensho_kfinance-2.9.0/kfinance/py.typed → /kensho_kfinance-3.0.0/kfinance/domains/__init__.py +0 -0
- {kensho_kfinance-2.9.0/kfinance/models → kensho_kfinance-3.0.0/kfinance/domains/line_items}/line_item_models.py +0 -0
- {kensho_kfinance-2.9.0/kfinance/models → kensho_kfinance-3.0.0/kfinance/domains/segments}/segment_models.py +0 -0
- {kensho_kfinance-2.9.0/kfinance/models → kensho_kfinance-3.0.0/kfinance/domains/statements}/statement_models.py +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/pyproject.toml +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/scripts/copyright_line_check.sh +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/scripts/lint.sh +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/scripts/test.sh +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/setup.cfg +0 -0
- {kensho_kfinance-2.9.0 → kensho_kfinance-3.0.0}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: kensho-kfinance
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.0.0
|
|
4
4
|
Summary: Python CLI for kFinance
|
|
5
5
|
Author-email: Luke Brown <luke.brown@kensho.com>, Michelle Keoy <michelle.keoy@kensho.com>, Keith Page <keith.page@kensho.com>, Matthew Rosen <matthew.rosen@kensho.com>, Nick Roshdieh <nick.roshdieh@kensho.com>
|
|
6
6
|
Project-URL: source, https://github.com/kensho-technologies/kfinance
|
|
@@ -5,8 +5,9 @@ from pathlib import Path
|
|
|
5
5
|
from langchain_core.utils.function_calling import convert_to_openai_tool
|
|
6
6
|
from pydantic._internal._repr import display_as_type
|
|
7
7
|
|
|
8
|
-
from kfinance.kfinance import Client
|
|
9
|
-
from kfinance.tool_calling import ALL_TOOLS
|
|
8
|
+
from kfinance.client.kfinance import Client
|
|
9
|
+
from kfinance.integrations.tool_calling.all_tools import ALL_TOOLS
|
|
10
|
+
from kfinance.integrations.tool_calling.tool_calling_models import KfinanceTool
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
def add_tool_calling_docs_for_all_tools() -> None:
|
|
@@ -58,7 +58,8 @@
|
|
|
58
58
|
"outputs": [],
|
|
59
59
|
"source": [
|
|
60
60
|
"# import the kfinance client\n",
|
|
61
|
-
"from kfinance.kfinance import Client\n",
|
|
61
|
+
"from kfinance.client.kfinance import Client\n",
|
|
62
|
+
"\n",
|
|
62
63
|
"# import standard libraries\n",
|
|
63
64
|
"import functools\n",
|
|
64
65
|
"import types\n",
|
|
@@ -98,8 +99,6 @@
|
|
|
98
99
|
"metadata": {},
|
|
99
100
|
"outputs": [],
|
|
100
101
|
"source": [
|
|
101
|
-
"from kfinance.models.date_and_period_models import PeriodType\n",
|
|
102
|
-
"\n",
|
|
103
102
|
"# You can create a Ticker object with client.ticker.\n",
|
|
104
103
|
"# A Ticker has access to a wide variety of attributes, including prices, \n",
|
|
105
104
|
"# market caps, statements, and line items.\n",
|
|
@@ -150,6 +149,8 @@
|
|
|
150
149
|
"execution_count": null,
|
|
151
150
|
"outputs": [],
|
|
152
151
|
"source": [
|
|
152
|
+
"from kfinance.client.models.date_and_period_models import PeriodType\n",
|
|
153
|
+
"\n",
|
|
153
154
|
"# However, it's also possible to set parameters to fetch, \n",
|
|
154
155
|
"# for example, annual balance sheets from the 2010s.\n",
|
|
155
156
|
"spgi.balance_sheet(period_type=PeriodType.annual, start_year=2010, end_year=2019)"
|
|
@@ -220,7 +221,7 @@
|
|
|
220
221
|
"execution_count": null,
|
|
221
222
|
"outputs": [],
|
|
222
223
|
"source": [
|
|
223
|
-
"from kfinance.models.date_and_period_models import Periodicity\n",
|
|
224
|
+
"from kfinance.client.models.date_and_period_models import Periodicity\n",
|
|
224
225
|
"\n",
|
|
225
226
|
"# To fetch recent spgi prices, you can use the `history` function.\n",
|
|
226
227
|
"# Without any further configuration `history()` will return adjusted\n",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"source": [
|
|
84
84
|
"# import the kfinance client\n",
|
|
85
85
|
"import sys\n",
|
|
86
|
-
"from kfinance.kfinance import Client\n",
|
|
86
|
+
"from kfinance.client.kfinance import Client\n",
|
|
87
87
|
"\n",
|
|
88
88
|
"# check if the current environment is a Google Colab\n",
|
|
89
89
|
"try:\n",
|
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
"outputs": [],
|
|
131
131
|
"source": [
|
|
132
132
|
"from pydantic import SecretStr\n",
|
|
133
|
-
"from kfinance.tool_calling.prompts import BASE_PROMPT\n",
|
|
133
|
+
"from kfinance.integrations.tool_calling.prompts import BASE_PROMPT\n",
|
|
134
134
|
"from langchain.agents import AgentExecutor, create_tool_calling_agent\n",
|
|
135
135
|
"from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
|
|
136
136
|
"from langchain_anthropic import ChatAnthropic\n",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"source": [
|
|
85
85
|
"# import the kfinance client\n",
|
|
86
86
|
"import sys\n",
|
|
87
|
-
"from kfinance.kfinance import Client\n",
|
|
87
|
+
"from kfinance.client.kfinance import Client\n",
|
|
88
88
|
"# check if the current environment is a Google Colab\n",
|
|
89
89
|
"try:\n",
|
|
90
90
|
" import google.colab\n",
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
},
|
|
129
129
|
"outputs": [],
|
|
130
130
|
"source": [
|
|
131
|
-
"from kfinance.tool_calling.prompts import BASE_PROMPT\n",
|
|
131
|
+
"from kfinance.integrations.tool_calling.prompts import BASE_PROMPT\n",
|
|
132
132
|
"# import langchain\n",
|
|
133
133
|
"from langchain.agents import AgentExecutor, create_tool_calling_agent\n",
|
|
134
134
|
"from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"source": [
|
|
85
85
|
"# import the kfinance client\n",
|
|
86
86
|
"import sys\n",
|
|
87
|
-
"from kfinance.kfinance import Client\n",
|
|
87
|
+
"from kfinance.client.kfinance import Client\n",
|
|
88
88
|
"# check if the current environment is a Google Colab\n",
|
|
89
89
|
"try:\n",
|
|
90
90
|
" import google.colab\n",
|
|
@@ -125,7 +125,8 @@
|
|
|
125
125
|
"execution_count": null,
|
|
126
126
|
"outputs": [],
|
|
127
127
|
"source": [
|
|
128
|
-
"
|
|
128
|
+
"\n",
|
|
129
|
+
"from kfinance.integrations.tool_calling.prompts import BASE_PROMPT\n",
|
|
129
130
|
"from pydantic import SecretStr\n",
|
|
130
131
|
"from langchain.agents import AgentExecutor, create_tool_calling_agent\n",
|
|
131
132
|
"from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"import json\n",
|
|
84
84
|
"\n",
|
|
85
85
|
"# import the kfinance client\n",
|
|
86
|
-
"from kfinance.kfinance import Client\n",
|
|
86
|
+
"from kfinance.client.kfinance import Client\n",
|
|
87
87
|
"\n",
|
|
88
88
|
"# check if the current environment is a Google Colab\n",
|
|
89
89
|
"try:\n",
|
|
@@ -129,12 +129,13 @@
|
|
|
129
129
|
},
|
|
130
130
|
"outputs": [],
|
|
131
131
|
"source": [
|
|
132
|
+
"from kfinance.integrations.tool_calling.prompts import BASE_PROMPT\n",
|
|
132
133
|
"from typing import Any, cast\n",
|
|
133
|
-
"
|
|
134
|
-
"from kfinance.tool_calling.prompts import BASE_PROMPT\n",
|
|
134
|
+
"\n",
|
|
135
135
|
"# import Anthropic\n",
|
|
136
136
|
"from anthropic import Anthropic\n",
|
|
137
137
|
"from anthropic.types import TextBlock, ToolUseBlock\n",
|
|
138
|
+
"from anthropic.types import ToolParam, Message, MessageParam, ToolResultBlockParam\n",
|
|
138
139
|
"\n",
|
|
139
140
|
"\n",
|
|
140
141
|
"def text_from_response_message(response_message: Any) -> str | None:\n",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"outputs": [],
|
|
82
82
|
"source": [
|
|
83
83
|
"# import the kfinance client\n",
|
|
84
|
-
"from kfinance.kfinance import Client\n",
|
|
84
|
+
"from kfinance.client.kfinance import Client\n",
|
|
85
85
|
"import json\n",
|
|
86
86
|
"\n",
|
|
87
87
|
"# check if the current environment is a Google Colab\n",
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
},
|
|
129
129
|
"outputs": [],
|
|
130
130
|
"source": [
|
|
131
|
-
"from kfinance.tool_calling.prompts import BASE_PROMPT\n",
|
|
131
|
+
"from kfinance.integrations.tool_calling.prompts import BASE_PROMPT\n",
|
|
132
132
|
"# import Google's generativeai package ('Gemini')\n",
|
|
133
133
|
"import google.generativeai as genai\n",
|
|
134
134
|
"\n",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"import json\n",
|
|
84
84
|
"\n",
|
|
85
85
|
"# import the kfinance client\n",
|
|
86
|
-
"from kfinance.kfinance import Client\n",
|
|
86
|
+
"from kfinance.client.kfinance import Client\n",
|
|
87
87
|
"\n",
|
|
88
88
|
"# check if the current environment is a Google Colab\n",
|
|
89
89
|
"try:\n",
|
|
@@ -129,10 +129,10 @@
|
|
|
129
129
|
},
|
|
130
130
|
"outputs": [],
|
|
131
131
|
"source": [
|
|
132
|
+
"from kfinance.integrations.tool_calling.prompts import BASE_PROMPT\n",
|
|
132
133
|
"from typing import cast\n",
|
|
133
134
|
"from openai.types.chat import ChatCompletionMessage, ChatCompletionMessageParam, \\\n",
|
|
134
135
|
" ChatCompletionAssistantMessageParam, ChatCompletionSystemMessageParam, ChatCompletionToolParam\n",
|
|
135
|
-
"from kfinance.tool_calling.prompts import BASE_PROMPT\n",
|
|
136
136
|
"# import OpenAI\n",
|
|
137
137
|
"from openai import OpenAI\n",
|
|
138
138
|
"\n",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: kensho-kfinance
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.0.0
|
|
4
4
|
Summary: Python CLI for kFinance
|
|
5
5
|
Author-email: Luke Brown <luke.brown@kensho.com>, Michelle Keoy <michelle.keoy@kensho.com>, Keith Page <keith.page@kensho.com>, Matthew Rosen <matthew.rosen@kensho.com>, Nick Roshdieh <nick.roshdieh@kensho.com>
|
|
6
6
|
Project-URL: source, https://github.com/kensho-technologies/kfinance
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
.coveragerc
|
|
2
|
+
.gitignore
|
|
3
|
+
.readthedocs.yaml
|
|
4
|
+
AUTHORS.md
|
|
5
|
+
CODE_OF_CONDUCT.md
|
|
6
|
+
CONTRIBUTING.md
|
|
7
|
+
LICENSE
|
|
8
|
+
README.md
|
|
9
|
+
justfile
|
|
10
|
+
pyproject.toml
|
|
11
|
+
setup.py
|
|
12
|
+
.github/workflows/ci-lint.yml
|
|
13
|
+
.github/workflows/ci-test.yml
|
|
14
|
+
.github/workflows/python-publish.yml
|
|
15
|
+
docs/build_tool_calling_documentation.py
|
|
16
|
+
docs/conf.py
|
|
17
|
+
docs/index.rst
|
|
18
|
+
docs/kfinance.rst
|
|
19
|
+
docs/requirements.txt
|
|
20
|
+
docs/tool_calling.rst
|
|
21
|
+
docs/templates/apidoc/package.rst_t
|
|
22
|
+
docs/templates/apidoc/toc.rst_t
|
|
23
|
+
example_notebooks/basic_usage.ipynb
|
|
24
|
+
example_notebooks/tool_calling/langchain/anthropic_langchain_tool_calling.ipynb
|
|
25
|
+
example_notebooks/tool_calling/langchain/google_gemini_langchain_tool_calling.ipynb
|
|
26
|
+
example_notebooks/tool_calling/langchain/openai_langchain_tool_calling.ipynb
|
|
27
|
+
example_notebooks/tool_calling/non-langchain/anthropic_tool_calling.ipynb
|
|
28
|
+
example_notebooks/tool_calling/non-langchain/google_gemini_tool_calling.ipynb
|
|
29
|
+
example_notebooks/tool_calling/non-langchain/openai_langchain_tool_calling.ipynb
|
|
30
|
+
images/colab_logo_32px.png
|
|
31
|
+
kensho_kfinance.egg-info/PKG-INFO
|
|
32
|
+
kensho_kfinance.egg-info/SOURCES.txt
|
|
33
|
+
kensho_kfinance.egg-info/dependency_links.txt
|
|
34
|
+
kensho_kfinance.egg-info/requires.txt
|
|
35
|
+
kensho_kfinance.egg-info/top_level.txt
|
|
36
|
+
kfinance/CHANGELOG.md
|
|
37
|
+
kfinance/__init__.py
|
|
38
|
+
kfinance/conftest.py
|
|
39
|
+
kfinance/py.typed
|
|
40
|
+
kfinance/version.py
|
|
41
|
+
kfinance/client/README.md
|
|
42
|
+
kfinance/client/__init__.py
|
|
43
|
+
kfinance/client/batch_request_handling.py
|
|
44
|
+
kfinance/client/fetch.py
|
|
45
|
+
kfinance/client/industry_models.py
|
|
46
|
+
kfinance/client/kfinance.py
|
|
47
|
+
kfinance/client/meta_classes.py
|
|
48
|
+
kfinance/client/permission_models.py
|
|
49
|
+
kfinance/client/server_thread.py
|
|
50
|
+
kfinance/client/models/__init__.py
|
|
51
|
+
kfinance/client/models/currency_models.py
|
|
52
|
+
kfinance/client/models/date_and_period_models.py
|
|
53
|
+
kfinance/client/models/decimal_with_unit.py
|
|
54
|
+
kfinance/client/models/tests/__init__.py
|
|
55
|
+
kfinance/client/models/tests/test_decimal_with_unit.py
|
|
56
|
+
kfinance/client/tests/__init__.py
|
|
57
|
+
kfinance/client/tests/test_batch_requests.py
|
|
58
|
+
kfinance/client/tests/test_client.py
|
|
59
|
+
kfinance/client/tests/test_fetch.py
|
|
60
|
+
kfinance/client/tests/test_group_objects.py
|
|
61
|
+
kfinance/client/tests/test_objects.py
|
|
62
|
+
kfinance/domains/README.md
|
|
63
|
+
kfinance/domains/__init__.py
|
|
64
|
+
kfinance/domains/business_relationships/__init__.py
|
|
65
|
+
kfinance/domains/business_relationships/business_relationship_models.py
|
|
66
|
+
kfinance/domains/business_relationships/business_relationship_tools.py
|
|
67
|
+
kfinance/domains/business_relationships/tests/__init__.py
|
|
68
|
+
kfinance/domains/business_relationships/tests/test_business_relationship_tools.py
|
|
69
|
+
kfinance/domains/capitalizations/__init__.py
|
|
70
|
+
kfinance/domains/capitalizations/capitalization_models.py
|
|
71
|
+
kfinance/domains/capitalizations/capitalization_tools.py
|
|
72
|
+
kfinance/domains/capitalizations/tests/__init__.py
|
|
73
|
+
kfinance/domains/capitalizations/tests/test_capitalization_models.py
|
|
74
|
+
kfinance/domains/capitalizations/tests/test_capitalization_tools.py
|
|
75
|
+
kfinance/domains/companies/__init__.py
|
|
76
|
+
kfinance/domains/companies/company_identifiers.py
|
|
77
|
+
kfinance/domains/companies/company_models.py
|
|
78
|
+
kfinance/domains/companies/company_tools.py
|
|
79
|
+
kfinance/domains/companies/tests/__init__.py
|
|
80
|
+
kfinance/domains/companies/tests/test_company_tools.py
|
|
81
|
+
kfinance/domains/competitors/__init__.py
|
|
82
|
+
kfinance/domains/competitors/competitor_models.py
|
|
83
|
+
kfinance/domains/competitors/competitor_tools.py
|
|
84
|
+
kfinance/domains/competitors/tests/__init__.py
|
|
85
|
+
kfinance/domains/competitors/tests/test_competitor_tools.py
|
|
86
|
+
kfinance/domains/cusip_and_isin/__init__.py
|
|
87
|
+
kfinance/domains/cusip_and_isin/cusip_and_isin_tools.py
|
|
88
|
+
kfinance/domains/cusip_and_isin/tests/__init__.py
|
|
89
|
+
kfinance/domains/cusip_and_isin/tests/test_cusip_and_isin_tools.py
|
|
90
|
+
kfinance/domains/earnings/__init__.py
|
|
91
|
+
kfinance/domains/earnings/earning_models.py
|
|
92
|
+
kfinance/domains/earnings/earning_tools.py
|
|
93
|
+
kfinance/domains/earnings/tests/__init__.py
|
|
94
|
+
kfinance/domains/earnings/tests/test_earnings_tools.py
|
|
95
|
+
kfinance/domains/line_items/__init__.py
|
|
96
|
+
kfinance/domains/line_items/line_item_models.py
|
|
97
|
+
kfinance/domains/line_items/line_item_tools.py
|
|
98
|
+
kfinance/domains/line_items/tests/__init__.py
|
|
99
|
+
kfinance/domains/line_items/tests/test_line_item_tools.py
|
|
100
|
+
kfinance/domains/mergers_and_acquisitions/__init__.py
|
|
101
|
+
kfinance/domains/mergers_and_acquisitions/merger_and_acquisition_tools.py
|
|
102
|
+
kfinance/domains/mergers_and_acquisitions/tests/__init__.py
|
|
103
|
+
kfinance/domains/mergers_and_acquisitions/tests/test_merger_and_acquisition_tools.py
|
|
104
|
+
kfinance/domains/prices/__init__.py
|
|
105
|
+
kfinance/domains/prices/price_models.py
|
|
106
|
+
kfinance/domains/prices/price_tools.py
|
|
107
|
+
kfinance/domains/prices/tests/__init__.py
|
|
108
|
+
kfinance/domains/prices/tests/test_price_models.py
|
|
109
|
+
kfinance/domains/prices/tests/test_price_tools.py
|
|
110
|
+
kfinance/domains/segments/__init__.py
|
|
111
|
+
kfinance/domains/segments/segment_models.py
|
|
112
|
+
kfinance/domains/segments/segment_tools.py
|
|
113
|
+
kfinance/domains/segments/tests/__init__.py
|
|
114
|
+
kfinance/domains/segments/tests/test_segment_tools.py
|
|
115
|
+
kfinance/domains/statements/__init__.py
|
|
116
|
+
kfinance/domains/statements/statement_models.py
|
|
117
|
+
kfinance/domains/statements/statement_tools.py
|
|
118
|
+
kfinance/domains/statements/tests/__init__.py
|
|
119
|
+
kfinance/domains/statements/tests/test_statement_tools.py
|
|
120
|
+
kfinance/integrations/README.md
|
|
121
|
+
kfinance/integrations/__init__.py
|
|
122
|
+
kfinance/integrations/mcp/__init__.py
|
|
123
|
+
kfinance/integrations/mcp/mcp.py
|
|
124
|
+
kfinance/integrations/tests/__init__.py
|
|
125
|
+
kfinance/integrations/tests/test_example_notebook.py
|
|
126
|
+
kfinance/integrations/tool_calling/README.md
|
|
127
|
+
kfinance/integrations/tool_calling/__init__.py
|
|
128
|
+
kfinance/integrations/tool_calling/all_tools.py
|
|
129
|
+
kfinance/integrations/tool_calling/prompts.py
|
|
130
|
+
kfinance/integrations/tool_calling/tool_calling_models.py
|
|
131
|
+
kfinance/integrations/tool_calling/static_tools/README.md
|
|
132
|
+
kfinance/integrations/tool_calling/static_tools/__init__.py
|
|
133
|
+
kfinance/integrations/tool_calling/static_tools/get_latest.py
|
|
134
|
+
kfinance/integrations/tool_calling/static_tools/get_n_quarters_ago.py
|
|
135
|
+
kfinance/integrations/tool_calling/static_tools/tests/__init__.py
|
|
136
|
+
kfinance/integrations/tool_calling/static_tools/tests/test_get_lastest.py
|
|
137
|
+
kfinance/integrations/tool_calling/static_tools/tests/test_get_n_quarters_ago.py
|
|
138
|
+
kfinance/integrations/tool_calling/tests/__init__.py
|
|
139
|
+
kfinance/integrations/tool_calling/tests/test_tool_calling_models.py
|
|
140
|
+
scripts/copyright_line_check.sh
|
|
141
|
+
scripts/lint.sh
|
|
142
|
+
scripts/test.sh
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from kfinance.integrations.mcp.mcp import run_mcp # noqa:F401
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Client
|
|
2
|
+
|
|
3
|
+
Client contains the main Kfinance `Client` class from `kfinance.py`
|
|
4
|
+
and the lower level `KFinanceApiClient` from `fetch.py`. It also
|
|
5
|
+
includes the objects like `Company` on which the `Client` operates
|
|
6
|
+
and related helpers like batch processing functionality.
|
|
7
|
+
|
|
8
|
+
It may at some point make sense to factor out objects and fetch
|
|
9
|
+
functions into their related domains.
|
{kensho_kfinance-2.9.0/kfinance → kensho_kfinance-3.0.0/kfinance/client}/batch_request_handling.py
RENAMED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
from concurrent.futures import Future
|
|
2
|
+
from dataclasses import dataclass, field
|
|
2
3
|
import functools
|
|
3
4
|
import threading
|
|
4
|
-
from typing import Any, Callable, Iterable, Protocol, Sized, Type, TypeVar
|
|
5
|
+
from typing import Any, Callable, Hashable, Iterable, Protocol, Sized, Type, TypeVar
|
|
5
6
|
|
|
6
7
|
from requests.exceptions import HTTPError
|
|
7
8
|
|
|
8
|
-
from .fetch import KFinanceApiClient
|
|
9
|
+
from kfinance.client.fetch import KFinanceApiClient
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
T = TypeVar("T")
|
|
@@ -54,29 +55,6 @@ def add_methods_of_singular_class_to_iterable_class(singular_cls: Type[T]) -> Ca
|
|
|
54
55
|
instances of [singular_cls].
|
|
55
56
|
"""
|
|
56
57
|
|
|
57
|
-
def process_in_batch(
|
|
58
|
-
method: Callable, self: IterableKfinanceClass, *args: Any, **kwargs: Any
|
|
59
|
-
) -> dict:
|
|
60
|
-
with self.kfinance_api_client.batch_request_header(batch_size=len(self)):
|
|
61
|
-
futures = []
|
|
62
|
-
for obj in self:
|
|
63
|
-
# Acquire throttle before submitting the task
|
|
64
|
-
throttle.acquire()
|
|
65
|
-
future = self.kfinance_api_client.thread_pool.submit(
|
|
66
|
-
method, obj, *args, **kwargs
|
|
67
|
-
)
|
|
68
|
-
# On success or failure, release the throttle.
|
|
69
|
-
# This releases the throttle before the
|
|
70
|
-
# `resolve_future_with_error_handling` call.
|
|
71
|
-
future.add_done_callback(lambda f: throttle.release())
|
|
72
|
-
futures.append(future)
|
|
73
|
-
|
|
74
|
-
results = {}
|
|
75
|
-
for obj, future in zip(self, futures):
|
|
76
|
-
results[obj] = resolve_future_with_error_handling(future)
|
|
77
|
-
|
|
78
|
-
return results
|
|
79
|
-
|
|
80
58
|
for method_name in dir(singular_cls):
|
|
81
59
|
method = getattr(singular_cls, method_name)
|
|
82
60
|
if method_name.startswith("__") or method_name.startswith("set_"):
|
|
@@ -88,7 +66,13 @@ def add_methods_of_singular_class_to_iterable_class(singular_cls: Type[T]) -> Ca
|
|
|
88
66
|
def method_wrapper(
|
|
89
67
|
self: IterableKfinanceClass, *args: Any, **kwargs: Any
|
|
90
68
|
) -> dict:
|
|
91
|
-
return
|
|
69
|
+
return process_tasks_in_thread_pool_executor(
|
|
70
|
+
api_client=self.kfinance_api_client,
|
|
71
|
+
tasks=[
|
|
72
|
+
Task(func=method, args=(obj, *args), kwargs=kwargs, result_key=obj)
|
|
73
|
+
for obj in self
|
|
74
|
+
],
|
|
75
|
+
)
|
|
92
76
|
|
|
93
77
|
return method_wrapper
|
|
94
78
|
|
|
@@ -102,7 +86,12 @@ def add_methods_of_singular_class_to_iterable_class(singular_cls: Type[T]) -> Ca
|
|
|
102
86
|
@functools.wraps(method.fget)
|
|
103
87
|
def prop_wrapper(self: IterableKfinanceClass) -> Any:
|
|
104
88
|
assert method.fget is not None
|
|
105
|
-
return
|
|
89
|
+
return process_tasks_in_thread_pool_executor(
|
|
90
|
+
api_client=self.kfinance_api_client,
|
|
91
|
+
tasks=[
|
|
92
|
+
Task(func=method.fget, args=(obj,), result_key=obj) for obj in self
|
|
93
|
+
],
|
|
94
|
+
)
|
|
106
95
|
|
|
107
96
|
return prop_wrapper
|
|
108
97
|
|
|
@@ -113,6 +102,53 @@ def add_methods_of_singular_class_to_iterable_class(singular_cls: Type[T]) -> Ca
|
|
|
113
102
|
return decorator
|
|
114
103
|
|
|
115
104
|
|
|
105
|
+
@dataclass(kw_only=True)
|
|
106
|
+
class Task:
|
|
107
|
+
"""A task for batch processing.
|
|
108
|
+
|
|
109
|
+
- args and kwargs are intended to be passed into the func as func(*args, **kwargs)
|
|
110
|
+
- results from batch processing are returned as dicts. The result_key is usually
|
|
111
|
+
something that either is an id (e.g. company_id) or has an id (e.g. Company
|
|
112
|
+
or CompanyIdentifier), used to map from that key to the corresponding result.
|
|
113
|
+
- The future is used to store the batch processing future. It should not be modified
|
|
114
|
+
directly outside of process_tasks_in_thread_pool_executor.
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
func: Callable
|
|
118
|
+
args: Any = field(default_factory=tuple)
|
|
119
|
+
kwargs: Any = field(default_factory=dict)
|
|
120
|
+
result_key: Hashable
|
|
121
|
+
future: Future | None = field(init=False, default=None)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def process_tasks_in_thread_pool_executor(api_client: KFinanceApiClient, tasks: list[Task]) -> dict:
|
|
125
|
+
"""Execute a list of tasks in the api client's thread pool executor and return the results.
|
|
126
|
+
|
|
127
|
+
Returns a dict mapping from each task's key to the corresponding result.
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
# Update access if necessary before submitting batch job.
|
|
131
|
+
# If the batch job starts without a valid token, each thread may try to refresh it.
|
|
132
|
+
assert api_client.access_token
|
|
133
|
+
with api_client.batch_request_header(batch_size=len(tasks)):
|
|
134
|
+
for task in tasks:
|
|
135
|
+
# Acquire throttle before submitting the task
|
|
136
|
+
throttle.acquire()
|
|
137
|
+
future = api_client.thread_pool.submit(task.func, *task.args, **task.kwargs)
|
|
138
|
+
# On success or failure, release the throttle.
|
|
139
|
+
# This releases the throttle before the
|
|
140
|
+
# `resolve_future_with_error_handling` call.
|
|
141
|
+
future.add_done_callback(lambda f: throttle.release())
|
|
142
|
+
task.future = future
|
|
143
|
+
|
|
144
|
+
results = {}
|
|
145
|
+
for task in tasks:
|
|
146
|
+
assert task.future
|
|
147
|
+
results[task.result_key] = resolve_future_with_error_handling(task.future)
|
|
148
|
+
|
|
149
|
+
return results
|
|
150
|
+
|
|
151
|
+
|
|
116
152
|
def resolve_future_with_error_handling(future: Future) -> Any:
|
|
117
153
|
"""Return the result of a future with error handling for non-200 status codes.
|
|
118
154
|
|
|
@@ -7,19 +7,21 @@ from typing import Callable, Generator, Optional
|
|
|
7
7
|
from uuid import uuid4
|
|
8
8
|
|
|
9
9
|
import jwt
|
|
10
|
-
from pydantic import ValidationError
|
|
11
10
|
import requests
|
|
12
11
|
|
|
13
|
-
from kfinance.
|
|
14
|
-
from kfinance.models.
|
|
15
|
-
from kfinance.
|
|
16
|
-
from kfinance.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
from kfinance.
|
|
21
|
-
from kfinance.
|
|
22
|
-
from kfinance.
|
|
12
|
+
from kfinance.client.industry_models import IndustryClassification
|
|
13
|
+
from kfinance.client.models.date_and_period_models import Periodicity, PeriodType
|
|
14
|
+
from kfinance.client.permission_models import Permission
|
|
15
|
+
from kfinance.domains.business_relationships.business_relationship_models import (
|
|
16
|
+
BusinessRelationshipType,
|
|
17
|
+
RelationshipResponse,
|
|
18
|
+
)
|
|
19
|
+
from kfinance.domains.capitalizations.capitalization_models import Capitalizations
|
|
20
|
+
from kfinance.domains.companies.company_models import IdentificationTriple
|
|
21
|
+
from kfinance.domains.competitors.competitor_models import CompetitorResponse, CompetitorSource
|
|
22
|
+
from kfinance.domains.earnings.earning_models import EarningsCallResp
|
|
23
|
+
from kfinance.domains.prices.price_models import PriceHistory
|
|
24
|
+
from kfinance.domains.segments.segment_models import SegmentType
|
|
23
25
|
|
|
24
26
|
|
|
25
27
|
# version.py gets autogenerated by setuptools-scm and is not available
|
|
@@ -528,30 +530,20 @@ class KFinanceApiClient:
|
|
|
528
530
|
|
|
529
531
|
def fetch_companies_from_business_relationship(
|
|
530
532
|
self, company_id: int, relationship_type: BusinessRelationshipType
|
|
531
|
-
) -> RelationshipResponse
|
|
533
|
+
) -> RelationshipResponse:
|
|
532
534
|
"""Fetches a dictionary of current and previous company IDs and names associated with a given company ID based on the specified relationship type.
|
|
533
535
|
|
|
534
536
|
Example: fetch_companies_from_business_relationship(company_id=1234, relationship_type="distributor") returns a dictionary of company 1234's current and previous distributors.
|
|
535
537
|
|
|
536
|
-
As of 2024-05-28, we are changing the response on the backend from
|
|
537
|
-
RelationshipResponseNoName to RelationshipResponse. This function can handle both response
|
|
538
|
-
types.
|
|
539
|
-
|
|
540
538
|
:param company_id: The ID of the company for which associated companies are being fetched.
|
|
541
539
|
:type company_id: int
|
|
542
540
|
:param relationship_type: The type of relationship to filter by. Valid relationship types are defined in the BusinessRelationshipType class.
|
|
543
541
|
:type relationship_type: BusinessRelationshipType
|
|
544
|
-
:return: A dictionary containing lists of current and previous company IDs that have the specified relationship with the given company_id.
|
|
545
|
-
:rtype: RelationshipResponse
|
|
542
|
+
:return: A dictionary containing lists of current and previous company IDs and names that have the specified relationship with the given company_id.
|
|
543
|
+
:rtype: RelationshipResponse
|
|
546
544
|
"""
|
|
547
545
|
url = f"{self.url_base}relationship/{company_id}/{relationship_type}"
|
|
548
|
-
|
|
549
|
-
# Try to parse as the newer RelationshipResponse and fall back to
|
|
550
|
-
# RelationshipResponseNoName if that fails.
|
|
551
|
-
try:
|
|
552
|
-
return RelationshipResponse.model_validate(result)
|
|
553
|
-
except ValidationError:
|
|
554
|
-
return RelationshipResponseNoName.model_validate(result)
|
|
546
|
+
return RelationshipResponse.model_validate(self.fetch(url))
|
|
555
547
|
|
|
556
548
|
def fetch_ticker_from_industry_code(
|
|
557
549
|
self,
|
|
@@ -589,22 +581,24 @@ class KFinanceApiClient:
|
|
|
589
581
|
url = f"{self.url_base}company_groups/industry/{industry_classification}/{industry_code}"
|
|
590
582
|
return self.fetch(url)
|
|
591
583
|
|
|
592
|
-
def fetch_earnings(self, company_id: int) ->
|
|
584
|
+
def fetch_earnings(self, company_id: int) -> EarningsCallResp:
|
|
593
585
|
"""Get the earnings for a company."""
|
|
594
586
|
url = f"{self.url_base}earnings/{company_id}"
|
|
595
|
-
return self.fetch(url)
|
|
587
|
+
return EarningsCallResp.model_validate(self.fetch(url))
|
|
596
588
|
|
|
597
589
|
def fetch_transcript(self, key_dev_id: int) -> dict:
|
|
598
590
|
"""Get the transcript for an earnings item."""
|
|
599
591
|
url = f"{self.url_base}transcript/{key_dev_id}"
|
|
600
592
|
return self.fetch(url)
|
|
601
593
|
|
|
602
|
-
def fetch_competitors(
|
|
594
|
+
def fetch_competitors(
|
|
595
|
+
self, company_id: int, competitor_source: CompetitorSource
|
|
596
|
+
) -> CompetitorResponse:
|
|
603
597
|
"""Get the competitors for a company."""
|
|
604
598
|
url = f"{self.url_base}competitors/{company_id}"
|
|
605
599
|
if competitor_source is not CompetitorSource.all:
|
|
606
600
|
url = url + f"/{competitor_source}"
|
|
607
|
-
return self.fetch(url)
|
|
601
|
+
return CompetitorResponse.model_validate(self.fetch(url))
|
|
608
602
|
|
|
609
603
|
def fetch_mergers_for_company(
|
|
610
604
|
self,
|