Skip to main content

llama-index tools python_file integration

Project description

Python File Tool

This tool loads a python file and extracts function names, arguments and descriptions automatically. This tool is particular useful for automatically creating custom Tool Specs when you already have well documented python functions.

Usage

This tool has more extensive example usage documented in a Jupyter notebook here

Here's an example usage of the PythonFileToolSpec.

from llama_index.tools.python_file import PythonFileToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI

pyfile = PythonFileToolSpec("./numpy_linalg.py")

agent = FunctionAgent(
    tools=pyfile.to_tool_list(),
    llm=OpenAI(model="gpt-4.1"),
)

print(
    await agent.run(
        """Load the eig, transpose and solve functions from the python file,
and then write a function definition using only builtin python types (List, float, Tuple)
with a short 5-10 line doc string tool prompts for the functions that only has a small description and arguments
"""
    )
)

function_definitions: Get all of the function definitions from the Python file get_function: Get a specific function definition from the Python file get_functions: Get a list of functions from the python file

This loader is designed to be used as a way to load data as a Tool in a Agent.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_tools_python_file-0.5.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_tools_python_file-0.5.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_tools_python_file-0.5.0.tar.gz.

File metadata

  • Download URL: llama_index_tools_python_file-0.5.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_tools_python_file-0.5.0.tar.gz
Algorithm Hash digest
SHA256 fb201827762240f9d467c1d9ac2f3ebf6a0fffc0109871bcce3544d78e2756ff
MD5 97346b37c8cf70abec57300b2bc91e6c
BLAKE2b-256 530416b18882eaaba0bfb991fc9b279f3f625e34c623c1a2a5586e8eec268fd7

See more details on using hashes here.

File details

Details for the file llama_index_tools_python_file-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: llama_index_tools_python_file-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_tools_python_file-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd0d3030b28d7936cb50169c81de2fbd4373a42df0334d3e866e863f11aadfa8
MD5 7f82315a03b7fbdfb5940f41836a01ef
BLAKE2b-256 0e392afde7eab8c57c124556b727cd3cbf7afed56270d01fa9ae80807a8c312b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page