BestPromptFinder
Home › Coding › Python: Download a CSV From a URL

Python: Download a CSV From a URL

Coding · GPT-5.6 · Coding
94AI Quality /100
85AI Usefulness est. /100
70Eval Confidence /100
No votes yetCommunity results

Quality, usefulness and confidence are AI evaluations out of 100 — not user ratings. Community results come from visitors' "worked / didn't work" votes below. How scoring works →

The prompt

Write a production-ready Python function that downloads a CSV file from a URL and saves it locally.

Requirements
- Signature: `download_csv(url: str, dest_path: str, timeout: int = 30) -> str` returning the saved path.
- Use `requests` with streaming (`iter_content`, 1 MB chunks) so large files don't load into memory.
- Raise a clear exception with the status code on non-2xx responses; handle timeouts and connection errors.
- Write to a temporary file first, then rename, so a failed download never leaves a half file.
- Create parent folders if missing.

Output
1. The function with docstring and type hints.
2. A short usage example.
3. How to load the result into pandas (`pd.read_csv`), including an encoding fallback.
4. Two pytest tests using a mocked response.
Find similar in the app →
Did this prompt work for you?

Why this prompt

Source

Created by BestPromptFinder — editorial prompt, not user-generated. See our content & source policy.

Related Coding prompts

Public-Market and Competitor Data Collection Agent
Quality 92 · GPT-5.6
AI2sql SQL Model - Query Generator
Quality 90 · GPT-5.6
PRD to MVP Technical Plan
Quality 90 · Claude Code
Third-Party API Integration
Quality 90 · Claude Code
Database Schema and Migration
Quality 90 · Claude Code
Cost-Aware AI Workflow Router
Quality 90 · Claude, Gemini