# Database Tool
This tool connects to a database (using SQLAlchemy under the hood) and allows an Agent to query the database and get information about the tables.
## Usage
This tool has more extensive example usage documented in a Jupyter notebook [here](https://github.com/emptycrown/llama-hub/tree/main/llama_hub/tools/notebooks/database.ipynb) and [here](https://github.com/emptycrown/llama-hub/tree/main/llama_hub/tools/notebooks/intro_to_tools.ipynb)
Here's an example usage of the DatabaseToolSpec.
```python
from llama_index.tools.database import DatabaseToolSpec
from llama_index.agent import OpenAIAgent
db_tools = DatabaseToolSpec(
scheme="postgresql", # Database Scheme
host="localhost", # Database Host
port="5432", # Database Port
user="postgres", # Database User
password="FakeExamplePassword", # Database Password
dbname="postgres", # Database Name
)
agent = OpenAIAgent.from_tools(db_tools.to_tool_list())
agent.chat("What tables does this database contain")
agent.chat("Describe the first table")
agent.chat("Retrieve the first row of that table")
```
The tools available are:
`list_tables`: A tool to list the tables in the database schema
`describe_tables`: A tool to describe the schema of a table
`load_data`: A tool that accepts an SQL query and returns the result
This loader is designed to be used as a way to load data as a Tool in a Agent. See [here](https://github.com/emptycrown/llama-hub/tree/main) for examples.
Raw data
{
"_id": null,
"home_page": "",
"name": "llama-index-tools-database",
"maintainer": "ajhofmann",
"docs_url": null,
"requires_python": ">=3.8.1,<4.0",
"maintainer_email": "",
"keywords": "aws rds,postgres,snowflake,sql",
"author": "Your Name",
"author_email": "you@example.com",
"download_url": "https://files.pythonhosted.org/packages/2f/fc/c2933085e63cbc77ea8eb7406cc30486735346deaa3db71dd31cf672ab7e/llama_index_tools_database-0.1.3.tar.gz",
"platform": null,
"description": "# Database Tool\n\nThis tool connects to a database (using SQLAlchemy under the hood) and allows an Agent to query the database and get information about the tables.\n\n## Usage\n\nThis tool has more extensive example usage documented in a Jupyter notebook [here](https://github.com/emptycrown/llama-hub/tree/main/llama_hub/tools/notebooks/database.ipynb) and [here](https://github.com/emptycrown/llama-hub/tree/main/llama_hub/tools/notebooks/intro_to_tools.ipynb)\n\nHere's an example usage of the DatabaseToolSpec.\n\n```python\nfrom llama_index.tools.database import DatabaseToolSpec\nfrom llama_index.agent import OpenAIAgent\n\ndb_tools = DatabaseToolSpec(\n scheme=\"postgresql\", # Database Scheme\n host=\"localhost\", # Database Host\n port=\"5432\", # Database Port\n user=\"postgres\", # Database User\n password=\"FakeExamplePassword\", # Database Password\n dbname=\"postgres\", # Database Name\n)\nagent = OpenAIAgent.from_tools(db_tools.to_tool_list())\n\nagent.chat(\"What tables does this database contain\")\nagent.chat(\"Describe the first table\")\nagent.chat(\"Retrieve the first row of that table\")\n```\n\nThe tools available are:\n\n`list_tables`: A tool to list the tables in the database schema\n`describe_tables`: A tool to describe the schema of a table\n`load_data`: A tool that accepts an SQL query and returns the result\n\nThis loader is designed to be used as a way to load data as a Tool in a Agent. See [here](https://github.com/emptycrown/llama-hub/tree/main) for examples.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "llama-index tools database integration",
"version": "0.1.3",
"project_urls": null,
"split_keywords": [
"aws rds",
"postgres",
"snowflake",
"sql"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2af53ef6a342199668981ebf2f81fc7318177707df106f970ab15cdde2c267bc",
"md5": "12b4836a8e239c22cc9f4895f4bccf44",
"sha256": "0c6ade4c6787da82608238a8a5d8ce2b40a624693633286bb5500e6592470bc1"
},
"downloads": -1,
"filename": "llama_index_tools_database-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "12b4836a8e239c22cc9f4895f4bccf44",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8.1,<4.0",
"size": 3677,
"upload_time": "2024-02-21T22:15:43",
"upload_time_iso_8601": "2024-02-21T22:15:43.898842Z",
"url": "https://files.pythonhosted.org/packages/2a/f5/3ef6a342199668981ebf2f81fc7318177707df106f970ab15cdde2c267bc/llama_index_tools_database-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2ffcc2933085e63cbc77ea8eb7406cc30486735346deaa3db71dd31cf672ab7e",
"md5": "abfa17548964733b534c8cc107c53dfc",
"sha256": "16676ffd83fa35ffaffbe1b35c64f16602d7d44be91c7af2817345b22c7bf2a1"
},
"downloads": -1,
"filename": "llama_index_tools_database-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "abfa17548964733b534c8cc107c53dfc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8.1,<4.0",
"size": 3429,
"upload_time": "2024-02-21T22:15:45",
"upload_time_iso_8601": "2024-02-21T22:15:45.111284Z",
"url": "https://files.pythonhosted.org/packages/2f/fc/c2933085e63cbc77ea8eb7406cc30486735346deaa3db71dd31cf672ab7e/llama_index_tools_database-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-21 22:15:45",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "llama-index-tools-database"
}