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. - Наука
"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.
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.
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
@@PatrickAlphaC HA! So true. Well it is definitely different and different is refreshing! I just subscribed. Looking forward to more!
Best async explanation in the burger loving world!!!
🙏🙏🙏
Usually i dont understand any of the programming video but this is by far the greatest explanation video ive ever watched
One of the greatest explanations of Async in RUclips.
You’re the man. 13 second code down to half a second. Thank you
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!
Thanks for the comment!
That was an AWESOME tutorial mate. Subscribed!
One of the best asyncio tutorial!!
Thanks much Patrick!
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.
hot dog
you have a skill for making tutorials very engaging. I didn't zone out for a sec
Yay :)
Glad it was helpful!
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.
ty fren
Dude this is the most amusing programming tutorial I've seen in a while! Good stuff, you've got some acting skills
Glad it was fun and educational hehe
@@PatrickAlphaC I wish you made the whole course on that stuff
Oh Dude, I would love to see more tutorials done in this style! Super entertaining!
really enjoyed the part where you shuttle between two pans to check if its done and in the process explaining the purpose event loop
Glad that was helpful!
I might make this video again...
Ayo this is the best clip I have ever witnessed about making api calls faster, props to u my man!!
Much obliged friend
Very informative. The cooking analogy was gold!
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
Good luck!
@@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.
didnt even zone out once, loving this....SUBSCRIBED
Ty Fren :)
i was having a hell of a time understanding async coding and this video really helped. Thank you! Take my sub :)
For more enquiries, reach out⬆️⬆️⬆️..
Great video Patrick! I wonder if you would make similar ones for threading, multi-processing and comparison of all concurrency features.
wonder i completed 17mins tutorial without getting distracted. Great way of keeping audience on focus :)
Fantastic video dude, please share more advanced tips for Python like this!!
For a tricker topic Very Clearly Explained.
Thanks brother once again.
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.
Hey Man, Thanks for the video.
using Tasks is a super duper and important way
Really loved this explanation!
I can't click enough on 'like' button. Thanks, your video was amazing!
It`s been less than 1 min of video and I already want to subscribe to his channel. Done.
this is the best tutorial i've watched on youtube. Surprisingly enjoyable for my pea brain
Glad you enjoyed fren :)
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.
Loved the tutorial. Thanks 👍
your video solved my issue! thanks! highly appreciated
Let's gooo!!
Wow! This is revolutionary technique in teaching how to code, to be honest it is better than the best tutorials here. Keep it up.
Glad it’s fun fren :)
For more enquiries, reach out⬆️⬆️⬆️..
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😂
the video really cool and fun. and the code examples are really helpful. Thank you!
Really Well explained and love the cooking. Subscribed. Very Fun to watch.
the best tutorial on the internet, ever
Who says programmers aren't funny? Great Vid!
you have nailed it !!!!
keep it up.
Best teacher i've ever seen. Really impressive
Glad it was helpful!
i'm so glad I found you.. Awesomeness !!
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!
Perfect!!
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?
this kind of guide, is life-altering. just amazing, man.
Great explanation, thank you!
It would be good too if you mention your learning process to grasp different topics
This is a HUGE part of it
ruclips.net/video/IS5dAkFSo_Y/видео.html
Loved the video and the enunciation!
good quality video right there. Synthetic and well explained. Good job man
Appreciate it! It’s a pretty tricky topic, so glad to hear it makes sense
Dude please more more more where have you been my whole coding life.
I'm flattered beyond reason
This is greatest. I bow in front of you Sir!
Thank you .. this changes everything
I had to stop the video, to like and comment on this amazing explanation.
Thank you!
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
It’s a kind of magic! Thank u!!!
I watched many videos and read the docs but understandid the best from you
Glad to hear it :)
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?
Really amazing, so well explained and funny
This is exactly what I was looking for. Thankss a ton
Beautiful!
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 :}
I didnt come here looking for an amazing channel. but here we are
😍😍😍
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'.
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)
@@jeffreylim5920 yea that's what he said lol...
Yes we need await before get_task(session)
Patrick great job. I didn't skip even a second till end. I request you to make more interactive videos on python.
Glad you enjoyed, and I can do that!
Your channel is going to blow up. Amazing explanation, keep up the good work
“Blow up” I hope you meant ;)
@@PatrickAlphaC ofcourse! ☺
Wow thank you so much Patrick
12:19 I just ran the exact same code, it says RuntimeError: Event loop is closed. Win11,python 3.10.5
Thank you for making this concept so straightforward!
This video makes me hungry and smarter at the same time.
yes
amazing way of explanation with nicely chosen examples , you have a great teaching style man
Appreciate it! Hope it was helpful
Thank you! This is exactly what I needed. Great tutorial
Oh man what a fun video. You have definitely earned a sub mate!
Thank you!
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!!!
Cooking example was on point lol
Glad you enjoyed
I like your energy and humor
I like you liking it
Got a new subscriber. Awesome
Hello, how can we add rate limit in the aiohttp requests using the gather method?
Very good! :) Thank you!
Thanks! I subscribed :D😁
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?
It was very useful thanks dude
Boom!
Thanks for sharing ..
Thank you bro for video so useful
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?
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?
@@PatrickAlphaC oh yeah thanks!
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
You'd have to do a lot more conditionals in the code 😅
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.
No, that would be confusing, considering the topic of the tutorial. A step-by-step (keep it simple) approach is preferable.
having that issue now
Great video my friend, await more_videos_please
Appropriate joke !
this was awesome 🔥
thank you so much for this great video ❤️🔥😇
🔥🔥🔥
great explanation
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.
I call you on your Ordinary Sausage "ta da!" Well played
As a c++ guy, I can seriously appreciate this
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
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
The right terminology of *task is called spread instead of dereferencing. @ 15:36
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!
Glad this is what helped it click!
literally i don't feel like i am learning ASYNC, just feel like watching any comedy show..
hmm... thanks for the feedback
@@PatrickAlphaC you really make asyncio easy for me thanks
@@nonesubham oh ahahha
Very clear and concise tutorial. Love it!
The Best Video About AsyncIO I've Ever Seen! Thanks Man!
Glad to hear it!
nice. thanks for this
Thank you !!
Man this video is Amazing 👏 I learned all about asyncio module in Python because of you Thank you 🙏
Awesome!! Glad it helped
Top explination.