← ClaudeAtlas

file-export-and-reportinglisted

Excel/CSV generation and download endpoints in FastAPI — pandas to_excel, multi-sheet workbooks, CSV streaming, presigned GCS URLs, UploadFile parsing. Use when building report exports or file downloads.
ajyadav013/claude-kit · ★ 12 · Data & Documents · score 72
Install: claude install-skill ajyadav013/claude-kit
Production patterns for generating and serving Excel and CSV file downloads from FastAPI endpoints, plus reading uploaded spreadsheets. ## When to use - Building report export endpoints that return Excel (.xlsx) or CSV files - Creating formatted multi-sheet Excel workbooks with auto-sized columns - Implementing CSV streaming downloads for large datasets - Handling file uploads (UploadFile) and reading Excel/CSV data from user uploads - Returning file content as base64-encoded JSON responses - Generating presigned GCS URLs for secure file downloads - Building download endpoints with proper Content-Disposition headers - Converting database query results or pandas DataFrames into downloadable reports - Creating Excel templates with specific formatting for user downloads ## Core conventions 1. **Excel generation with openpyxl**: use `pd.ExcelWriter(output, engine='openpyxl')` with `BytesIO()` buffer. Write DataFrame via `df.to_excel(writer, sheet_name='..', index=False)`, access `writer.sheets['SheetName']` for formatting, auto-adjust column widths using `openpyxl.utils.get_column_letter()` and `worksheet.column_dimensions[letter].width`. Alternative: `engine='xlsxwriter'` for advanced formatting (charts, conditional formatting). Always `seek(0)` before reading bytes. 2. **StreamingResponse for file downloads**: return `StreamingResponse(BytesIO_content, media_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', headers={'Content-Disposition': f'attachme