Python Asyncio, Requests, Aiohttp | Make faster API Calls

Поделиться
HTML-код
  • Опубликовано: 19 апр 2021
  • #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.
  • НаукаНаука

Комментарии • 337

  • @saminyead1233
    @saminyead1233 9 месяцев назад +25

    "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.

  • @werthersoriginal
    @werthersoriginal 3 года назад +100

    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 года назад +8

      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 года назад +2

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

  • @ubaidulkhan
    @ubaidulkhan 3 года назад +32

    Best async explanation in the burger loving world!!!

  • @sleepyimsomx354
    @sleepyimsomx354 18 дней назад

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

  • @ermalgashimramori
    @ermalgashimramori Год назад +13

    One of the greatest explanations of Async in RUclips.

  • @apexlex1634
    @apexlex1634 Месяц назад +1

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

  • @nam4574
    @nam4574 2 года назад +7

    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!

  • @padraic1983
    @padraic1983 2 года назад +2

    That was an AWESOME tutorial mate. Subscribed!

  • @kapilsonyt
    @kapilsonyt 2 года назад

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

  • @lawrencedoliveiro9104
    @lawrencedoliveiro9104 Год назад +11

    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.

  • @davidkorn5253
    @davidkorn5253 2 года назад +18

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

  • @903vulture
    @903vulture Год назад +1

    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.

  • @vadim921
    @vadim921 2 года назад +3

    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 года назад +1

      Glad it was fun and educational hehe

    • @vadim921
      @vadim921 2 года назад

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

  • @Lorant1984
    @Lorant1984 Год назад +1

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

  • @anoopisaac
    @anoopisaac Год назад +2

    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...

  • @evanfonseka5520
    @evanfonseka5520 2 года назад +2

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

  • @billjellesma1371
    @billjellesma1371 Год назад

    Very informative. The cooking analogy was gold!

  • @venkatramachandran6345
    @venkatramachandran6345 2 года назад +3

    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 года назад +1

      Good luck!

    • @venkatramachandran6345
      @venkatramachandran6345 2 года назад +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.

  • @FaizanUlHaq-mf3zt
    @FaizanUlHaq-mf3zt 3 месяца назад +2

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

  • @carterreynolds5649
    @carterreynolds5649 Год назад +1

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

  • @Flyingnobull
    @Flyingnobull Год назад +5

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

  • @bravitheja1142
    @bravitheja1142 2 месяца назад +1

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

  • @Woeden
    @Woeden Год назад +1

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

  • @vickysharma9227
    @vickysharma9227 2 года назад

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

  • @legateau5387
    @legateau5387 Год назад +1

    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.

  • @vickysharma9227
    @vickysharma9227 2 года назад +1

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

  • @damiyagondha7153
    @damiyagondha7153 Месяц назад

    Really loved this explanation!

  • @lucasvazdelima4420
    @lucasvazdelima4420 Год назад

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

  • @paulovinicius5833
    @paulovinicius5833 2 года назад +2

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

  • @mattmaximo8716
    @mattmaximo8716 2 года назад +1

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

  • @127.
    @127. 3 года назад +6

    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.

  • @nassehk
    @nassehk 7 месяцев назад

    Loved the tutorial. Thanks 👍

  • @stro3277
    @stro3277 2 года назад +1

    your video solved my issue! thanks! highly appreciated

  • @RenormalizedAdvait
    @RenormalizedAdvait Год назад +1

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

  • @asimkhan-ko6ew
    @asimkhan-ko6ew 9 месяцев назад +1

    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😂

  • @peterwoo2718
    @peterwoo2718 3 месяца назад +1

    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
    @Nikki713100 2 года назад +3

    the best tutorial on the internet, ever

  • @hypebeastuchiha9229
    @hypebeastuchiha9229 2 года назад +1

    Who says programmers aren't funny? Great Vid!

  • @smitjainsj
    @smitjainsj 2 года назад +1

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

  • @yerielkim327
    @yerielkim327 2 года назад +1

    Best teacher i've ever seen. Really impressive

  • @EekaMau5
    @EekaMau5 Год назад +1

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

  • @AD-cw1ny
    @AD-cw1ny 2 года назад +2

    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!

  • @ishikadav1708
    @ishikadav1708 10 месяцев назад

    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?

  • @luxeave
    @luxeave 2 года назад +4

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

  • @ahmed-samer
    @ahmed-samer 11 месяцев назад +1

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

    • @PatrickAlphaC
      @PatrickAlphaC  11 месяцев назад

      This is a HUGE part of it
      ruclips.net/video/IS5dAkFSo_Y/видео.html

  • @ravindrakakade9859
    @ravindrakakade9859 Год назад

    Loved the video and the enunciation!

  • @rolandandrews7518
    @rolandandrews7518 3 года назад +6

    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

  • @h8handles
    @h8handles 2 года назад +1

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

  • @Kaustubhingale952
    @Kaustubhingale952 Год назад +1

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

  • @BillThornton-pm4hd
    @BillThornton-pm4hd 9 месяцев назад

    Thank you .. this changes everything

  • @malakggh
    @malakggh Год назад +1

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

  • @PrakashReddyK
    @PrakashReddyK Год назад +1

    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

  • @filippov_es
    @filippov_es 2 года назад +1

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

  • @kareemmahlees3597
    @kareemmahlees3597 2 года назад +1

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

  • @user-up1xf2lq4y
    @user-up1xf2lq4y 2 года назад +1

    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?

  • @eugenmalatov5470
    @eugenmalatov5470 Месяц назад +1

    Really amazing, so well explained and funny

  • @SaishShettytgroxx
    @SaishShettytgroxx 2 года назад +6

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

  • @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 :}

  • @idlenoodle2385
    @idlenoodle2385 2 года назад +1

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

  • @jeffreylim5920
    @jeffreylim5920 2 года назад +4

    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 года назад +1

      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)

  • @sujalpadhiyar5731
    @sujalpadhiyar5731 Год назад +1

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

  • @safeer786ful
    @safeer786ful 3 года назад +3

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

    • @PatrickAlphaC
      @PatrickAlphaC  3 года назад +1

      “Blow up” I hope you meant ;)

    • @safeer786ful
      @safeer786ful 3 года назад +1

      @@PatrickAlphaC ofcourse! ☺

  • @dumisanimthethwa4279
    @dumisanimthethwa4279 Год назад

    Wow thank you so much Patrick

  • @dipankardey1044
    @dipankardey1044 Год назад +2

    12:19 I just ran the exact same code, it says RuntimeError: Event loop is closed. Win11,python 3.10.5

  • @ziyiyang4550
    @ziyiyang4550 2 года назад +2

    Thank you for making this concept so straightforward!

  • @Networkprofessor
    @Networkprofessor Год назад +1

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

  • @fuad471
    @fuad471 2 года назад +2

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

    • @PatrickAlphaC
      @PatrickAlphaC  2 года назад +1

      Appreciate it! Hope it was helpful

  • @Whoosh12345
    @Whoosh12345 2 года назад +1

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

  • @i701Dev
    @i701Dev 2 года назад +4

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

  • @mafirus
    @mafirus Год назад +2

    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!!!

  • @Tntpker
    @Tntpker 2 года назад +1

    Cooking example was on point lol

  • @danielhidefjall5060
    @danielhidefjall5060 2 года назад +1

    I like your energy and humor

  • @jbusmoove
    @jbusmoove 7 месяцев назад

    Got a new subscriber. Awesome

  • @leoparrilha1
    @leoparrilha1 Год назад +1

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

  • @galichandreyschool
    @galichandreyschool 2 года назад

    Very good! :) Thank you!

  • @sevashpun
    @sevashpun 2 года назад

    Thanks! I subscribed :D😁

  • @BaronXOfficial
    @BaronXOfficial 2 года назад

    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?

  • @sheracore9190
    @sheracore9190 2 года назад +1

    It was very useful thanks dude

  • @45234523452345
    @45234523452345 7 месяцев назад +1

    Thanks for sharing ..

  • @yerkebulanzhaukenov138
    @yerkebulanzhaukenov138 2 года назад

    Thank you bro for video so useful

  • @user-dx2yp1rk4k
    @user-dx2yp1rk4k 2 года назад

    I didn't quite get it - in your last example, do you wait for all the GET requests first and THEN loop over them? Where does the increase in speed come from in this case? Wouldn't it just be the same as the synchronous approach, since you are waiting for all of the responses first before looping over them?

    • @PatrickAlphaC
      @PatrickAlphaC  2 года назад +1

      I don't wait for all the GET requests to come back, I just send them all.
      I then loop over the get their responses. The increase in speed is because I didn't wait for each to respond when sending the GET requests.
      Does that make sense?

    • @user-dx2yp1rk4k
      @user-dx2yp1rk4k 2 года назад +1

      @@PatrickAlphaC oh yeah thanks!

  • @spencerphill8115
    @spencerphill8115 6 месяцев назад +1

    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 месяцев назад +1

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

  • @anamoly01
    @anamoly01 Год назад +3

    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

  • @redjinnee2008
    @redjinnee2008 2 года назад +1

    Great video my friend, await more_videos_please

  • @ankitbrijwasi9902
    @ankitbrijwasi9902 2 года назад +4

    this was awesome 🔥
    thank you so much for this great video ❤️🔥😇

  • @raghavarahulkalavala1542
    @raghavarahulkalavala1542 Год назад +1

    great explanation

  • @tushar3875
    @tushar3875 2 года назад

    Sir my request is such that, it has to open browser using selenium and then get cookies parameter and then data comes.
    Currently I use concurrent.futures , which send 7 request at once( coz that's what my PC can take) , so it makes it somewhat fast.
    Now if I use asyncio, will it make the code faster? For every symbol browser is opened once.

  • @AR-fh2uh
    @AR-fh2uh 2 года назад +1

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

  • @andyhawaii2819
    @andyhawaii2819 Год назад

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

  • @ParthPatel-jn6io
    @ParthPatel-jn6io 2 года назад +1

    Patrick, Upon doing last task ending at 16:37 minutes. I get connection reset by peer error saying cannot connect to host. I was able to do query API to server till the time we didn't get get_tasks() function defined

    • @PatrickAlphaC
      @PatrickAlphaC  2 года назад

      You probably don’t have an api key from AV. If you get an api key or use another API you’ll be able to get around the limitations, you’re getting rate limited

  • @jamesyinbaare
    @jamesyinbaare 6 месяцев назад

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

  • @dientu10
    @dientu10 2 года назад +2

    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!

  • @nonesubham
    @nonesubham Год назад +1

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

    • @PatrickAlphaC
      @PatrickAlphaC  11 месяцев назад

      hmm... thanks for the feedback

    • @nonesubham
      @nonesubham 11 месяцев назад +1

      @@PatrickAlphaC you really make asyncio easy for me thanks

    • @PatrickAlphaC
      @PatrickAlphaC  11 месяцев назад

      @@nonesubham oh ahahha

  • @SpacebarWarrior
    @SpacebarWarrior 2 года назад

    Very clear and concise tutorial. Love it!

  • @danyalt8221
    @danyalt8221 2 года назад +1

    The Best Video About AsyncIO I've Ever Seen! Thanks Man!

  • @rkiacnhg
    @rkiacnhg Год назад

    nice. thanks for this

  • @DM_MOTO
    @DM_MOTO 2 года назад

    Thank you !!

  • @b391i
    @b391i 2 года назад +2

    Man this video is Amazing 👏 I learned all about asyncio module in Python because of you Thank you 🙏

  • @saidaghzou7064
    @saidaghzou7064 17 дней назад

    Top explination.