I was never a big fan of poetry, since I tended to manage my environments mostly with just pip. Poetry just didn't provide enough value by itself for me to justify deferring my environment control to it. However, the pure speed of UV initially attracted me to it, but the new features are likely to convert me to fully (or close) buy-in to the ecosystem.
Great video! UV is indeed an awesome tool! Actually I was so impressed by the speed that I started learning rust. Using UV multiple months already. In GH actions and local environment. But with -system flag now I am thinking about trying it in a dockerfile, since some of them take a while to install all deps.
@@JakeCallahan easter egg? will check the video one more time anyway to learn the features :) the primary goal of using rust was rewriting my python handlers in aws lambda since the language is really fast and might significantly decrease execution time especially in warm starts
I'm interested to know what you all think about uv? Personally, I'm going to be moving more of my work projects over to it in GitHub actions and hopefully our CI environments as well.
I don’t follow how it knows you are trying to match type to p_type instead of trying to create a variable called p_type with a value of type from your dict…
Wow!! Another great tutorial Jake. I am really enjoying your teaching style, the choice of content/examples and the difficulty level you choose of your examples. I do have a query about this, though. I am not sure but guessing that, async operations run on a single process, like threading. So, suppose if I have a piece of program that downloads data from a website using multiple request which is IO intensive, cleans that data using advanced feature engineering techniques which are CPU intensive, and then stores that cleaned data into a DB, which again will be a IO task, then I would be needing asyncio, threading and multiprocessing in one piece of code. Is there some literature like blogs, books, video tutorials or articles you could direct me towards that could help when building such software as there is going to be a great degree of overlap and interaction between all three packages. Also, is the assumption that async operations run on a single process, correct? Can I make them run in parallel in multiple processes? I know a google search would do the trick, but I am guessing you will share much better resources than what google would. But again, excellent tutorial!! Cheers and Kudos!
That is one of the main challenges when dealing with concurrency, determining which method to use based on the situation you're in. One way you could potentially deal with the mix between IO and CPU tasks is to break the CPU bound task into a separate process that would then "consume" the results from the async process as they come in. However, this does introduce potential challenges around race conditions, so using locking mechanisms (file write locks) are typically key to lessen that risk.
@@JakeCallahan Yes, I concur with the arguments made. I did in fact manage to build the thing I was looking for. I'm pretty sure it's not optimised, but it does the task, so decently satisfied. One great learning was, cause I had to breakup my functions/classes based on the task i.e. IO or CPU, it forced me to reflect and introspect about my architectural design and in the process forced me to think deeply and understand more about the inner workings of the language. This felt like an excruciatingly difficult exercise, but the results do justify the grind. And your tutorials have been more than helpful. Thank you once again for them! Extremely grateful.
Perfect! We learn a ton when writing new projects. So much so that it's one of my top recommendations for someone newer to programming or a new language. Glad I could help
Another great tutorial! Awesome work Jake. I just thought it's a bit uncomfortable to write -t in front of every topping we want to pass, and hence searched the documentation. Unfortunately, click by default has no help for passing multiple args while writing the option name only once. But I think a custom class/function and some clever str manipulation can do the trick. Other than that, I feel click is a great tool for every python programmer to have. Do you have some custom class to handle such scenarios? I think it'll relatively easy to build one. I am guessing we could even use a namedtuple object for this. Cheers and Kudos!
One of the easiest ways to solve this problem is just to make your users specify multiple items in a comma separated list. --toppings cheese,bacon,onion Then you just split that string on the commas and handle the individual values.
Man, this is really cool behaviour. namedtuple can be a great alternative to dataclasses when we want our class to implement just some basic functionality. Just curious about this though, can a namedtuple inherit from multiple namedtuple? Like if I have a RGB namedtuple and a A namedtuple, and I want RGBA to inherit from both, I can just use the ._fields attribute of both in defining the RGBA namedtuple class. Is there some downside to this? Or maybe bad programming practice? Should I expect to run into some error later? But yeah, great tutorial Jake. Absolute gold!! Cheers!!
Thank you very much! That's a great question, and something I've not personally tried. However, you should be able to combine the fields of two parent named tuples (maybe run through a set() to de-dupe fields), then use that for the child.
Hi Jake, excellent tutorial. I absolutely love your content on youtube. It feels like a crime to be able to learn this free of cost. Anyways, Im guessing you already know this, but we could use the python's inbuilt map method with the ThreadPoolExecutor like executor.map(func_name, list_of_args) . It just feels a bit more readable. That way we could just loop over the futures object to get the results and not use the .as_completed() method, assuming the func_name function returns something. Cheers and Kudos!!
Thank you very much. You're definitely definitely correct that using map is anither easy way to do this, especially for those that are more used to functional programming
@@JakeCallahan Just something I realised about the map method. It returns the future objects in the order they were started and not in the order they finish. It might be helpful to someone who also cares about the order in which threads finished, incase the result is being passed on to someother function/class for which order matters.
What is the best way, to go around the external API limitations? I want to get all data from the API, yet it yields only 10 data point, and a nextPageToken. So I tried to flood it with multiple calls, but it simply stooped sending data for a while. So I guess, the way to go is to do the initial check for 10-30 data point, and pass the flow of the program two ways, one for interaction with the user, and displaying those first data point, and second, which will continue gathering the data in the background. For now Im using asyncio and aiohttp, but now I wonder, should I use threading as well, as a way to split those tasks?
If the pages need to be requested sequentially, then there aren't many good options, assuming the next page requires the token from the current page response. Many APIs do let you set a larger size for responses per page, but if this one doesn't, then they are likely trying to limit their resource usage. If that's the case, then the responsible plan would be to follow their design and go slow. With that in mind, even if all of the above were true, if you have other non-sequential requests that runs against this (or other) API, then you can run those tasks concurrently. The first challenge is figuring out what can actually be done concurrently.
The team and community has done a great job with uv since then. It is now my daily driver for package management. I'll need to do an update video sometime soon.
I haven't formally put down a list yet, but it would certainly include aiohttp after requests. Things like pytest might have their own sub-series. I will give you a hint about the video I'm putting notes down for now, it includes a number of patterns (relatively) newer to Python.
Hi! Subscribed. "Understanding Python" is a great series. Much better then what I watched when I started learning python. The best for python refreshing.
I was wondering if there are any particular benefits to writing class-based loggers. Also, how to do them 'right'... Would love to see something on that subject.
A lot of thanks for sharing your knowledge, dude! In the 2nd example when you're getting prime numbers I didn't know that way to test if a number is prime or not (what's its name?), so I coded the classical and academic definition of primes, and when I ran it, what a surprise, 20 min., 25 min., not finished, and I question myself WTF I'm doing wrong: so when I was washing my clothes, I realized it, the classical definition is making an absurd and vast amount of divisions when testing a number prime. I reviewed the code and looked for the best optimized prime testing until a video that explains a RU-vid channel called GeeksForGeeks, which is exactly like yours but coded differently (your code is also testing negative numbers which is good), and finally I kept following your explanation and I was much glad to remember that feeling of getting stuck by a task and resolving with my own effort plus your video and the other sources. ¡Saludos desde México, estimado!
The best thing about your videos is the fact that you actually show some situational samples from your previous experiences in code. I have not noticed any teacher (except a few, perhaps) in RU-vid do this. This REALLY sets your content apart. Appreciate it.
By the way, I do not know if you have ever covered it or not, but I would love to see your technique of designing and implementing custom exceptions for a general application (that is fairly complex and huge). How do you handle their respective logs? How do you decide what information to expose to the clients using the application as logs (may be in the terminal or a separate log file) and what to send to a more dev-centric log file (if any)? How do you tackle exceptions arising due to another exception in logs? Also, (this is more opinionated, I suppose) do you find the use of things like Liskov's Substitutions within Exceptions reasonable (and why)?
These are all great questions, most of which are answered in one of my pet projects at work: github.com/SatelliteQE/broker. In that project, you can find the custom exceptions I use and how logging is handled when in different log levels. Another interesting thing I've introduced with this is an "Emitter" class that can be used for a more structured log-like file that can be more easily consumed in CI environments. github.com/SatelliteQE/broker/blob/master/broker/helpers.py#L269 Now regarding LSP, I'm not very strict when it comes to adhering to most paradigms, if the situation you're in requires some kind of deviation. With that said, my exception subclasses are typically very lightweight.
Dependency resolution is NP hard I don't care how performant their resolver is they can't get around this. The future of all package management is nix-like where the dependency graph is explicit so there is no dependency resolution problem. Checkout the video: "Nix: What Even Is it Though?" from Burke Libbey for a good talk explaining how it works. People should stop wasting time implementing a bad architecture better, bite the bullet and invest their time in packing for Nix / GUIX.
Great tutorial! I must say after getting in touch with Go, TS/JS and now Rust I appreciate more and more the genius of Guido to develop really user friendly language.
Great video! Espessially the inheritance part! One more way to construct named tuples is to inherit from typing,NamedTuple. Similar to dataclasses this method allows to add type hints to the attributes.
Since rust based products like warp terminal and zed editor, as well as uv and ruff are kinda hype right now, it is definitely worth it to take a look at the language. Looking forward to learn rust at this channel!
Hey there. Yeah I've been crazy busy but am hoping to get back to making videos in June. As far as PyO3, I'll let you in on a spoiler for one of the things that kept me so busy... pip install hussh
I don't believe Pyscript has plans to directly support notebooks. However, I do know that notebooks will have a completely in-browser version (if not already) that runs on Pyodide.
Great catch! The reason this still works, and wouldn't if the inverse were true, is that Python is passing the meta class as the first positional argument. So while this is decorated with staticmethod, there is no real effect on the behavior since Python itself is the consumer. We can verify this by looking at the output at 18:09