> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# SQL Tools

> List tables and query a Postgres database from a connection URL with SQLTools.

```python sql_tools.py theme={null}
"""
Sql Tools
=============================

Demonstrates sql tools.
"""

from agno.agent import Agent
from agno.tools.sql import SQLTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

agent = Agent(tools=[SQLTools(db_url=db_url)])

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response(
        "List the tables in the database. Tell me about contents of one of the tables",
        markdown=True,
    )
```

## Run the Example

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno "psycopg[binary]" openai sqlalchemy
```

**2. Export your OpenAI API key**

```bash Mac/Linux theme={null}
export OPENAI_API_KEY="your_openai_api_key_here"
```

```bash Windows theme={null}
$Env:OPENAI_API_KEY="your_openai_api_key_here"
```

<Snippet file="run-pgvector-step.mdx" />

**3. Run the example**

Save the code above as `sql_tools.py`, then run:

```bash theme={null}
python sql_tools.py
```

Full source: [cookbook/91\_tools/sql\_tools.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/91_tools/sql_tools.py)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.