This should help:

import csv
import requests

CSV_URL = 'http://samplecsvs.s3.amazonaws.com/Sacramentorealestatetransactions.csv'


with requests.Session() as s:
    download = s.get(CSV_URL)

    decoded_content = download.content.decode('utf-8')

    cr = csv.reader(decoded_content.splitlines(), delimiter=',')
    my_list = list(cr)
    for row in my_list:
        print(row)

Ouput sample:

['street', 'city', 'zip', 'state', 'beds', 'baths', 'sq__ft', 'type', 'sale_date', 'price', 'latitude', 'longitude']
['3526 HIGH ST', 'SACRAMENTO', '95838', 'CA', '2', '1', '836', 'Residential', 'Wed May 21 00:00:00 EDT 2008', '59222', '38.631913', '-121.434879']
['51 OMAHA CT', 'SACRAMENTO', '95823', 'CA', '3', '1', '1167', 'Residential', 'Wed May 21 00:00:00 EDT 2008', '68212', '38.478902', '-121.431028']
['2796 BRANCH ST', 'SACRAMENTO', '95815', 'CA', '2', '1', '796', 'Residential', 'Wed May 21 00:00:00 EDT 2008', '68880', '38.618305', '-121.443839']
['2805 JANETTE WAY', 'SACRAMENTO', '95815', 'CA', '2', '1', '852', 'Residential', 'Wed May 21 00:00:00 EDT 2008', '69307', '38.616835', '-121.439146']
[...]

Related question with answer: https://stackoverflow.com/a/33079644/295246


Edit: Other answers are useful if you need to download large files (i.e. stream=True).

Answer from HEADLESS_0NE on Stack Overflow
Top answer
1 of 14
128

This should help:

import csv
import requests

CSV_URL = 'http://samplecsvs.s3.amazonaws.com/Sacramentorealestatetransactions.csv'


with requests.Session() as s:
    download = s.get(CSV_URL)

    decoded_content = download.content.decode('utf-8')

    cr = csv.reader(decoded_content.splitlines(), delimiter=',')
    my_list = list(cr)
    for row in my_list:
        print(row)

Ouput sample:

['street', 'city', 'zip', 'state', 'beds', 'baths', 'sq__ft', 'type', 'sale_date', 'price', 'latitude', 'longitude']
['3526 HIGH ST', 'SACRAMENTO', '95838', 'CA', '2', '1', '836', 'Residential', 'Wed May 21 00:00:00 EDT 2008', '59222', '38.631913', '-121.434879']
['51 OMAHA CT', 'SACRAMENTO', '95823', 'CA', '3', '1', '1167', 'Residential', 'Wed May 21 00:00:00 EDT 2008', '68212', '38.478902', '-121.431028']
['2796 BRANCH ST', 'SACRAMENTO', '95815', 'CA', '2', '1', '796', 'Residential', 'Wed May 21 00:00:00 EDT 2008', '68880', '38.618305', '-121.443839']
['2805 JANETTE WAY', 'SACRAMENTO', '95815', 'CA', '2', '1', '852', 'Residential', 'Wed May 21 00:00:00 EDT 2008', '69307', '38.616835', '-121.439146']
[...]

Related question with answer: https://stackoverflow.com/a/33079644/295246


Edit: Other answers are useful if you need to download large files (i.e. stream=True).

2 of 14
40

To simplify these answers, and increase performance when downloading a large file, the below may work a bit more efficiently.

import requests
from contextlib import closing
import csv
from codecs import iterdecode

url = "http://download-and-process-csv-efficiently/python.csv"

with closing(requests.get(url, stream=True)) as r:
    reader = iterdecode(csv.reader(r.iter_lines(), 'utf-8'), 
                        delimiter=',', 
                        quotechar='"')
    for row in reader:
        print(row)

By setting stream=True in the GET request, when we pass r.iter_lines() to csv.reader(), we are passing a generator to csv.reader(). By doing so, we enable csv.reader() to lazily iterate over each line in the response with for row in reader.

This avoids loading the entire file into memory before we start processing it, drastically reducing memory overhead for large files.

Discussions

pandas - How to download a csv file in Python - Stack Overflow
I am trying to download a csv file from the url https://qubeshub.org/publications/1220/supportingdocs/1#supportingdocs . the file is Elephant Morphometrics and Tusk Size-originaldata-3861.csv I have More on stackoverflow.com
🌐 stackoverflow.com
pandas - Saving a downloaded CSV file using Python - Stack Overflow
I want to download a csv file from a link with request and save it as MSFT.csv. However, my code return error File " ", line 1, in _csv.Error: new-line character seen in unquoted fi... More on stackoverflow.com
🌐 stackoverflow.com
Python Download Using CSV file - Stack Overflow
I am trying to figure out how to use Python to download files listed in a CSV file and use the CSV file to name the download. So my CSV file would look like this: HTTP://www.example.com/filetodownl... More on stackoverflow.com
🌐 stackoverflow.com
Downloading a csv file using requests, but getting the header and malformed csv
I’m trying to download a csv file from a server that uses a basic authkey in the header. On the webpage, there is just a text box for the Authkey and a button to download the csv file. So far I can authenticate and pri… More on discuss.python.org
🌐 discuss.python.org
2
0
March 2, 2023
🌐
Saturn Cloud
saturncloud.io › blog › downloading-a-csv-from-a-url-and-converting-it-to-a-dataframe-using-python-pandas
Downloading a CSV from a URL and Converting it to a DataFrame using Python Pandas | Saturn Cloud Blog
May 1, 2026 - In this guide, we covered the process of downloading a CSV file from a URL and converting it into a Pandas DataFrame using Python. We discussed the pros and cons of this method, common errors, and provided detailed examples for handling potential issues.
🌐
Medium
medium.com › @amiri.mccain › use-python-to-read-and-download-a-large-csv-from-a-url-03a8f3062a4e
Use Python to Read and Download a Large CSV from a URL | by Amiri McCain | Medium
January 23, 2024 - Replacing NaN null fields with the string “null” fixed the issue (e.g. NULL_IF = (‘NULL', ‘null')in the FILE FORMAT object in Snowflake). Since Snowflake is outside the scope of this article, I plan on discussing this a little more in a future article. ... import pandas as pd import numpy as np import os # Download CSV with read_csv df = pd.read_csv('https://static.openfoodfacts.org/data/en.openfoodfacts.org.products.csv', \ sep='\t', low_memory=False)
🌐
Delft Stack
delftstack.com › home › howto › python › python download csv from url
How to Download CSV From URL in Python | Delft Stack
February 12, 2024 - The csv module works with CSV files in Python. It can parse the response using the csv.reader() function. We can then display the parsed result at once or traverse through the content one row at a time. Let’s explore a practical example of how to download a CSV file from a URL using the urllib and csv modules.
🌐
Quora
quora.com › How-do-I-write-a-code-in-Python-that-downloads-a-csv-file-from-the-web
How to write a code in Python that downloads a .csv file from the web - Quora
Answer (1 of 3): The easiest and fastest option is as follows. This will download the file, parse it and return a tabular object, so-called DataFrame. With that you can directly work with the data and apply statistics to it etc. [code]# install pandas: run pip install pandas before you run this ...
Find elsewhere
🌐
Kaggle
kaggle.com › code › arkaung › download-csv-file
Download csv file | Kaggle
March 17, 2019 - Explore and run AI code with Kaggle Notebooks | Using data from No attached data sources
🌐
Medium
medium.com › @mudassar_lhr › how-to-download-the-csv-file-from-url-using-python-650eae6d3478
How to download the CSV file from URL using Python | by Mudassar | Medium
May 27, 2022 - As I mentioned above some modules are built-in and some are need to install. For download the csv file we have to install the package “requests” For this you have to go to the Terminal: write the command:
Top answer
1 of 4
28

If you're trying to write this data to a CSV file, you can first download it using requests.get, then save each line to a CSV file.

import csv
import requests

url = 'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&apikey=demo&datatype=csv'
response = requests.get(url)        

with open('out.csv', 'w') as f:
    writer = csv.writer(f)
    for line in response.iter_lines():
        writer.writerow(line.decode('utf-8').split(','))

Alternatively, if you have pandas installed (pip install --user pandas), you can load data by passing a URL directly.

import pandas as pd

df = pd.read_csv(url)   
df.head()

    timestamp    open    high     low   close  adjusted_close    volume  dividend_amount  split_coefficient
0  2019-06-19  135.00  135.93  133.81  135.69          135.69  17946556              0.0                1.0
1  2019-06-18  134.19  135.24  133.57  135.16          135.16  25908534              0.0                1.0
2  2019-06-17  132.63  133.73  132.53  132.85          132.85  14517785              0.0                1.0
3  2019-06-14  132.26  133.79  131.64  132.45          132.45  17821703              0.0                1.0
4  2019-06-13  131.98  132.67  131.56  132.32          132.32  17200848              0.0                1.0

df.to_csv('out.csv')
2 of 4
7

You can achieve it via requests as

import os
import requests

def download_file(url, filename):
    ''' Downloads file from the url and save it as filename '''
    # check if file already exists
    if not os.path.isfile(filename):
        print('Downloading File')
        response = requests.get(url)
        # Check if the response is ok (200)
        if response.status_code == 200:
            # Open file and write the content
            with open(filename, 'wb') as file:
                # A chunk of 128 bytes
                for chunk in response:
                    file.write(chunk)
    else:
        print('File exists')

You can call the function with your url and filename that you want. In your case it would be:

url = 'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&apikey=demo&datatype=csv'
filename = 'MSFT.csv'
download_file(url, filename)

Hope this helps.

🌐
Python.org
discuss.python.org › python help
Downloading a csv file using requests, but getting the header and malformed csv - Python Help - Discussions on Python.org
March 2, 2023 - I’m trying to download a csv file from a server that uses a basic authkey in the header. On the webpage, there is just a text box for the Authkey and a button to download the csv file. So far I can authenticate and print the data using. url = 'https://example.com/stats/data/' keyLogin = {"from":"2023-2-28T0:0:0Z","to":"2023-2-28T23:59:59Z","lists":"%%All%%","authKey":"pythonKey","timeOffset":0} x = requests.post(url, json = keyLogin) f = open('data.txt', 'wb') f.write(x.text.encode('utf8'))...
🌐
GitHub
gist.github.com › krisrak › 2cd4230682997d399c33a1b24c266521
Python script to download urls in a csv file · GitHub
you have to specify the csv_filename and the column_header_name that has the urls to be downloaded. The urls can be images or video files, and the script will create a folder in the same location and download the files to it.
🌐
Python Forum
python-forum.io › thread-31169.html
Downloading CSV from a website
Hello all, I ran into a few issues when dealing with Python and CSV files. 1. How do I automatically login to a website? 2. How do I automatically export a CSV file from the website - The CSV file downloads onto my computer - I need an updated C...
🌐
PyPI
pypi.org › project › python-csv
python-csv · PyPI
Download the file for your platform. If you're not sure which to choose, learn more about installing packages. ... Filter files by name, interpreter, ABI, and platform. If you're not sure about the file name format, learn more about wheel file names. ... Details for the file python_csv-0.0.14.tar.gz.
      » pip install python-csv
    
Published   Jun 07, 2025
Version   0.0.14
🌐
Reddit
reddit.com › r/webscraping › automatically download csv from website (python)
r/webscraping on Reddit: Automatically download CSV from website (Python)
January 20, 2022 -

I need to be able to download a file each day from the following site:
https://fundcentres.lgim.com/uk/en/fund-centre/PMC/

There is a link that says 'Download Data' which then presents a pop-up with 'All Fund Data'.

Normally I use Python requests but this is more complicated than I've dealt with. I've searched different way to try to replicated the POST request but can't quite understand what I'm missing.

Any help would be appreciated!

🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
How to download the .csv? - Python
May 27, 2022 - Im trying to work on one of the python project called Sea Level Predictor. And the first task is to import the data from epa-sea-level.csv However, i dont know how to download the file. I’ve been clicking but nothings happening. How do i download the file to get me started? Your browser information...