kensho-kfinance 1.2.2__tar.gz → 2.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

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.2 → kensho_kfinance-2.0.1}/.gitignore +4 -0
  2. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/.readthedocs.yaml +6 -4
  3. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/PKG-INFO +5 -3
  4. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/README.md +1 -1
  5. kensho_kfinance-2.0.1/docs/build_tool_calling_documentation.py +118 -0
  6. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/docs/conf.py +6 -6
  7. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/docs/index.rst +2 -1
  8. kensho_kfinance-2.0.1/docs/tool_calling.rst +17 -0
  9. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/justfile +1 -1
  10. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kensho_kfinance.egg-info/PKG-INFO +5 -3
  11. kensho_kfinance-2.0.1/kensho_kfinance.egg-info/SOURCES.txt +64 -0
  12. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kensho_kfinance.egg-info/requires.txt +3 -1
  13. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kfinance/CHANGELOG.md +6 -0
  14. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kfinance/constants.py +40 -8
  15. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kfinance/fetch.py +15 -9
  16. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kfinance/kfinance.py +128 -38
  17. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kfinance/meta_classes.py +3 -9
  18. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kfinance/tests/test_fetch.py +7 -6
  19. kensho_kfinance-2.0.1/kfinance/tests/test_tools.py +430 -0
  20. kensho_kfinance-2.0.1/kfinance/tool_calling/README.md +38 -0
  21. kensho_kfinance-2.0.1/kfinance/tool_calling/__init__.py +47 -0
  22. kensho_kfinance-2.0.1/kfinance/tool_calling/get_business_relationship_from_identifier.py +28 -0
  23. kensho_kfinance-2.0.1/kfinance/tool_calling/get_capitalization_from_identifier.py +35 -0
  24. kensho_kfinance-2.0.1/kfinance/tool_calling/get_company_id_from_identifier.py +14 -0
  25. kensho_kfinance-2.0.1/kfinance/tool_calling/get_cusip_from_ticker.py +18 -0
  26. kensho_kfinance-2.0.1/kfinance/tool_calling/get_earnings_call_datetimes_from_identifier.py +17 -0
  27. kensho_kfinance-2.0.1/kfinance/tool_calling/get_financial_line_item_from_identifier.py +45 -0
  28. kensho_kfinance-2.0.1/kfinance/tool_calling/get_financial_statement_from_identifier.py +41 -0
  29. kensho_kfinance-2.0.1/kfinance/tool_calling/get_history_metadata_from_identifier.py +15 -0
  30. kensho_kfinance-2.0.1/kfinance/tool_calling/get_info_from_identifier.py +14 -0
  31. kensho_kfinance-2.0.1/kfinance/tool_calling/get_isin_from_ticker.py +18 -0
  32. kensho_kfinance-2.0.1/kfinance/tool_calling/get_latest.py +21 -0
  33. kensho_kfinance-2.0.1/kfinance/tool_calling/get_n_quarters_ago.py +21 -0
  34. kensho_kfinance-2.0.1/kfinance/tool_calling/get_prices_from_identifier.py +44 -0
  35. kensho_kfinance-2.0.1/kfinance/tool_calling/get_security_id_from_identifier.py +14 -0
  36. kensho_kfinance-2.0.1/kfinance/tool_calling/get_trading_item_id_from_identifier.py +14 -0
  37. kensho_kfinance-2.0.1/kfinance/tool_calling/shared_models.py +53 -0
  38. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kfinance/version.py +2 -2
  39. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/pyproject.toml +4 -1
  40. kensho_kfinance-1.2.2/docs/llm_tools.rst +0 -7
  41. kensho_kfinance-1.2.2/kensho_kfinance.egg-info/SOURCES.txt +0 -46
  42. kensho_kfinance-1.2.2/kfinance/llm_tools.py +0 -747
  43. kensho_kfinance-1.2.2/kfinance/tool_schemas.py +0 -148
  44. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/.coveragerc +0 -0
  45. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/.github/workflows/ci-lint.yml +0 -0
  46. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/.github/workflows/ci-test.yml +0 -0
  47. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/.github/workflows/python-publish.yml +0 -0
  48. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/AUTHORS.md +0 -0
  49. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/CODE_OF_CONDUCT.md +0 -0
  50. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/CONTRIBUTING.md +0 -0
  51. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/LICENSE +0 -0
  52. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/docs/kfinance.rst +0 -0
  53. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/docs/requirements.txt +0 -0
  54. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/docs/templates/apidoc/package.rst_t +0 -0
  55. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/docs/templates/apidoc/toc.rst_t +0 -0
  56. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kensho_kfinance.egg-info/dependency_links.txt +0 -0
  57. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kensho_kfinance.egg-info/top_level.txt +0 -0
  58. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kfinance/__init__.py +0 -0
  59. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kfinance/batch_request_handling.py +0 -0
  60. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kfinance/prompt.py +0 -0
  61. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kfinance/py.typed +0 -0
  62. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kfinance/server_thread.py +0 -0
  63. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kfinance/tests/__init__.py +0 -0
  64. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kfinance/tests/test_batch_requests.py +0 -0
  65. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/kfinance/tests/test_objects.py +0 -0
  66. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/scripts/copyright_line_check.sh +0 -0
  67. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/scripts/lint.sh +0 -0
  68. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/scripts/test.sh +0 -0
  69. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/setup.cfg +0 -0
  70. {kensho_kfinance-1.2.2 → kensho_kfinance-2.0.1}/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/
@@ -3,13 +3,15 @@ build:
3
3
  os: ubuntu-22.04
4
4
  tools:
5
5
  python: "3.10"
6
- # You can also specify other tool versions:
7
- # nodejs: "16"
8
- # borrowed from here:
9
- # https://docs.readthedocs.com/platform/stable/build-customization.html#avoid-having-a-dirty-git-index
10
6
  jobs:
11
7
  pre_install:
8
+ # borrowed from here:
9
+ # https://docs.readthedocs.com/platform/stable/build-customization.html#avoid-having-a-dirty-git-index
12
10
  - git update-index --assume-unchanged docs/conf.py
11
+ pre_build:
12
+ # build documentation for tool calling before generating docs.
13
+ - pip install langchain-core
14
+ - python docs/build_tool_calling_documentation.py
13
15
 
14
16
  # Build documentation in the docs/ directory with Sphinx
15
17
  sphinx:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kensho-kfinance
3
- Version: 1.2.2
3
+ Version: 2.0.1
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
@@ -13,6 +13,7 @@ Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  License-File: AUTHORS.md
15
15
  Requires-Dist: langchain-core>=0.3.15
16
+ Requires-Dist: langchain-google-genai<3,>=2.1.0
16
17
  Requires-Dist: numpy>=1.22.4
17
18
  Requires-Dist: pandas>=2.0.0
18
19
  Requires-Dist: pillow>=10
@@ -29,15 +30,16 @@ Requires-Dist: coverage<8,>=7.6.10; extra == "dev"
29
30
  Requires-Dist: mypy<2,>=1.15.0; extra == "dev"
30
31
  Requires-Dist: pytest<7,>=6.1.2; extra == "dev"
31
32
  Requires-Dist: pytest-cov<7,>=6.0.0; extra == "dev"
32
- Requires-Dist: requests_mock<1.2,>=1.1; extra == "dev"
33
+ Requires-Dist: requests_mock<2,>=1.12; extra == "dev"
33
34
  Requires-Dist: ruff<1,>=0.9.4; extra == "dev"
35
+ Requires-Dist: time_machine<3,>=2.1; extra == "dev"
34
36
  Dynamic: license-file
35
37
 
36
38
  # kFinance
37
39
 
38
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.
39
41
 
40
- 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/).
41
43
 
42
44
  Any questions or suggestions can be sent to the [kFinance Maintainers](kfinance-maintainers@kensho.com).
43
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,118 @@
1
+ from enum import Enum
2
+ import inspect
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 = ["import kfinance", "import datetime", "from typing import Optional"]
52
+ signature_str = build_signature_str(tool)
53
+
54
+ # Use inspect to retrieve the return type and add it to the imports if it's not a builtin.
55
+ return_annotation = inspect.signature(tool._run).return_annotation
56
+ if return_annotation.__module__ != "builtins":
57
+ imports.append(f"from {return_annotation.__module__} import {return_annotation.__name__}")
58
+
59
+ # Generate sphinx style annotations for each param.
60
+ openai_params = convert_to_openai_tool(tool)["function"]["parameters"]["properties"]
61
+ args = ""
62
+ for field_name, field_metadata in tool.args_schema.model_fields.items():
63
+ # We use the openai definition to extract the field description. This means that, just like
64
+ # pydantic/langchain, we use the docstring of an enum as the description for an enum field.
65
+ args += f"\n :param {field_name}: {openai_params[field_name]['description']}"
66
+ args += f"\n :type {field_name}: {display_as_type(field_metadata.annotation)}"
67
+
68
+ func_str = "\n" + "\n".join(imports) + "\n"
69
+ func_str += f"{signature_str}"
70
+ func_str += f'\n """{tool.description}\n'
71
+ func_str += args
72
+ # Add sphinx style return annotation
73
+ func_str += f'\n :rtype: {return_annotation.__name__}"""'
74
+
75
+ # Write definition to tool file
76
+ with open(inspect.getfile(tool.__class__), mode="a") as f:
77
+ f.write(func_str)
78
+
79
+
80
+ def build_signature_str(tool: KfinanceTool) -> str:
81
+ """Return the signature string of the tool
82
+
83
+ Return value example:
84
+ def get_latest(use_local_timezone: bool = True) -> kfinance.constants.LatestPeriods:
85
+
86
+ This function is mostly necessary for proper enum handling.
87
+ inspect.Parameter uses __repr__ to stringify enum default values, not __str__.
88
+ As a result, it formats default values as "<Periodicity.day: 'day'>" rather than
89
+ "Periodicity.day".
90
+ """
91
+ signature = inspect.signature(tool._run)
92
+
93
+ for param in signature.parameters.values():
94
+ if isinstance(param.default, Enum):
95
+ # For enums, redirect __repr__ to __str__
96
+ param.default.__class__.__repr__ = param.default.__class__.__str__
97
+ return f"def {tool.name}{signature}:"
98
+
99
+
100
+ def add_module_to_tool_calling_rst(tool: KfinanceTool) -> None:
101
+ """Add a module for each tool to tool_calling.rst.
102
+
103
+ We only want to include the generated function in the docs.
104
+
105
+ Example:
106
+ .. automodule:: kfinance.tool_calling.get_latest
107
+ :members: get_latest
108
+ """
109
+
110
+ module_str = "\n"
111
+ module_str += f"\n.. automodule:: {tool.__module__}"
112
+ module_str += f"\n :members: {tool.name}"
113
+
114
+ with open(Path(Path(__file__).resolve().parent, "tool_calling.rst"), mode="a") as f:
115
+ f.write(module_str)
116
+
117
+ if __name__ == "__main__":
118
+ add_tool_calling_docs_for_all_tools()
@@ -7,15 +7,16 @@
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
+ project = "kensho-kfinance"
11
+ copyright = "2025, Kensho Technologies"
12
+ author = "Kensho Technologies"
13
+
13
14
 
14
15
  # borrowed from here:
15
16
  # https://setuptools-scm.readthedocs.io/en/latest/usage/#usage-from-sphinx
16
17
  release: str = get_version(project)
17
18
  # for example take major/minor
18
- version: str = ".".join(release.split('.')[:2])
19
+ version: str = ".".join(release.split(".")[:2])
19
20
 
20
21
  # -- General configuration ---------------------------------------------------
21
22
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
@@ -53,11 +54,10 @@ templates_path = ["templates"]
53
54
  source_suffix = [".rst", ".md"]
54
55
 
55
56
 
56
-
57
57
  # -- Options for HTML output -------------------------------------------------
58
58
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
59
59
 
60
- html_theme = 'sphinx_rtd_theme'
60
+ html_theme = "sphinx_rtd_theme"
61
61
 
62
62
  # https://sphinx-rtd-theme.readthedocs.io/en/stable/configuring.html
63
63
  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.2
3
+ Version: 2.0.1
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
@@ -13,6 +13,7 @@ Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  License-File: AUTHORS.md
15
15
  Requires-Dist: langchain-core>=0.3.15
16
+ Requires-Dist: langchain-google-genai<3,>=2.1.0
16
17
  Requires-Dist: numpy>=1.22.4
17
18
  Requires-Dist: pandas>=2.0.0
18
19
  Requires-Dist: pillow>=10
@@ -29,15 +30,16 @@ Requires-Dist: coverage<8,>=7.6.10; extra == "dev"
29
30
  Requires-Dist: mypy<2,>=1.15.0; extra == "dev"
30
31
  Requires-Dist: pytest<7,>=6.1.2; extra == "dev"
31
32
  Requires-Dist: pytest-cov<7,>=6.0.0; extra == "dev"
32
- Requires-Dist: requests_mock<1.2,>=1.1; extra == "dev"
33
+ Requires-Dist: requests_mock<2,>=1.12; extra == "dev"
33
34
  Requires-Dist: ruff<1,>=0.9.4; extra == "dev"
35
+ Requires-Dist: time_machine<3,>=2.1; extra == "dev"
34
36
  Dynamic: license-file
35
37
 
36
38
  # kFinance
37
39
 
38
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.
39
41
 
40
- 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/).
41
43
 
42
44
  Any questions or suggestions can be sent to the [kFinance Maintainers](kfinance-maintainers@kensho.com).
43
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,4 +1,5 @@
1
1
  langchain-core>=0.3.15
2
+ langchain-google-genai<3,>=2.1.0
2
3
  numpy>=1.22.4
3
4
  pandas>=2.0.0
4
5
  pillow>=10
@@ -16,5 +17,6 @@ coverage<8,>=7.6.10
16
17
  mypy<2,>=1.15.0
17
18
  pytest<7,>=6.1.2
18
19
  pytest-cov<7,>=6.0.0
19
- requests_mock<1.2,>=1.1
20
+ requests_mock<2,>=1.12
20
21
  ruff<1,>=0.9.4
22
+ time_machine<3,>=2.1
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## v2.0.1
4
+ - Fix readthedocs integration for llm tools.
5
+
6
+ ## v2.0.0
7
+ - Refactor llm tools to use langchain `BaseTool`.
8
+
3
9
  ## v1.2.2
4
10
  - Add tabulate and pydantic as dependencies
5
11
 
@@ -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"
@@ -1672,18 +1711,11 @@ LINE_ITEMS: list[LineItemType] = [
1672
1711
  },
1673
1712
  ]
1674
1713
 
1675
- LINE_ITEMS_TO_DATA_ITEM_ID = {
1676
- line_item["name"]: line_item["dataitemid"] for line_item in LINE_ITEMS
1677
- }
1678
1714
 
1679
- LINE_ITEM_NAMES_AND_ALIASES = list(
1715
+ LINE_ITEM_NAMES_AND_ALIASES: list[str] = list(
1680
1716
  chain(*[[line_item["name"]] + list(line_item["aliases"]) for line_item in LINE_ITEMS])
1681
1717
  )
1682
1718
 
1683
- LINE_ITEM_SYNONYMS = {
1684
- alias: line_item["dataitemid"] for line_item in LINE_ITEMS for alias in line_item["aliases"]
1685
- }
1686
-
1687
1719
 
1688
1720
  FINANCIAL_STATEMENTS: dict[str, int] = {
1689
1721
  "income_statement": 1,
@@ -7,7 +7,13 @@ from uuid import uuid4
7
7
  import jwt
8
8
  import requests
9
9
 
10
- from .constants import BusinessRelationshipType, IdentificationTriple, IndustryClassification
10
+ from .constants import (
11
+ BusinessRelationshipType,
12
+ IdentificationTriple,
13
+ IndustryClassification,
14
+ Periodicity,
15
+ PeriodType,
16
+ )
11
17
 
12
18
 
13
19
  # version.py gets autogenerated by setuptools-scm and is not available
@@ -228,14 +234,14 @@ class KFinanceApiClient:
228
234
  is_adjusted: bool = True,
229
235
  start_date: Optional[str] = None,
230
236
  end_date: Optional[str] = None,
231
- periodicity: Optional[str] = None,
237
+ periodicity: Optional[Periodicity] = None,
232
238
  ) -> dict:
233
239
  """Get the pricing history."""
234
240
  url = (
235
241
  f"{self.url_base}pricing/{trading_item_id}/"
236
242
  f"{start_date if start_date is not None else 'none'}/"
237
243
  f"{end_date if end_date is not None else 'none'}/"
238
- f"{periodicity if periodicity is not None else 'none'}/"
244
+ f"{periodicity.value if periodicity else 'none'}/"
239
245
  f"{'adjusted' if is_adjusted else 'unadjusted'}"
240
246
  )
241
247
  return self.fetch(url)
@@ -265,14 +271,14 @@ class KFinanceApiClient:
265
271
  is_adjusted: bool = True,
266
272
  start_date: Optional[str] = None,
267
273
  end_date: Optional[str] = None,
268
- periodicity: Optional[str] = "",
274
+ periodicity: Optional[Periodicity] = None,
269
275
  ) -> bytes:
270
276
  """Get the price chart."""
271
277
  url = (
272
278
  f"{self.url_base}price_chart/{trading_item_id}/"
273
279
  f"{start_date if start_date is not None else 'none'}/"
274
280
  f"{end_date if end_date is not None else 'none'}/"
275
- f"{periodicity if periodicity is not None else 'none'}/"
281
+ f"{periodicity.value if periodicity else 'none'}/"
276
282
  f"{'adjusted' if is_adjusted else 'unadjusted'}"
277
283
  )
278
284
 
@@ -291,7 +297,7 @@ class KFinanceApiClient:
291
297
  self,
292
298
  company_id: int,
293
299
  statement_type: str,
294
- period_type: Optional[str] = None,
300
+ period_type: Optional[PeriodType] = None,
295
301
  start_year: Optional[int] = None,
296
302
  end_year: Optional[int] = None,
297
303
  start_quarter: Optional[int] = None,
@@ -300,7 +306,7 @@ class KFinanceApiClient:
300
306
  """Get a specified financial statement for a specified duration."""
301
307
  url = (
302
308
  f"{self.url_base}statements/{company_id}/{statement_type}/"
303
- f"{period_type if period_type is not None else 'none'}/"
309
+ f"{period_type.value if period_type else 'none'}/"
304
310
  f"{start_year if start_year is not None else 'none'}/"
305
311
  f"{end_year if end_year is not None else 'none'}/"
306
312
  f"{start_quarter if start_quarter is not None else 'none'}/"
@@ -312,7 +318,7 @@ class KFinanceApiClient:
312
318
  self,
313
319
  company_id: int,
314
320
  line_item: str,
315
- period_type: Optional[str] = None,
321
+ period_type: Optional[PeriodType] = None,
316
322
  start_year: Optional[int] = None,
317
323
  end_year: Optional[int] = None,
318
324
  start_quarter: Optional[int] = None,
@@ -321,7 +327,7 @@ class KFinanceApiClient:
321
327
  """Get a specified financial line item for a specified duration."""
322
328
  url = (
323
329
  f"{self.url_base}line_item/{company_id}/{line_item}/"
324
- f"{period_type if period_type is not None else 'none'}/"
330
+ f"{period_type.value if period_type else 'none'}/"
325
331
  f"{start_year if start_year is not None else 'none'}/"
326
332
  f"{end_year if end_year is not None else 'none'}/"
327
333
  f"{start_quarter if start_quarter is not None else 'none'}/"