Python Asyncio, Requests, Aiohttp | Make faster API Calls

Ғылым және технология

#python #asyncio #aiohttp
Python, asynchronous programming, the event loop... what is all this stuff?
We learn what python is doing in the background so we can make more API Calls faster. We learn how to go from requests to aiohttp in our code, and refactor code for asynchronous programming.
✍️Medium Post: betterprogramming.pub/python-...
⌨️ Code: github.com/PatrickAlphaC/asyn...
✅✅ Donate ✅✅
I use donated funds to spend money on making fun & informational videos.
ETH Wallet address: 0x9680201d9c93d65a3603d2088d125e955c73BD65
😸😸Join the community!😸😸
Chainlink developers discord: / discord
Alpha Chain discord: / discord
Twitter: / alphachainio
Twitter (me): / patrickalphac
Medium: / patrick.collins_58673
Twitch Stream Uploads: / @patrickalphac-alt
Twitch: / patrickalphac
All thoughts and opinions are my own.

Пікірлер: 340

  • @saminyead1233
    @saminyead123310 ай бұрын

    "An event loop is when we let some stuff that takes a long time do it's thing in the background. And when it's all set, the 'event loop' will 'pick it up'." is the most helpful and intuitive definition of event loop I've heard.

  • @ubaidulkhan
    @ubaidulkhan3 жыл бұрын

    Best async explanation in the burger loving world!!!

  • @PatrickAlphaC

    @PatrickAlphaC

    3 жыл бұрын

    🙏🙏🙏

  • @werthersoriginal
    @werthersoriginal3 жыл бұрын

    I really enjoy the fast-pace and the humor of your tutorials. Keeps me from zoning out. You've got a gift for making these tutorials both informative and enjoyable.

  • @PatrickAlphaC

    @PatrickAlphaC

    3 жыл бұрын

    Appreciate it! I’m trying to find the right style. I get some people saying they hate it, and others love it. Guess time will tell ahah

  • @werthersoriginal

    @werthersoriginal

    3 жыл бұрын

    @@PatrickAlphaC HA! So true. Well it is definitely different and different is refreshing! I just subscribed. Looking forward to more!

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

    One of the greatest explanations of Async in KZread.

  • @apexlex1634
    @apexlex1634Ай бұрын

    You’re the man. 13 second code down to half a second. Thank you

  • @sleepyimsomx354
    @sleepyimsomx35429 күн бұрын

    Usually i dont understand any of the programming video but this is by far the greatest explanation video ive ever watched

  • @davidkorn5253
    @davidkorn52532 жыл бұрын

    you have a skill for making tutorials very engaging. I didn't zone out for a sec

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Yay :) Glad it was helpful!

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

    6:12 You could turn any synchronous (i.e. thread-blocking call) into an async one using the to_thread() function available in asyncio with Python 3.9 and later.

  • @PatrickAlphaC

    @PatrickAlphaC

    Жыл бұрын

    hot dog

  • @venkatramachandran6345
    @venkatramachandran63452 жыл бұрын

    Incredible. Thank you so much. In the middle of a development that has 300,000 inevitable API calls. Let me check how it works. Again, Thank you

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Good luck!

  • @venkatramachandran6345

    @venkatramachandran6345

    2 жыл бұрын

    @@PatrickAlphaC Processed 320k API with 100 APIs at a time. Out of 320k, 91 got connection error (404). When I rerun the remaining APIs, it worked. How to avoid this connection failure? It looks like a common issue in asyncio but dont see proper fix.

  • @nam4574
    @nam45742 жыл бұрын

    I really really like this tutorial!! You made it really funny and enjoyable. Never had such a fun programming tutorial on youtube :D Keep going!

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Thanks for the comment!

  • @padraic1983
    @padraic19832 жыл бұрын

    That was an AWESOME tutorial mate. Subscribed!

  • @kapilsonyt
    @kapilsonyt2 жыл бұрын

    One of the best asyncio tutorial!! Thanks much Patrick!

  • @903vulture
    @903vulture Жыл бұрын

    Dude, you have an amazing way for teaching things that in another way would result boring and complex. You've won a new and loyal subscriptor from Uruguay.

  • @PatrickAlphaC

    @PatrickAlphaC

    Жыл бұрын

    ty fren

  • @FaizanUlHaq-mf3zt
    @FaizanUlHaq-mf3zt3 ай бұрын

    didnt even zone out once, loving this....SUBSCRIBED

  • @PatrickAlphaC

    @PatrickAlphaC

    3 ай бұрын

    Ty Fren :)

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

    Oh Dude, I would love to see more tutorials done in this style! Super entertaining!

  • @bravitheja1142
    @bravitheja11422 ай бұрын

    wonder i completed 17mins tutorial without getting distracted. Great way of keeping audience on focus :)

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

    really enjoyed the part where you shuttle between two pans to check if its done and in the process explaining the purpose event loop

  • @PatrickAlphaC

    @PatrickAlphaC

    Жыл бұрын

    Glad that was helpful! I might make this video again...

  • @vadim921
    @vadim9212 жыл бұрын

    Dude this is the most amusing programming tutorial I've seen in a while! Good stuff, you've got some acting skills

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Glad it was fun and educational hehe

  • @vadim921

    @vadim921

    2 жыл бұрын

    @@PatrickAlphaC I wish you made the whole course on that stuff

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

    Very informative. The cooking analogy was gold!

  • @vickysharma9227
    @vickysharma92272 жыл бұрын

    For a tricker topic Very Clearly Explained. Thanks brother once again.

  • @evanfonseka5520
    @evanfonseka55202 жыл бұрын

    Ayo this is the best clip I have ever witnessed about making api calls faster, props to u my man!!

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Much obliged friend

  • @paulovinicius5833
    @paulovinicius58332 жыл бұрын

    It`s been less than 1 min of video and I already want to subscribe to his channel. Done.

  • @Woeden
    @Woeden2 жыл бұрын

    Fantastic video dude, please share more advanced tips for Python like this!!

  • @asimkhan-ko6ew
    @asimkhan-ko6ew10 ай бұрын

    Best video on aync I have ever seen. It is just like Tom cruise movie, you have to stick till end, twist may come any moment. Who knows😂

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

    Wow! This is revolutionary technique in teaching how to code, to be honest it is better than the best tutorials here. Keep it up.

  • @PatrickAlphaC

    @PatrickAlphaC

    Жыл бұрын

    Glad it’s fun fren :)

  • @kovychchat__my_Teleqram_id

    @kovychchat__my_Teleqram_id

    Жыл бұрын

    For more enquiries, reach out⬆️⬆️⬆️..

  • @hypebeastuchiha9229
    @hypebeastuchiha92292 жыл бұрын

    Who says programmers aren't funny? Great Vid!

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

    i was having a hell of a time understanding async coding and this video really helped. Thank you! Take my sub :)

  • @kovychchat__my_Teleqram_id

    @kovychchat__my_Teleqram_id

    Жыл бұрын

    For more enquiries, reach out⬆️⬆️⬆️..

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

    Great video Patrick! I wonder if you would make similar ones for threading, multi-processing and comparison of all concurrency features.

  • @mattmaximo8716
    @mattmaximo87162 жыл бұрын

    this is the best tutorial i've watched on youtube. Surprisingly enjoyable for my pea brain

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Glad you enjoyed fren :)

  • @yerielkim327
    @yerielkim3272 жыл бұрын

    Best teacher i've ever seen. Really impressive

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Glad it was helpful!

  • @vickysharma9227
    @vickysharma92272 жыл бұрын

    Hey Man, Thanks for the video. using Tasks is a super duper and important way

  • @nassehk
    @nassehk7 ай бұрын

    Loved the tutorial. Thanks 👍

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

    i'm so glad I found you.. Awesomeness !!

  • @damiyagondha7153
    @damiyagondha71532 ай бұрын

    Really loved this explanation!

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

    I can't click enough on 'like' button. Thanks, your video was amazing!

  • @ahmed-samer
    @ahmed-samer Жыл бұрын

    Great explanation, thank you! It would be good too if you mention your learning process to grasp different topics

  • @PatrickAlphaC

    @PatrickAlphaC

    Жыл бұрын

    This is a HUGE part of it kzread.info/dash/bejne/e4dpxqOkdrbVj7w.html

  • @peterwoo2718
    @peterwoo27183 ай бұрын

    the video really cool and fun. and the code examples are really helpful. Thank you!

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

    Really Well explained and love the cooking. Subscribed. Very Fun to watch.

  • @Nikki713100
    @Nikki7131002 жыл бұрын

    the best tutorial on the internet, ever

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

    Came back to this when exploring MEV and monitoring the chain for certain txs. All the code I've seen uses JS and async/await so was curious on implementing it in python.

  • @stro3277
    @stro32772 жыл бұрын

    your video solved my issue! thanks! highly appreciated

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Let's gooo!!

  • @127.
    @127.3 жыл бұрын

    Finally understood how to implement asycio. Very well explained. You not trying to get everything correct in first attempt and giving errors so viewers can understand why it gave error was something very educational in this video. Subscribed.

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

    Patrick great job. I didn't skip even a second till end. I request you to make more interactive videos on python.

  • @PatrickAlphaC

    @PatrickAlphaC

    Жыл бұрын

    Glad you enjoyed, and I can do that!

  • @jeffreylim5920
    @jeffreylim59202 жыл бұрын

    Two things to remember when to use await. 1. You have to await to register the task to the event loop. 2. You have to await the coroutine to return the 'real response'.

  • @jeffreylim5920

    @jeffreylim5920

    2 жыл бұрын

    The first job takes significant time, and this is why 11:27 method only diminished 4 seconds. (13s -> 9s) So when we do registering job all at once, it saves time and we could enjoy enormous time gain. (13s->1s)

  • @carterreynolds5649

    @carterreynolds5649

    Жыл бұрын

    @@jeffreylim5920 yea that's what he said lol...

  • @zmaktr

    @zmaktr

    Жыл бұрын

    Yes we need await before get_task(session)

  • @kareemmahlees3597
    @kareemmahlees35972 жыл бұрын

    I watched many videos and read the docs but understandid the best from you

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Glad to hear it :)

  • @eugenmalatov5470
    @eugenmalatov5470Ай бұрын

    Really amazing, so well explained and funny

  • @h8handles
    @h8handles2 жыл бұрын

    Dude please more more more where have you been my whole coding life.

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    I'm flattered beyond reason

  • @idlenoodle2385
    @idlenoodle23853 жыл бұрын

    I didnt come here looking for an amazing channel. but here we are

  • @PatrickAlphaC

    @PatrickAlphaC

    3 жыл бұрын

    😍😍😍

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

    This is greatest. I bow in front of you Sir!

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

    I had to stop the video, to like and comment on this amazing explanation.

  • @PatrickAlphaC

    @PatrickAlphaC

    Жыл бұрын

    Thank you!

  • @smitjainsj
    @smitjainsj2 жыл бұрын

    you have nailed it !!!! keep it up.

  • @BillThornton-pm4hd
    @BillThornton-pm4hd9 ай бұрын

    Thank you .. this changes everything

  • @luxeave
    @luxeave2 жыл бұрын

    this kind of guide, is life-altering. just amazing, man.

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

    This video makes me hungry and smarter at the same time.

  • @PatrickAlphaC

    @PatrickAlphaC

    Жыл бұрын

    yes

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

    As a c++ guy, I can seriously appreciate this

  • @filippov_es
    @filippov_es2 жыл бұрын

    It’s a kind of magic! Thank u!!!

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

    In in the version 2 of your code you have remove the print statments for printing out the each 60 symbol and print is an i/o bound job which indeed reduces the execution time but i am sure with print statment included the execution time gonna be better that the version 1 thanks awsome job :}

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

    Loved the video and the enunciation!

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

    Wow thank you so much Patrick

  • @rolandandrews7518
    @rolandandrews75183 жыл бұрын

    good quality video right there. Synthetic and well explained. Good job man

  • @PatrickAlphaC

    @PatrickAlphaC

    3 жыл бұрын

    Appreciate it! It’s a pretty tricky topic, so glad to hear it makes sense

  • @danielhidefjall5060
    @danielhidefjall50602 жыл бұрын

    I like your energy and humor

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    I like you liking it

  • @ishikadav1708
    @ishikadav170810 ай бұрын

    hi, i really loved the tutorial! thanks so much! one question- i have created a different python file, where you use requests, and have imported that to my main file. however, the loop is in my main file. do i add 'async with aiohttp.ClientSession() as session:' in my imported file, and add async def where my loop occurs?

  • @AD-cw1ny
    @AD-cw1ny2 жыл бұрын

    This is the best coding tutorial ever! Before finding it i was wondering what half of these things are. Now it's all clear, just like that! Thanks!

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Perfect!!

  • @redjinnee2008
    @redjinnee20082 жыл бұрын

    Great video my friend, await more_videos_please

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Appropriate joke !

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

    Dude , thank you for the video , you made this so easy for me to understand how asyncio works , before I could not even begin to understand this concept

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

    Great video. would be even better if you could also show how to control number of parallel requests. Uncontrolled parallel requests will trigger dos attack protections and block your further requests.

  • @Lorant1984

    @Lorant1984

    Жыл бұрын

    No, that would be confusing, considering the topic of the tutorial. A step-by-step (keep it simple) approach is preferable.

  • @oakae326

    @oakae326

    Жыл бұрын

    having that issue now

  • @user-up1xf2lq4y
    @user-up1xf2lq4y2 жыл бұрын

    I'm trying to understand how throwing tasks in an event loop by create_task in tasks list then gather the results(17:02) differs from just executing all tasks at once by gather method(16:38). It seems that gather method not only throws tasks in an event loop but also it executes and waits to be finished(?) so only difference from the two example is that whether you registered the tasks manually by adding create_task or just get them all done by gather method? Did i get it right?

  • @ziyiyang4550
    @ziyiyang45502 жыл бұрын

    Thank you for making this concept so straightforward!

  • @jbusmoove
    @jbusmoove7 ай бұрын

    Got a new subscriber. Awesome

  • @Tntpker
    @Tntpker2 жыл бұрын

    Cooking example was on point lol

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Glad you enjoyed

  • @rns10
    @rns1011 ай бұрын

    okay you are better than chatgpt.

  • @45234523452345
    @452345234523457 ай бұрын

    Thanks for sharing ..

  • @sheracore9190
    @sheracore91902 жыл бұрын

    It was very useful thanks dude

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Boom!

  • @galichandreyschool
    @galichandreyschool2 жыл бұрын

    Very good! :) Thank you!

  • @yerkebulanzhaukenov138
    @yerkebulanzhaukenov1382 жыл бұрын

    Thank you bro for video so useful

  • @mafirus
    @mafirus2 жыл бұрын

    I'm a full-time JS web dev, and I was wondering recently what was the python approach of Promise.all() Thank you so much, this is great content!!!

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

    great explanation

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

    cool I m leraning python the cooking is best analogy

  • @SaishShettytgroxx
    @SaishShettytgroxx2 жыл бұрын

    This is exactly what I was looking for. Thankss a ton

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Beautiful!

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

    so great! love from China

  • @safeer786ful
    @safeer786ful3 жыл бұрын

    Your channel is going to blow up. Amazing explanation, keep up the good work

  • @PatrickAlphaC

    @PatrickAlphaC

    3 жыл бұрын

    “Blow up” I hope you meant ;)

  • @safeer786ful

    @safeer786ful

    3 жыл бұрын

    @@PatrickAlphaC ofcourse! ☺

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

    Hello, how can we add rate limit in the aiohttp requests using the gather method?

  • @Whoosh12345
    @Whoosh123452 жыл бұрын

    Thank you! This is exactly what I needed. Great tutorial

  • @sevashpun
    @sevashpun2 жыл бұрын

    Thanks! I subscribed :D😁

  • @jamesyinbaare
    @jamesyinbaare6 ай бұрын

    The right terminology of *task is called spread instead of dereferencing. @ 15:36

  • @AR-fh2uh
    @AR-fh2uh2 жыл бұрын

    I call you on your Ordinary Sausage "ta da!" Well played

  • @fuad471
    @fuad4712 жыл бұрын

    amazing way of explanation with nicely chosen examples , you have a great teaching style man

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Appreciate it! Hope it was helpful

  • @sahabtariq4039
    @sahabtariq40392 жыл бұрын

    give that man a cookie.

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

    This was a fun one!

  • @rkiacnhg
    @rkiacnhg2 жыл бұрын

    nice. thanks for this

  • @spencerphill8115
    @spencerphill81156 ай бұрын

    Great video, my only question would be is, how would you make it async if each time you made a call the url changed and there were headers involved in making the api request? Headers being content type and authentication

  • @PatrickAlphaC

    @PatrickAlphaC

    6 ай бұрын

    You'd have to do a lot more conditionals in the code 😅

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

    Great video...can you kindly explain how to get the candle data of the symbols in a dataframe/s...thnx

  • @i701Dev
    @i701Dev2 жыл бұрын

    Oh man what a fun video. You have definitely earned a sub mate!

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Thank you!

  • @dientu10
    @dientu102 жыл бұрын

    Well well well, to make tasks happen simultaneously, put them into an even_loop, just simple principle that i only understood after this video. The tutorial surprise my brain. Thank you!

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    Glad this is what helped it click!

  • @BaronXOfficial
    @BaronXOfficial2 жыл бұрын

    What if I wanted to create an asynchronous task Loop that executes as tasks are added to it? Say if I am receiving calls from a Discord bot which will access an API and I want to handle those requests asynchronously rather than executing a predefined set of API calls? Additionally, how would I return those results to the original functions which called them? Is that something which is within the purview of aiohttp and asyncio?

  • @goodlack9093
    @goodlack909313 күн бұрын

    that's actually good!

  • @h00t-h00t
    @h00t-h00t10 ай бұрын

    Amazing stuff ❤❤

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

    literally i don't feel like i am learning ASYNC, just feel like watching any comedy show..

  • @PatrickAlphaC

    @PatrickAlphaC

    Жыл бұрын

    hmm... thanks for the feedback

  • @nonesubham

    @nonesubham

    Жыл бұрын

    @@PatrickAlphaC you really make asyncio easy for me thanks

  • @PatrickAlphaC

    @PatrickAlphaC

    Жыл бұрын

    @@nonesubham oh ahahha

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

    funny yet educational!

  • @onijadissanayaka6190
    @onijadissanayaka61902 жыл бұрын

    wow I leaned how to make a burger while cooking beans : )

  • @PatrickAlphaC

    @PatrickAlphaC

    2 жыл бұрын

    That was the real take away

Келесі