kensho-kfinance 1.2.0__tar.gz → 2.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.

Files changed (70) hide show
  1. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/.gitignore +4 -0
  2. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/PKG-INFO +13 -9
  3. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/README.md +1 -1
  4. kensho_kfinance-2.0.0/docs/build_tool_calling_documentation.py +123 -0
  5. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/docs/conf.py +11 -5
  6. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/docs/index.rst +2 -1
  7. kensho_kfinance-2.0.0/docs/tool_calling.rst +17 -0
  8. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/justfile +1 -1
  9. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kensho_kfinance.egg-info/PKG-INFO +13 -9
  10. kensho_kfinance-2.0.0/kensho_kfinance.egg-info/SOURCES.txt +64 -0
  11. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kensho_kfinance.egg-info/requires.txt +11 -7
  12. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kfinance/CHANGELOG.md +10 -0
  13. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kfinance/constants.py +51 -8
  14. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kfinance/fetch.py +68 -29
  15. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kfinance/kfinance.py +128 -38
  16. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kfinance/meta_classes.py +3 -9
  17. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kfinance/tests/test_fetch.py +7 -26
  18. kensho_kfinance-2.0.0/kfinance/tests/test_tools.py +430 -0
  19. kensho_kfinance-2.0.0/kfinance/tool_calling/README.md +38 -0
  20. kensho_kfinance-2.0.0/kfinance/tool_calling/__init__.py +47 -0
  21. kensho_kfinance-2.0.0/kfinance/tool_calling/get_business_relationship_from_identifier.py +28 -0
  22. kensho_kfinance-2.0.0/kfinance/tool_calling/get_capitalization_from_identifier.py +35 -0
  23. kensho_kfinance-2.0.0/kfinance/tool_calling/get_company_id_from_identifier.py +14 -0
  24. kensho_kfinance-2.0.0/kfinance/tool_calling/get_cusip_from_ticker.py +18 -0
  25. kensho_kfinance-2.0.0/kfinance/tool_calling/get_earnings_call_datetimes_from_identifier.py +17 -0
  26. kensho_kfinance-2.0.0/kfinance/tool_calling/get_financial_line_item_from_identifier.py +45 -0
  27. kensho_kfinance-2.0.0/kfinance/tool_calling/get_financial_statement_from_identifier.py +41 -0
  28. kensho_kfinance-2.0.0/kfinance/tool_calling/get_history_metadata_from_identifier.py +15 -0
  29. kensho_kfinance-2.0.0/kfinance/tool_calling/get_info_from_identifier.py +14 -0
  30. kensho_kfinance-2.0.0/kfinance/tool_calling/get_isin_from_ticker.py +18 -0
  31. kensho_kfinance-2.0.0/kfinance/tool_calling/get_latest.py +21 -0
  32. kensho_kfinance-2.0.0/kfinance/tool_calling/get_n_quarters_ago.py +21 -0
  33. kensho_kfinance-2.0.0/kfinance/tool_calling/get_prices_from_identifier.py +44 -0
  34. kensho_kfinance-2.0.0/kfinance/tool_calling/get_security_id_from_identifier.py +14 -0
  35. kensho_kfinance-2.0.0/kfinance/tool_calling/get_trading_item_id_from_identifier.py +14 -0
  36. kensho_kfinance-2.0.0/kfinance/tool_calling/shared_models.py +53 -0
  37. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kfinance/version.py +2 -2
  38. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/pyproject.toml +13 -7
  39. kensho_kfinance-1.2.0/docs/llm_tools.rst +0 -7
  40. kensho_kfinance-1.2.0/kensho_kfinance.egg-info/SOURCES.txt +0 -46
  41. kensho_kfinance-1.2.0/kfinance/llm_tools.py +0 -747
  42. kensho_kfinance-1.2.0/kfinance/tool_schemas.py +0 -148
  43. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/.coveragerc +0 -0
  44. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/.github/workflows/ci-lint.yml +0 -0
  45. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/.github/workflows/ci-test.yml +0 -0
  46. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/.github/workflows/python-publish.yml +0 -0
  47. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/.readthedocs.yaml +0 -0
  48. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/AUTHORS.md +0 -0
  49. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/CODE_OF_CONDUCT.md +0 -0
  50. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/CONTRIBUTING.md +0 -0
  51. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/LICENSE +0 -0
  52. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/docs/kfinance.rst +0 -0
  53. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/docs/requirements.txt +0 -0
  54. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/docs/templates/apidoc/package.rst_t +0 -0
  55. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/docs/templates/apidoc/toc.rst_t +0 -0
  56. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kensho_kfinance.egg-info/dependency_links.txt +0 -0
  57. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kensho_kfinance.egg-info/top_level.txt +0 -0
  58. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kfinance/__init__.py +0 -0
  59. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kfinance/batch_request_handling.py +0 -0
  60. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kfinance/prompt.py +0 -0
  61. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kfinance/py.typed +0 -0
  62. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kfinance/server_thread.py +0 -0
  63. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kfinance/tests/__init__.py +0 -0
  64. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kfinance/tests/test_batch_requests.py +0 -0
  65. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/kfinance/tests/test_objects.py +0 -0
  66. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/scripts/copyright_line_check.sh +0 -0
  67. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/scripts/lint.sh +0 -0
  68. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/scripts/test.sh +0 -0
  69. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/setup.cfg +0 -0
  70. {kensho_kfinance-1.2.0 → kensho_kfinance-2.0.0}/setup.py +0 -0
@@ -100,3 +100,7 @@ dmypy.json
100
100
 
101
101
 
102
102
  kfinance/version.py
103
+ kfinance/wrappers/
104
+
105
+ docs/output/
106
+ docs/generated/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kensho-kfinance
3
- Version: 1.2.0
3
+ Version: 2.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
@@ -12,30 +12,34 @@ Requires-Python: >=3.10
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  License-File: AUTHORS.md
15
- Requires-Dist: python-dateutil<2.9,>=2.8.2
16
- Requires-Dist: requests<3,>=2.22.0
17
- Requires-Dist: urllib3>=1.21.1
18
- Requires-Dist: pyjwt>=2.8.0
15
+ Requires-Dist: langchain-core>=0.3.15
16
+ Requires-Dist: langchain-google-genai<3,>=2.1.0
19
17
  Requires-Dist: numpy>=1.22.4
20
18
  Requires-Dist: pandas>=2.0.0
21
- Requires-Dist: types-requests<3,>=2.22.0
22
19
  Requires-Dist: pillow>=10
23
- Requires-Dist: langchain-core>=0.3.15
20
+ Requires-Dist: pydantic<3,>=2.10.0
21
+ Requires-Dist: pyjwt>=2.8.0
22
+ Requires-Dist: python-dateutil<2.9,>=2.8.2
24
23
  Requires-Dist: strenum>=0.4.15
24
+ Requires-Dist: tabulate>=0.9.0
25
+ Requires-Dist: types-requests<3,>=2.22.0
26
+ Requires-Dist: requests<3,>=2.22.0
27
+ Requires-Dist: urllib3>=1.21.1
25
28
  Provides-Extra: dev
26
29
  Requires-Dist: coverage<8,>=7.6.10; extra == "dev"
27
30
  Requires-Dist: mypy<2,>=1.15.0; extra == "dev"
28
31
  Requires-Dist: pytest<7,>=6.1.2; extra == "dev"
29
32
  Requires-Dist: pytest-cov<7,>=6.0.0; extra == "dev"
33
+ Requires-Dist: requests_mock<2,>=1.12; extra == "dev"
30
34
  Requires-Dist: ruff<1,>=0.9.4; extra == "dev"
31
- Requires-Dist: requests_mock<1.2,>=1.1; extra == "dev"
35
+ Requires-Dist: time_machine<3,>=2.1; extra == "dev"
32
36
  Dynamic: license-file
33
37
 
34
38
  # kFinance
35
39
 
36
40
  The kFinance Python library provides a simple interface for the LLM-ready API, streamlining API requests and response handling. It can be used on its own, with LLMs, or integrated into applications.
37
41
 
38
- For a complete overview of the functions, usage, and features of the kFinance Python library, please refer to documentation [here](https://kfinance.kensho.com/docs).
42
+ For a complete overview of the functions, usage, and features of the kFinance Python library, please refer to documentation [here](https://kensho-kfinance.readthedocs.io/en/stable/).
39
43
 
40
44
  Any questions or suggestions can be sent to the [kFinance Maintainers](kfinance-maintainers@kensho.com).
41
45
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  The kFinance Python library provides a simple interface for the LLM-ready API, streamlining API requests and response handling. It can be used on its own, with LLMs, or integrated into applications.
4
4
 
5
- For a complete overview of the functions, usage, and features of the kFinance Python library, please refer to documentation [here](https://kfinance.kensho.com/docs).
5
+ For a complete overview of the functions, usage, and features of the kFinance Python library, please refer to documentation [here](https://kensho-kfinance.readthedocs.io/en/stable/).
6
6
 
7
7
  Any questions or suggestions can be sent to the [kFinance Maintainers](kfinance-maintainers@kensho.com).
8
8
 
@@ -0,0 +1,123 @@
1
+ import inspect
2
+ from enum import Enum
3
+ from pathlib import Path
4
+
5
+ from langchain_core.utils.function_calling import convert_to_openai_tool
6
+ from pydantic._internal._repr import display_as_type
7
+
8
+ from kfinance.kfinance import Client
9
+ from kfinance.tool_calling import ALL_TOOLS, KfinanceTool
10
+
11
+
12
+ def add_tool_calling_docs_for_all_tools() -> None:
13
+ """Add tool calling documentation for all tools.
14
+
15
+ Adding tool calling documentation involves two steps:
16
+ - Add a function definition to the tool file
17
+ - Add the module to tool_calling.rst to instruct sphinx what tool functions to document.
18
+
19
+ Do not commit changes that result from executing this function.
20
+ """
21
+
22
+ for tool_cls in ALL_TOOLS:
23
+ tool = tool_cls(kfinance_client=Client(refresh_token="fake"))
24
+ add_function_to_tools_file(tool)
25
+ add_module_to_tool_calling_rst(tool)
26
+
27
+
28
+ def add_function_to_tools_file(tool: KfinanceTool) -> None:
29
+ """Add a function definition to each tool file, which mimics the tool definition passed to LLMs
30
+
31
+ The KfinanceTools are primarily intended to be transpiled for use with langchain, openai,
32
+ anthropic etc. However, the automatically generated documentation is not very helpful.
33
+ Instead, we use the tool definition to create a function definition that's close to what we
34
+ pass to the LLM. We then use sphinx to generate docs only for these generated functions.
35
+
36
+ We append the function definition to the same file as the tool. This ensures that the
37
+ [source] field in the documentation links to the file where the tool is defined.
38
+
39
+ Here's an example from the `GetNQuartersAgo` tool:
40
+
41
+ def get_n_quarters_ago(n: int) -> kfinance.constants.YearAndQuarter:
42
+ '''Get the year and quarter corresponding to [n] quarters before the current quarter.
43
+
44
+ :param n: Number of quarters before the current quarter
45
+ :type n: int
46
+ :rtype: YearAndQuarter'''
47
+
48
+ """
49
+
50
+ # The signature built with the inspect module does not include necessary imports.
51
+ imports = [
52
+ "import kfinance",
53
+ "import datetime",
54
+ "from typing import Optional"
55
+ ]
56
+ signature_str = build_signature_str(tool)
57
+
58
+ # Use inspect to retrieve the return type and add it to the imports if it's not a builtin.
59
+ return_annotation = inspect.signature(tool._run).return_annotation
60
+ if return_annotation.__module__ != "builtins":
61
+ imports.append(f"from {return_annotation.__module__} import {return_annotation.__name__}")
62
+
63
+ # Generate sphinx style annotations for each param.
64
+ openai_params = convert_to_openai_tool(tool)["function"]["parameters"]["properties"]
65
+ args = ""
66
+ for field_name, field_metadata in tool.args_schema.model_fields.items():
67
+ # We use the openai definition to extract the field description. This means that, just like
68
+ # pydantic/langchain, we use the docstring of an enum as the description for an enum field.
69
+ try:
70
+ openai_params[field_name]['description']
71
+ except:
72
+ assert False, tool.name
73
+ args += f"\n :param {field_name}: {openai_params[field_name]['description']}"
74
+ args += f"\n :type {field_name}: {display_as_type(field_metadata.annotation)}"
75
+
76
+ func_str = "\n" + "\n".join(imports) + "\n"
77
+ func_str += f"{signature_str}"
78
+ func_str += f'\n """{tool.description}\n'
79
+ func_str += args
80
+ # Add sphinx style return annotation
81
+ func_str += f'\n :rtype: {return_annotation.__name__}"""'
82
+
83
+ # Write definition to tool file
84
+ with open(inspect.getfile(tool.__class__), mode="a") as f:
85
+ f.write(func_str)
86
+
87
+ def build_signature_str(tool) -> str:
88
+ """Return the signature string of the tool
89
+
90
+ Return value example:
91
+ def get_latest(use_local_timezone: bool = True) -> kfinance.constants.LatestPeriods:
92
+
93
+ This function is mostly necessary for proper enum handling.
94
+ inspect.Parameter uses __repr__ to stringify enum default values, not __str__.
95
+ As a result, it formats default values as "<Periodicity.day: 'day'>" rather than
96
+ "Periodicity.day".
97
+ """
98
+ signature = inspect.signature(tool._run)
99
+
100
+ for param in signature.parameters.values():
101
+ if isinstance(param.default, Enum):
102
+ # For enums, redirect __repr__ to __str__
103
+ param.default.__class__.__repr__ = param.default.__class__.__str__
104
+ return f"def {tool.name}{signature}:"
105
+
106
+
107
+
108
+ def add_module_to_tool_calling_rst(tool: KfinanceTool) -> None:
109
+ """Add a module for each tool to tool_calling.rst.
110
+
111
+ We only want to include the generated function in the docs.
112
+
113
+ Example:
114
+ .. automodule:: kfinance.tool_calling.get_latest
115
+ :members: get_latest
116
+ """
117
+
118
+ module_str = "\n"
119
+ module_str += f"\n.. automodule:: {tool.__module__}"
120
+ module_str += f"\n :members: {tool.name}"
121
+
122
+ with open(Path(Path(__file__).resolve().parent, "tool_calling.rst"), mode="a") as f:
123
+ f.write(module_str)
@@ -7,15 +7,21 @@
7
7
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8
8
  from importlib.metadata import version as get_version
9
9
 
10
- project = 'kensho-kfinance'
11
- copyright = '2025, Kensho Technologies'
12
- author = 'Kensho Technologies'
10
+ from docs.build_tool_calling_documentation import add_tool_calling_docs_for_all_tools
11
+
12
+
13
+ project = "kensho-kfinance"
14
+ copyright = "2025, Kensho Technologies"
15
+ author = "Kensho Technologies"
16
+
17
+ # Add documentation for tool calling.
18
+ add_tool_calling_docs_for_all_tools()
13
19
 
14
20
  # borrowed from here:
15
21
  # https://setuptools-scm.readthedocs.io/en/latest/usage/#usage-from-sphinx
16
22
  release: str = get_version(project)
17
23
  # for example take major/minor
18
- version: str = ".".join(release.split('.')[:2])
24
+ version: str = ".".join(release.split(".")[:2])
19
25
 
20
26
  # -- General configuration ---------------------------------------------------
21
27
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
@@ -57,7 +63,7 @@ source_suffix = [".rst", ".md"]
57
63
  # -- Options for HTML output -------------------------------------------------
58
64
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
59
65
 
60
- html_theme = 'sphinx_rtd_theme'
66
+ html_theme = "sphinx_rtd_theme"
61
67
 
62
68
  # https://sphinx-rtd-theme.readthedocs.io/en/stable/configuring.html
63
69
  html_theme_options = {"body_min_width": 0, "body_max_width": "none"}
@@ -9,7 +9,8 @@ Documentation page for kensho-kfinance library.
9
9
  :maxdepth: 1
10
10
 
11
11
  kfinance <kfinance>
12
- llm_tools <llm_tools>
12
+ tool_calling <tool_calling>
13
+
13
14
 
14
15
  Indices and tables
15
16
  ==================
@@ -0,0 +1,17 @@
1
+ Tool Calling
2
+ ============
3
+
4
+ Below, you can find all the tools that are available for tool calling.
5
+
6
+ For examples on how to call these tools via OpenAI, Anthropic, or Gemini, see the
7
+ `LLM-ready API examples. <https://github.com/kensho-technologies/llm-ready-api-examples>`_
8
+
9
+ Note: The tool definitions below cannot be called directly and are intended for documentation only.
10
+ They are auto-generated from langchain
11
+ `BaseTools. <https://api.python.langchain.com/en/latest/tools/langchain_core.tools.BaseTool.html>`_
12
+ To see the BaseTool behind a function definition, click on the source of the definition.
13
+
14
+ .. The contents of tool_calling.rst get auto-generated by
15
+ .. build_tool_calling_documentation.py. Don't commit any content below
16
+ .. this comment.
17
+
@@ -34,4 +34,4 @@ unit-test *args:
34
34
  # First, copy the dependencies in docs/requirements.txt into pyproject.toml and install in a venv.
35
35
  # Don't merge changes to pyproject and docs/output into the remote repo!
36
36
  sphinx *args:
37
- sphinx-build docs docs/output
37
+ PYTHONPATH="${PYTHONPATH:-}:." sphinx-build docs docs/output
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kensho-kfinance
3
- Version: 1.2.0
3
+ Version: 2.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
@@ -12,30 +12,34 @@ Requires-Python: >=3.10
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  License-File: AUTHORS.md
15
- Requires-Dist: python-dateutil<2.9,>=2.8.2
16
- Requires-Dist: requests<3,>=2.22.0
17
- Requires-Dist: urllib3>=1.21.1
18
- Requires-Dist: pyjwt>=2.8.0
15
+ Requires-Dist: langchain-core>=0.3.15
16
+ Requires-Dist: langchain-google-genai<3,>=2.1.0
19
17
  Requires-Dist: numpy>=1.22.4
20
18
  Requires-Dist: pandas>=2.0.0
21
- Requires-Dist: types-requests<3,>=2.22.0
22
19
  Requires-Dist: pillow>=10
23
- Requires-Dist: langchain-core>=0.3.15
20
+ Requires-Dist: pydantic<3,>=2.10.0
21
+ Requires-Dist: pyjwt>=2.8.0
22
+ Requires-Dist: python-dateutil<2.9,>=2.8.2
24
23
  Requires-Dist: strenum>=0.4.15
24
+ Requires-Dist: tabulate>=0.9.0
25
+ Requires-Dist: types-requests<3,>=2.22.0
26
+ Requires-Dist: requests<3,>=2.22.0
27
+ Requires-Dist: urllib3>=1.21.1
25
28
  Provides-Extra: dev
26
29
  Requires-Dist: coverage<8,>=7.6.10; extra == "dev"
27
30
  Requires-Dist: mypy<2,>=1.15.0; extra == "dev"
28
31
  Requires-Dist: pytest<7,>=6.1.2; extra == "dev"
29
32
  Requires-Dist: pytest-cov<7,>=6.0.0; extra == "dev"
33
+ Requires-Dist: requests_mock<2,>=1.12; extra == "dev"
30
34
  Requires-Dist: ruff<1,>=0.9.4; extra == "dev"
31
- Requires-Dist: requests_mock<1.2,>=1.1; extra == "dev"
35
+ Requires-Dist: time_machine<3,>=2.1; extra == "dev"
32
36
  Dynamic: license-file
33
37
 
34
38
  # kFinance
35
39
 
36
40
  The kFinance Python library provides a simple interface for the LLM-ready API, streamlining API requests and response handling. It can be used on its own, with LLMs, or integrated into applications.
37
41
 
38
- For a complete overview of the functions, usage, and features of the kFinance Python library, please refer to documentation [here](https://kfinance.kensho.com/docs).
42
+ For a complete overview of the functions, usage, and features of the kFinance Python library, please refer to documentation [here](https://kensho-kfinance.readthedocs.io/en/stable/).
39
43
 
40
44
  Any questions or suggestions can be sent to the [kFinance Maintainers](kfinance-maintainers@kensho.com).
41
45
 
@@ -0,0 +1,64 @@
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
+ kensho_kfinance.egg-info/PKG-INFO
24
+ kensho_kfinance.egg-info/SOURCES.txt
25
+ kensho_kfinance.egg-info/dependency_links.txt
26
+ kensho_kfinance.egg-info/requires.txt
27
+ kensho_kfinance.egg-info/top_level.txt
28
+ kfinance/CHANGELOG.md
29
+ kfinance/__init__.py
30
+ kfinance/batch_request_handling.py
31
+ kfinance/constants.py
32
+ kfinance/fetch.py
33
+ kfinance/kfinance.py
34
+ kfinance/meta_classes.py
35
+ kfinance/prompt.py
36
+ kfinance/py.typed
37
+ kfinance/server_thread.py
38
+ kfinance/version.py
39
+ kfinance/tests/__init__.py
40
+ kfinance/tests/test_batch_requests.py
41
+ kfinance/tests/test_fetch.py
42
+ kfinance/tests/test_objects.py
43
+ kfinance/tests/test_tools.py
44
+ kfinance/tool_calling/README.md
45
+ kfinance/tool_calling/__init__.py
46
+ kfinance/tool_calling/get_business_relationship_from_identifier.py
47
+ kfinance/tool_calling/get_capitalization_from_identifier.py
48
+ kfinance/tool_calling/get_company_id_from_identifier.py
49
+ kfinance/tool_calling/get_cusip_from_ticker.py
50
+ kfinance/tool_calling/get_earnings_call_datetimes_from_identifier.py
51
+ kfinance/tool_calling/get_financial_line_item_from_identifier.py
52
+ kfinance/tool_calling/get_financial_statement_from_identifier.py
53
+ kfinance/tool_calling/get_history_metadata_from_identifier.py
54
+ kfinance/tool_calling/get_info_from_identifier.py
55
+ kfinance/tool_calling/get_isin_from_ticker.py
56
+ kfinance/tool_calling/get_latest.py
57
+ kfinance/tool_calling/get_n_quarters_ago.py
58
+ kfinance/tool_calling/get_prices_from_identifier.py
59
+ kfinance/tool_calling/get_security_id_from_identifier.py
60
+ kfinance/tool_calling/get_trading_item_id_from_identifier.py
61
+ kfinance/tool_calling/shared_models.py
62
+ scripts/copyright_line_check.sh
63
+ scripts/lint.sh
64
+ scripts/test.sh
@@ -1,18 +1,22 @@
1
- python-dateutil<2.9,>=2.8.2
2
- requests<3,>=2.22.0
3
- urllib3>=1.21.1
4
- pyjwt>=2.8.0
1
+ langchain-core>=0.3.15
2
+ langchain-google-genai<3,>=2.1.0
5
3
  numpy>=1.22.4
6
4
  pandas>=2.0.0
7
- types-requests<3,>=2.22.0
8
5
  pillow>=10
9
- langchain-core>=0.3.15
6
+ pydantic<3,>=2.10.0
7
+ pyjwt>=2.8.0
8
+ python-dateutil<2.9,>=2.8.2
10
9
  strenum>=0.4.15
10
+ tabulate>=0.9.0
11
+ types-requests<3,>=2.22.0
12
+ requests<3,>=2.22.0
13
+ urllib3>=1.21.1
11
14
 
12
15
  [dev]
13
16
  coverage<8,>=7.6.10
14
17
  mypy<2,>=1.15.0
15
18
  pytest<7,>=6.1.2
16
19
  pytest-cov<7,>=6.0.0
20
+ requests_mock<2,>=1.12
17
21
  ruff<1,>=0.9.4
18
- requests_mock<1.2,>=1.1
22
+ time_machine<3,>=2.1
@@ -1,4 +1,14 @@
1
1
  # Changelog
2
+
3
+ ## v2.0.0
4
+ - Refactor llm tools to use langchain `BaseTool`.
5
+
6
+ ## v1.2.2
7
+ - Add tabulate and pydantic as dependencies
8
+
9
+ ## v1.2.1
10
+ - Add fetch for industry_code, industry_classification and gics_code.
11
+
2
12
  ## v1.2.0
3
13
  - Add batch requests for iterable classes
4
14
 
@@ -1,4 +1,5 @@
1
1
  from datetime import date
2
+ from enum import Enum
2
3
  from itertools import chain
3
4
  from typing import TypedDict
4
5
 
@@ -26,7 +27,45 @@ class IdentificationTriple(TypedDict):
26
27
  company_id: int
27
28
 
28
29
 
30
+ class Capitalization(Enum):
31
+ """The capitalization type"""
32
+
33
+ market_cap = "market_cap"
34
+ tev = "tev"
35
+ shares_outstanding = "shares_outstanding"
36
+
37
+
38
+ class PeriodType(Enum):
39
+ """The period type"""
40
+
41
+ annual = "annual"
42
+ quarterly = "quarterly"
43
+ ltm = "ltm"
44
+ ytd = "ytd"
45
+
46
+
47
+ class Periodicity(Enum):
48
+ """The frequency or interval at which the historical data points are sampled or aggregated. Periodicity is not the same as the date range. The date range specifies the time span over which the data is retrieved, while periodicity determines how the data within that date range is aggregated."""
49
+
50
+ day = "day"
51
+ week = "week"
52
+ month = "month"
53
+ year = "year"
54
+
55
+
56
+ class StatementType(Enum):
57
+ """The type of financial statement"""
58
+
59
+ balance_sheet = "balance_sheet"
60
+ bs = "balance_sheet"
61
+ income_statement = "income_statement"
62
+ cashflow = "cashflow"
63
+ cf = "cashflow"
64
+
65
+
29
66
  class BusinessRelationshipType(StrEnum):
67
+ """The type of business relationship"""
68
+
30
69
  supplier = "supplier"
31
70
  customer = "customer"
32
71
  distributor = "distributor"
@@ -76,6 +115,17 @@ class LatestPeriods(TypedDict):
76
115
  now: CurrentPeriod
77
116
 
78
117
 
118
+ class IndustryClassification(StrEnum):
119
+ sic = "sic"
120
+ naics = "naics"
121
+ nace = "nace"
122
+ anzsic = "anzsic"
123
+ spcapiqetf = "spcapiqetf"
124
+ spratings = "spratings"
125
+ gics = "gics"
126
+ simple = "simple"
127
+
128
+
79
129
  # all of these values must be lower case keys
80
130
  LINE_ITEMS: list[LineItemType] = [
81
131
  {
@@ -1661,18 +1711,11 @@ LINE_ITEMS: list[LineItemType] = [
1661
1711
  },
1662
1712
  ]
1663
1713
 
1664
- LINE_ITEMS_TO_DATA_ITEM_ID = {
1665
- line_item["name"]: line_item["dataitemid"] for line_item in LINE_ITEMS
1666
- }
1667
1714
 
1668
- LINE_ITEM_NAMES_AND_ALIASES = list(
1715
+ LINE_ITEM_NAMES_AND_ALIASES: list[str] = list(
1669
1716
  chain(*[[line_item["name"]] + list(line_item["aliases"]) for line_item in LINE_ITEMS])
1670
1717
  )
1671
1718
 
1672
- LINE_ITEM_SYNONYMS = {
1673
- alias: line_item["dataitemid"] for line_item in LINE_ITEMS for alias in line_item["aliases"]
1674
- }
1675
-
1676
1719
 
1677
1720
  FINANCIAL_STATEMENTS: dict[str, int] = {
1678
1721
  "income_statement": 1,