> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# CSV

> Read and manipulate CSV files

## Overview

CSV tool allows you to read, write, and query CSV files.

The user points to a CSV file; the agent reads, filters, or writes rows and returns the result.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "CSVTool Flow"
        User[👤 User] --> Agent[🤖 Agent]
        Agent --> Tool[🔧 CSVTool]
        Tool --> Result[✅ Result]
        Result --> Agent
    end

    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef tool fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef output fill:#10B981,stroke:#7C90A0,color:#fff

    class User,Agent agent
    class Tool tool
    class Result output
```

## Installation

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install "praisonai[tools]"
```

## Quick Start

<Steps>
  <Step title="Simple Usage">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonai_tools import CSVTool

    # Initialize
    csv_tool = CSVTool()

    # Read CSV
    data = csv_tool.read("data.csv")
    print(data)
    ```
  </Step>

  <Step title="With Configuration">
    Use the same tool with an agent — see **Usage with Agent** below, or pass env vars and options from the sections above.
  </Step>
</Steps>

## Usage with Agent

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent
from praisonai_tools import CSVTool

agent = Agent(
    name="DataAnalyst",
    instructions="You help analyze CSV data.",
    tools=[CSVTool()]
)

response = agent.chat("Read sales.csv and summarize the data")
print(response)
```

## Available Methods

### read(path)

Read a CSV file.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonai_tools import CSVTool

csv_tool = CSVTool()
data = csv_tool.read("data.csv")
```

### write(path, data)

Write data to a CSV file.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
csv_tool.write("output.csv", [{"name": "Alice", "age": 30}])
```

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Tool as Tool
    participant Svc as CSV file

    User->>Agent: Request
    Agent->>Tool: Call tool
    Tool->>Svc: Query
    Svc-->>Tool: Data
    Tool-->>Agent: Result
    Agent-->>User: Response
```

***

## Best Practices

<AccordionGroup>
  <Accordion title="Read a schema first">
    Inspect column names before querying so the agent references real fields, not guesses.
  </Accordion>

  <Accordion title="Stream large files">
    For big CSVs, process in chunks so memory stays bounded.
  </Accordion>

  <Accordion title="Validate before writing">
    Confirm row shape before `write` so you don't corrupt an existing file.
  </Accordion>
</AccordionGroup>

***

## Related Tools

<CardGroup cols={2}>
  <Card title="JSON" icon="book" href="/docs/tools/external/json">
    JSON files
  </Card>

  <Card title="Pandas" icon="book" href="/docs/tools/external/pandas">
    Data analysis
  </Card>

  <Card title="File" icon="book" href="/docs/tools/external/file">
    General files
  </Card>
</CardGroup>
