# 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/run-llama/llama_index/blob/main/llama-index-integrations/tools/llama-index-tools-database/examples/database.ipynb).
Here's an example usage of the DatabaseToolSpec.
```python
from llama_index.tools.database import DatabaseToolSpec
from llama_index.agent.openai 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.
Raw data
{
"_id": null,
"home_page": null,
"name": "llama-index-tools-database",
"maintainer": "ajhofmann",
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "aws rds, postgres, snowflake, sql",
"author": "Your Name",
"author_email": "you@example.com",
"download_url": "https://files.pythonhosted.org/packages/cf/c1/f7a3cac198cbd08f9a1624f944ea80692c55a9daa3bbae777a54dcc49a50/llama_index_tools_database-0.3.0.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/run-llama/llama_index/blob/main/llama-index-integrations/tools/llama-index-tools-database/examples/database.ipynb).\n\nHere's an example usage of the DatabaseToolSpec.\n\n```python\nfrom llama_index.tools.database import DatabaseToolSpec\nfrom llama_index.agent.openai 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.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "llama-index tools database integration",
"version": "0.3.0",
"project_urls": null,
"split_keywords": [
"aws rds",
" postgres",
" snowflake",
" sql"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "482b7dd5118365de6d82e5bbc90081538e46abe255ee8f48f6dbabcdb5b4b64b",
"md5": "51130ab3be37cd89cbcaa43e6477b6bf",
"sha256": "d7820fb960dca18bbbc78e330a68769b97c73c514f26a813c47fc7cbb3870dc3"
},
"downloads": -1,
"filename": "llama_index_tools_database-0.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "51130ab3be37cd89cbcaa43e6477b6bf",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 3657,
"upload_time": "2024-11-17T23:04:11",
"upload_time_iso_8601": "2024-11-17T23:04:11.835074Z",
"url": "https://files.pythonhosted.org/packages/48/2b/7dd5118365de6d82e5bbc90081538e46abe255ee8f48f6dbabcdb5b4b64b/llama_index_tools_database-0.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cfc1f7a3cac198cbd08f9a1624f944ea80692c55a9daa3bbae777a54dcc49a50",
"md5": "43eae513258b12c7637390183a9ae2d4",
"sha256": "8bbce16005b99a311912e9fee3c087a8db2beaeb0855e20ebb808fee00047d44"
},
"downloads": -1,
"filename": "llama_index_tools_database-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "43eae513258b12c7637390183a9ae2d4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 3407,
"upload_time": "2024-11-17T23:04:13",
"upload_time_iso_8601": "2024-11-17T23:04:13.272031Z",
"url": "https://files.pythonhosted.org/packages/cf/c1/f7a3cac198cbd08f9a1624f944ea80692c55a9daa3bbae777a54dcc49a50/llama_index_tools_database-0.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-17 23:04:13",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "llama-index-tools-database"
}