Async application classes vs. functions
Ғылым және технология
To function or to class?
According to the spec, an ASGI application is an async callable, but when we use FastAPI, Starlette, or other ASGI frameworks, that callable is hidden in plain sight. In this video, we see how it's possible to use an application class instead of a literal async def function, and we go over reasons for preferring the class approach.
― mCoding with James Murphy (mcoding.io)
Source code: github.com/mCodingLLC/VideosS...
ASGI Spec: asgi.readthedocs.io/
SUPPORT ME ⭐
---------------------------------------------------
Sign up on Patreon to get your donor role and early access to videos!
/ mcoding
Feeling generous but don't have a Patreon? Donate via PayPal! (No sign up needed.)
www.paypal.com/donate/?hosted...
Want to donate crypto? Check out the rest of my supported donations on my website!
mcoding.io/donate
Top patrons and donors: Jameson, Laura M, Dragos C, Vahnekie, Neel R, Matt R, Johan A, Casey G, Mark M, Mutual Information, Pi
BE ACTIVE IN MY COMMUNITY 😄
---------------------------------------------------
Discord: / discord
Github: github.com/mCodingLLC/
Reddit: / mcoding
Facebook: / james.mcoding
Пікірлер: 14
I really love your videos! I started watching back when you mostly did short Python and C++ videos, and watched them even though I knew most of it already, mostly because of the clear way you presented things, and it allowed me to gain an even better understanding of it. Thank you! EDIT: Now, you increasingly cover topics that are a bit new to me, but you cover it so well that I immediately understand. You're a great teacher!
Are you by any chance writing a book about python or creating a course? I would 100% buy anything that was created by you.
@mCoding
2 ай бұрын
I don't have any plans to write a book or make a course at the moment, my consulting business keeps me quite busy! But thank you for saying so, I appreciate your support, and I'll keep it in mind for the future.
thank you!
nice video
Where is the better place to store a database connection: as a global variable or as a member variable of the application object ?
@doctor_py42
3 ай бұрын
You mostly won't use ASGI directly, but I think you should use a connection pool (for example sqlalchemy comes with one already) and get a connection from it when you need it. Since requests would be performed concurrently you can't use single connection (most dbs, e.g. postgres don't support performing multiple operations concurrently on a single connection).
Letsgoo
That was... Fast 😢 But stick to your plan if you think this is better! Though I really enjoy your godlike videos and wish it was a little bit longer😅
fIsrt!
Why so many ho-bots here only 12 minutes after the video went live? sigh.
@chriskeo392
3 ай бұрын
Leave my GF alone!
I thought you were joking when you said "thanks for watching..." But no 🥲