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

# File

Read a file from disk and parse it into the [Data structure](/sdk/core/data-structure) expected by `@graphysdk/core`. The format is auto-detected from the file extension.

## fromFile

```typescript theme={null}
import { fromFile } from '@graphysdk/data-import-utils/file';

const data = await fromFile('sales.csv');
const data = await fromFile('report.xlsx', { sheet: 'Revenue' });
```

### Signature

```typescript theme={null}
function fromFile(
  filePath: string,
  options?: FileParseOptions
): Promise<Data>
```

`FileParseOptions` combines spreadsheet options with the `hasHeader` flag from delimited parsing.

## Options

<ParamField path="filePath" type="string" required>
  Path to the file. The extension determines the format.
</ParamField>

<ParamField path="options.hasHeader" type="boolean" default="true">
  Whether the first row contains column headers (CSV/TSV only). When `false`,
  columns are auto-named `Column 1`, `Column 2`, etc.
</ParamField>

<ParamField path="options.sheet" type="string | number" default="0">
  Sheet to parse (spreadsheets only). Pass a sheet name or 0-based index.
</ParamField>

<ParamField path="options.locale" type="VizLocale" default="EN_US">
  Locale for number parsing. Determines thousand/decimal separator conventions.
</ParamField>

<ParamField path="options.maxFileSize" type="number" default="5">
  Maximum allowed input size in megabytes. Throws an error if the input exceeds this limit.
</ParamField>

<ParamField path="options.maxRows" type="number" default="100000">
  Maximum number of data rows to process (spreadsheets only).
</ParamField>

<ParamField path="options.maxCells" type="number" default="5000000">
  Maximum total cells to process (spreadsheets only).
</ParamField>

## Supported Extensions

| Extension      | Format |
| -------------- | ------ |
| `.csv`         | CSV    |
| `.tsv`, `.tab` | TSV    |
| `.xlsx`        | XLSX   |
| `.xls`         | XLS    |
| `.ods`         | ODS    |

Unsupported extensions throw an error listing the supported formats.

## Examples

### With the AI SDK

```typescript theme={null}
import { fromFile } from '@graphysdk/data-import-utils/file';
import { GraphyAiSdk } from '@graphysdk/agents-sdk';

const ai = new GraphyAiSdk({
  apiKey: process.env.GRAPHY_API_KEY,
  baseUrl: 'https://agents.graphy.dev',
});

const data = await fromFile('quarterly-sales.csv');

const result = await ai.generateGraph({
  config: { data },
  userPrompt: 'line chart showing quarterly trends',
});
```

### Error Handling

```typescript theme={null}
try {
  const data = await fromFile('data.pdf');
} catch (error) {
  // Error: Unsupported file extension ".pdf". Supported: .csv, .tsv, .tab, .xlsx, .xls, .ods
}
```

<Note>
  `fromFile` uses Node.js `fs.readFile` under the hood and is not available in
  the browser. For browser usage, use the format-specific parsers (`fromCSV`,
  `fromXLSX`, etc.) after reading the file with the File API.
</Note>
