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