save_query_to_csv
Export government data by running a filter or SQL query and saving the result as a local CSV file. Returns the file path and row count.
Instructions
Write a query or filter result to a local CSV file.
Export endpoint for analysis workflows — run your filter or SQL, then save the result to open in Excel or another tool. Returns the file path and row count. First call downloads + caches the source file. Subsequent calls reuse the cache.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | Direct URL to the file (CKAN resource 'url' field). | |
| format | Yes | Format declared in CKAN. Accepts: csv, tsv, xlsx, json. | |
| dest | No | Absolute path for the output file (.csv or .tsv). If None, saves to ~/Downloads/datosgobdo-exports/<slug>-<timestamp>.csv. Must not contain '..'. Cannot write to system paths (/etc, /usr, /bin, ...). | |
| sql | No | Read-only SQL query against table 'data' (same rules as query_resource). If provided, takes precedence over filters/columns. | |
| filters | No | Same filter syntax as filter_resource. Used if sql is None. | |
| columns | No | Columns to include. None = all. Ignored if sql is provided. | |
| limit | No | Max rows to write (1–100000). Default 10000. | |
| overwrite | No | Overwrite dest if it already exists. Default False. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| error | No | ||
| hint | No | ||
| path | No | ||
| rows_written | No | ||
| columns | No | ||
| bytes_written | No | ||
| cache | No |