Using Python to Fetch API Data into CSV

Today, ill be demonstrating a nice beginner 'project' to show how you can quickly and easily build a python script using standard modules to fetch data from an API and write it to a CSV. In this video we'll be using a public API provided from Coincap to grab cryptocurrency prices and write them into a CSV file. I encourage anyone who watches this to expand this out to present this in a webpage or maybe even upload the CSV to Google Sheets!
A great resource for getting free publicly available API's as seen in this video is from this repo here : github.com/public-apis/public...
📧 Weekly mail dedicated to solo devs looking to make it online: danielotto.beehiiv.com/
☕Buy me a coffee: buymeacoffee.com/danielotto
If you found this video helpful and would like to support my channel make sure you give the sub button a smash so you also dont miss out on video's like this in the future! :)
Note: In this video I am using Python v3.9.4

Пікірлер: 44

  • @griffingillam9800
    @griffingillam9800 Жыл бұрын

    thank you so much for the walkthrough. been trying to find a way to do this for a few days now and your video worked perfectly

  • @doop9134
    @doop9134 Жыл бұрын

    I love your tutorial! Short & precise & super helpful! This helped a lot! Thanks so much!! 💙

  • @renan6827
    @renan68273 ай бұрын

    Great tutorial!!! Short, precise and very straightforward😁. No time wasting. Your video helped a lot. Much appreciate !!!!

  • @MegaGroover
    @MegaGroover2 жыл бұрын

    Thank you very much, really good tutorial! I'm so happy it worked!

  • @historique1
    @historique1 Жыл бұрын

    Exactly what I needed, thank you so much!!

  • @VanioJR
    @VanioJR2 жыл бұрын

    your tutorial is very good, it helped me a lot! thank you so much!

  • @thean1585
    @thean15852 жыл бұрын

    thankyou for the tutorial, im just starting to learn python but im sure this will be useful in the future!

  • @pleabargain
    @pleabargain2 жыл бұрын

    Very helpful! Thank you!

  • @nftichie
    @nftichie11 ай бұрын

    Love this video

  • @financephofun7090
    @financephofun70902 жыл бұрын

    Thank you Daniel! I used your code to practice on different different API to csv file, it was very helpful, not sure if you have any plans, it would be nice if we took the csv file and did some analysis

  • @ashu__risiofficial5887
    @ashu__risiofficial58872 жыл бұрын

    Saved my job bro ☺️☺️☺️

  • @PoolNinjasTN
    @PoolNinjasTN Жыл бұрын

    Hey boss, so im having the issue typeError: list indices must be integers or slices, not str for the for x in function My "in" is purple yours is blue. Ideas? Im new to python!

  • @youtubewatch3981
    @youtubewatch39812 жыл бұрын

    thanks for your video Daniel, i try to use same way to pull options data and format like your style.. but i can't find the "data" and i try to run it. the error :for x in myjson['strikePrice']: TypeError: string indices must be integers [Finished in 2.524s]

  • @thippeswamykv242
    @thippeswamykv2422 жыл бұрын

    What is the method for storing post api into csv

  • @memo.a937
    @memo.a9372 ай бұрын

    I want to do the same thing but the problem i have is that the json response have so many levels, any Idea how to reach these data in the inner levels

  • @navdeepkaur4574
    @navdeepkaur45742 жыл бұрын

    Thnks alot 😊

  • @easylearnfrench
    @easylearnfrench Жыл бұрын

    Hi, thank you for your helpful video. how can I access to second entry? e.g there is an order_id with two different rows like below row #1 order id: i6tp-pucp-dsrx-1gg7-ikef item_no: 2304 row #2 order id: i6tp-pucp-dsrx-1gg7-ikef item_no: 10914

  • @monikak6212
    @monikak6212 Жыл бұрын

    I use ur code for different api,but i use to get error list indices must be integer or slices,not str

  • @zuriatnaveed6723
    @zuriatnaveed67232 жыл бұрын

    myjson = response.json() TypeError: 'NoneType' object is not callable how to solvs this error??

  • @JasonSvoboda
    @JasonSvoboda Жыл бұрын

    How do you approach this if they do not have a top level organizer like data and instead are just the individual items strings themselves?

  • @danielotto

    @danielotto

    Жыл бұрын

    The name ‘data’ is simply the key to the value which is the array. If you have just individual items you should able to select on those individual key names to read their respective values. You can google ‘How to get values by key in python’ and their should be a few examples :)

  • @qb9496
    @qb94962 жыл бұрын

    Can you do a tutorial on google places api to csv? Name, address, phone

  • @2010aishwary
    @2010aishwary2 жыл бұрын

    how do we filter if the data has more nested arrays ?

  • @danielotto

    @danielotto

    2 жыл бұрын

    If they are nested arrays you would do : myjson[‘data’][0] , replacing 0 with the required index. If it is nested objects then myjson[‘data’][‘nestedobject’]. Hope this helps!

  • @2010aishwary

    @2010aishwary

    2 жыл бұрын

    @@danielotto got it. I am a bit new to this had to loop through multiple lists and dictionaries. Thanks for this amazing video helped a lot.

  • @whatarewetoday4585
    @whatarewetoday45852 жыл бұрын

    ...Broooo, I will make you dinner, anything you want. You want to order in courses I got you. This was so helpful

  • @danielotto

    @danielotto

    2 жыл бұрын

    Haha thanks mate glad you found it useful!

  • @-majidkids8087
    @-majidkids80872 жыл бұрын

    for x in myjson['data']: KeyError: 'data' how i can resolve this problem please ? i write same your code

  • @danielotto

    @danielotto

    2 жыл бұрын

    Hey Majid, are you using the same API as in the video? Because the API returns a response of an object like { *data* : [{ id: bitcoin, rank : 1 }] etc we are referencing the key in that response object which is the word *data* . If your using another API the response could be different and the key is likely different aswell. If your using a different API you need to reference the key value name in myjson['data']

  • @-majidkids8087

    @-majidkids8087

    2 жыл бұрын

    @@danielotto the key value is : {"txs":

  • @danielotto

    @danielotto

    2 жыл бұрын

    if it is something like that then you would need to do : mydata['txs'] However if it is nested and your data looks like this from the api : { "data" : [{ "txs" : 3 } ,{"txs" : 5 ]} then you would need to do something like myjson['data']['txs'] It's hard to know without seeing what kind of response your API is giving you but hope that helps :)

  • @-majidkids8087

    @-majidkids8087

    2 жыл бұрын

    @@danielotto can i send my code to see it please ?

  • @-majidkids8087

    @-majidkids8087

    2 жыл бұрын

    @@danielotto thank you very much sir

  • @v.abhinav5637
    @v.abhinav5637 Жыл бұрын

    the prices are so different today . i just forget the price back then

  • @natalyescamilla7022
    @natalyescamilla70222 жыл бұрын

    Daniel, working on a piece for API to csv and would love to get some 1-1 with you. Have two days to complete it. Let me know, Thank you

  • @danielotto

    @danielotto

    2 жыл бұрын

    Hey Nataly, what are you needing help with on that?

  • @natalyescamilla8907

    @natalyescamilla8907

    2 жыл бұрын

    @@danielotto need to call multiple GET API calls to find temperature, humidity, vehicle, close to real time.

  • @natalyescamilla7022

    @natalyescamilla7022

    2 жыл бұрын

    @@danielotto Hey, Do you happen to have any content on updating the csv every 30 mins? I'm trying to use the schedule module but not getting anything

  • @danielotto

    @danielotto

    2 жыл бұрын

    @@natalyescamilla7022 Depending where you're running it from, you could setup a server with a cron job if on linux or a windows service to trigger the script. You could even use something like Zapier which could do most of the scheduling for you but you would need to be able to send the file back to yourself through some other email or storage API. Hope this helps :)

  • @terristhompson9860
    @terristhompson98602 жыл бұрын

    Bump