- Podcasts
- Python Bytes
- #279 Autocorrect and other Git Tricks
About this episodeTopics covered in this episode: OpenBB wants to be an open source challenger to Bloomberg Terminal Python f-strings JSON Web Tokens @…
- OpenBB wants to be an open source challenger to Bloomberg Terminal
- Python f-strings
- JSON Web Tokens @ jwt.io
- Autocorrect and other Git Tricks
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#279 Autocorrect and other Git Tricks
Great Brians think alike. That's right. That's the saying. Brian Skin, welcome. It's great to have you here. You are now completing the trifecta of podcasts, I understand. Yes, indeed. I was on a panel for Talk Python and an episode of Test & Code a little while back. And excited to be here for Python Bytes.
Yes. You've been a big contributor in terms of sending topics our way. So it's only fitting that you're here. Tell people real quick about yourself before we jump into the topics. Sure. I'm a chemical engineer by training. I am not actually a software dev by day. I have a PhD in chemical engineering.
I've been working for the last 10 years or so at a company here in Dayton, Ohio, Faraday Technology, working on electrochemical process R&D. So there's a lot of science there, some programming, mostly for data analysis, things like that. But I also have done quite a bit of Python on the side in the documentation area and various things like that.
So excellent. Cool. Chemical engineering is pretty awesome. And it's great to have someone here who's not a straight software developer. You know, we get a lot of myopic views and I think you'll have some interesting perspectives. Hope so. Yeah. I hope so as well. I'm sure. Now, before we kick this off, I want to say this episode is brought to you by Datadog.
Check them out at pythonbytes.fm/Datadog. We'll talk more about them later. Right now, Brian, maybe we could talk about f-strings. What do you think? Yeah. I mean, I love f-strings. I use them all the time. But I was like really thought it was cool. There were a couple of new resources that I kind of wish I had had earlier.
This one, a couple, they're new. So we've got from Florian Bruin. And he's hugely helpful to getting, doing the code review or book review and code review and all that stuff on the pytest book. So I definitely want to shout out to him for thank him for doing that. Yeah. But so he generated this Python f-strings.
It's called f-strings.help. And it's just like it's a Jupyter Notebook looking thing. I think he created it with Jupyter Notebook. But it just quickly goes through all of the formatting stuff of f-strings. And there's a little bit of explanation, but it just sort of exactly shows you what the syntax is and what the output is really concisely.
This is a nice, nice run through of the F-string features. Yeah, that's cool. Well, it looks like if you were trying to either learn Python strings or trying to help someone learn Python strings, you could just send them this and go, here, scan this. You'll be good to go. What I like about it is just the terseness as well.
So this is a decent reference to Bookmark for looking things up. The other thing I wanted to point out was an article called Python f-strings are more powerful than you might think. And that's exactly kind of the gist of it. It's more discussion. It doesn't, I mean, it does sort of tell you what they are, but it kind of assumes you already know.
But some really cool things like date and time formatting, using it for debugging with variable names. We've talked about that on the show. Taking advantage of string representations. There's even embedded, I didn't know you could put f-strings inside of f-strings. So there's part nested f-strings, they call it.
So interesting stuff here. Yes. Yes. So, yes. Nested f-strings. I had no idea. I didn't either. I've totally done that before. Really? Totally. Yeah. Templating one thing to then template into another thing. Absolutely. It's super helpful. Nice. Very cool. So, yeah. Yeah. It's easy to forget that you can apply the standard, I guess, string.format type of operators.
Like colon, 0.3F or colon, comma to put digit grouping, but in f-strings, right? Because it's, I don't know, it feels more like you're working with a variable than you are with a format character. I mean, short examples like this of, here's a cool thing you can do with, you know, even a well-established basic feature like that can really help people go, oh, hey, that's just what I need.
And run with it. Yeah. Very nice. Oh, this is great, Brian. I love it. Now, are we ready to move on? Yeah, definitely. Cool. All right. I kind of want to blow your mind with this thing here. You've probably heard about Bloomberg terminals. So, if you're in the investment space, like if you work at a hedge fund or an investment company, especially in Manhattan, you know, you'll sit down and you'll see like these six monitor crazy setups that would make gamers jealous, you know, around them.
And look at what's going on here. And one of the tools they use a lot is this thing called the Bloomberg terminal that lets them look at all kinds of different visualizations and real-time instant updating things around the stock market and whatnot. That is a commercial project that, best I can tell.
I mean, there's probably discounts or whatever, but it costs around $2,000 per user per month, which is a non-trivial amount of cost, right? I mean, no wonder we're all getting like little percentages of money sucked out of our 401k retirements because all of those people are like paying that much money to like manage our accounts.
Yes, exactly. So, I want to introduce you all to OpenBB at OpenBB.co. This is the equivalent thing, but several interesting aspects. One, it's open source. Two, it's free. That's cheaper. It's cheaper. It's not necessarily the most important thing, but it also gives you access to all sorts of tools that we know and love from Python, especially on the data science side.
So, this OpenBB thing is this terminal type thing you can install. It's really got this sort of weird blend of like CLI. I know Will McGugan would be super impressed with all of its like terminal UI, its TUI aspects. But then it also pops open interactive windows that are like graphs and all those kinds of things.
We'll pull up some examples in a minute. So, you get access. It's not just that it's free, but you get access to all the Python data science stack. And it is itself created in Python. So, pretty cool. It's pretty popular. It's got 11,000 GitHub stars. And what you do is you show up at this terminal.
And there's even an interactive live version. You can have dark mode or not dark mode turned on the website. I mean, I love it. This is really a polished thing. And you can type things like stocks. If you could spell stocks, you could type stocks. And it'll come up with all these ways that you could explore them.
If you could type BA and it'll come and give you these things. And eventually, if you get to the right spot, it doesn't happen on the website. But it'll pop up these extra windows that then like let you explore things with graphs and so on. So, very, very cool. Let's pull up some of the terminal things here.
And look at the features. Where are the features? So, you can install it through its own installer. You can install it through Anaconda. Or you can run a Docker image of it to get it to run. So, it's sort of summary is Python-based integrated environment for investing research that leverages state-of-the-art data science tools and machine learning technologies.
That's astonishing. Yeah, it really is pretty astonishing. And like the things just keep coming. So, if you just keep scrolling through this, there's such a way to like to understand how is the economy doing. Apply AI predictions to like GDP and all sorts of wild stuff. So, it's this really crazy blend of terminal TUI plus pop open a bunch of data science explorations.
Very cool. Thank you. And tested with pytest. Oh, my goodness. Yeah. So, that's awesome. Anyway, I am super impressed with this. It's an open source project based on Python sort of democratizing a lot of these things. And if that wasn't enough, I think here's one more sort of side story that I think is interesting.
So, I'm sure you two have seen, you go, it's not as common as it used to be, but you go to some open source project or some application and says, buy us a coffee. Help make that next feature happen. This one has a different banner at the top instead of coffee. It says, we've just landed our $8.5 million seed funding round and we're about ready to get started.
I mean, that's some kind of crushing it for open source, isn't it? Yeah, definitely. That's a lot of coffee. That is a... They're going to be so jittery. Just like the stock prices. Exactly. Look, so much fluctuation. Oh, no, no. That's just me. It's actually very still. Maybe that's why stocks go up and down so rapidly.
Too many traders and too much coffee. Yeah. That's probably actually true. Anyway, I think this is a really cool Python application. It looks well done. It looks pretty modern. And yeah, it just looks like a neat way to apply some data science to investing. Do you have a sense of the learning curve?
Is it mainly directed at investment professionals or is there an on-ramp for casual use? If you look at their description, it does seem to be focused on a casual use case here. Let me see. It says, a terminal built by the community, Shape Artes. Where did I see this? Somewhere. I can't remember where I ran across it.
But they do talk about sort of like individual investors getting access to the tools that the companies, the people at the big banks and hedge funds would have. So it does sort of seem to be aimed at that. And my experience is it's pretty easy to use. I don't know. It's easy to understand the output, right?
That's more of a investing economics problem, though. That's a perpetual problem. Yeah. Yeah. Yeah, indeed. All right. Well, people can check this out if it sounds interesting to them. Brian Skin, what you got for us? So my first item is PyProject.com and PEP621 for project metadata and PyProject.com coming to set up tools.
Because that, you know, for things to get uploaded to PyPI, if you want to have information about dependencies or, you know, various other things like that. If you have the metadata specified statically, it's much easier to get to. It's you can trust it more. And so, the PEP, you know, it's how it's defining how to put project metadata in PyProject.com how to tell the build tools like build or flit.
What is a static defined in declaratively in the metadata and what's dynamic that is going to be provided dynamically later on. And a number of tools had implemented PyProject.com support. Things like flit, hatch, PDM. Not poetry yet, though they're discussing it. But setup tools was still missing it.
So, if you had a setup.cfg with an array in it, setup tools actually had to take that as a string representation of an array and then arrayify it. By executing it basically. Instead of the Tumble where it actually knows it as a, a, an array in a table. But in any event, Anderson Bravo Harry has just within the last month or so, I think it was, finished an experimental implementation of pep621.
In setup tools. There was a discuss thread seeking feedback from the community. Try it out. Yeah. Report bugs. I tried it on one of my projects and it mostly worked. I actually turned up a bug that Anderson fixed super quickly where I do dynamic long description, which turns into the readme for, you know, for the PyPI page.
And so I dynamically do a replace on the docs branch for those links. Well, aren't you a special butterfly? I have complicated needs. It's, I'm sorry. But, you know, so I, you know, I have that set up and it broke and I reported it and he fixed it. So, as far as I can tell, you know, it's, it may, it may be experimental and it probably will change, especially some of the issues around specifying dynamic, metadata.
More progress on the pyproject.toml stuff. Definitely. Very cool. Now, before we move on, let me tell you all about our sponsor this week. Datadog. They've been supporting the show for a really, really long time. Datadog is great. They have a real-time monitoring platform that unifies metrics, traces, and logs into one integrated system.
Their APM empowers developers and teams to identify anomalies and resolve issues and improve application performance. So you can begin collecting stack traces and visualizing them as flame graphs and organizing them into profile types, such as CPU or IO types of reports. Teams can search for specific profiles and correlate them into distributed traces and identify slow or underperforming code for later analysis and optimization.
And with Datadog's APM live search, you can perform searches across the full stream of ingest traces of your app over the last 15 minutes. Like, I need to figure out what the database is doing and the API and the front end and all those things. So try them for free with a 14-day free trial and Datadog will send you a free t-shirt.
So just check them out and support the show by visiting pythonbytes.fm/Datadog or just click the link in your podcast player show notes to get started. Nice. Indeed. All right. Ryan, what do you got next? I've got Git. So this isn't necessarily Python only related, but I use Git a lot and I didn't know you could do autocorrect with Git.
So this is Wayland Walker. I think he's been submitted other things to us on the show. But he wrote this article called configure Git to autocorrect your fat fingers, you know, or just your sloppy typing. So there's this, like, let's say you do Git checkout dev, but you spell checkout C-H-E-K-O-U-T and misspell it.
Well, Git will, like, tell you that you did it wrong and it guesses what you meant and tells you. This is a similar command as this. But there's a configuration option that I didn't know about called help.autocorrect that you can set a timeout and it just automatically runs the command it thinks you wanted.
Git reset-dash-hard. Oh, yeah. That one actually would be kind of destructive. That would be bad. But I, so I realized that I added this to my workflow, but I realized that I hadn't really talked about my workflow at all on my blog. So I went ahead and just showed the things that I do normally for a quick change.
I usually check out main, do a poll, then create a branch with checkout-b. And then I commit, I usually do commit-a-m with a message. I want to talk about these, that one a little bit, the dash-a, and then also push because I want that to be faster. So the dash-a, what that does is, that's that push.
If I delete something, I want that to change. So the dash-a does that. I just learned about that recently. Oh, interesting. So you can basically skip the git add dot. Yeah. Or something equivalent to that, or the git add file names. Right. And the add dot is a little dangerous because it'll add everything, the unstaged stuff too.
So if you have temporary files or, or just play, you know, you get a test file or a goofy file that you're just playing out with. I don't want to add that stuff. I, I intentionally add things that I want, or I mean, add, what's the other one? You know, uncommitted things. I don't usually want to add that.
So the dash-a is nice that it doesn't do that. And then the last thing that I did was the global, there's another configuration change of global push dot default current. So weird. But what this does is that the current, there's a bunch of values for that. I'm going to have a link to the other show notes and the other, the documentation about all the different values in the show notes.
And you can do it with push. You can do a dash you in push to make it automatically do that, but it's just for both. And I always wanted to do that. So anyway, that's, that's my new get workflow for simple stuff. I love it. Very nice. Yeah. I really liked that, that, that current having to do that, all that extra typing, even with autocomplete is just annoying.
Yeah. So, yeah. Brian S. It sounds like you use get a lot. What's your view of source control from a chemical engineer perspective? Like in that ecosystem and that, that environment, how do people view this kind of stuff? they don't basically, I mean, you know, it, it, anyone who's, who's familiar with with the, you know, much development probably uses it.
Some, actually there's a 3d physics modeling, multi-physics modeling tool, console that just added a, source control like feature into it. So it's, it's starting, you know, the data reproducibility and the history tracking has started to become more of a thing. but yeah, it's, it's very often the, you know, V2, V3, 2020.
2020. V3, V3. V3. Final. Final. Final. Yeah. Yeah. So, I mean, you know, I have, you know, I have blog posts churning about strategies for, version control on, data analysis code. because of the reproducibility and needing to, to, to track environments precisely for reproducibility at a point in the past.
Indeed. Okay, cool. Alvaro points out at work, they have a project with 6,000 lines of, in an INI final that INI might be just what they need. That sounds like, that sounds like a lot. You definitely have to, you know, you have to, you have to proof them afterwards because, you know, there, there may be some stuff that doesn't, translate cleanly, but yeah.
Yeah. We need a Toml to INI and if you can round trip it and it's the same, then you're good to go. Yeah. Don't know if that'll work. Keep your sanity. All right. This next one's a quick one for me, but it'll be useful for people who are working with JSON web tokens. So JSON web tokens are a thing that you can exchange with maybe a distributed login system.
So instead of using like an API key that you just pass around all the time, you could say, I'm going to either share a certificate or somehow log into some other system and I'll get back this token that I can share on to other places to communicate who I am, communicate what roles or permissions I should be granted and so on.
So if you work in that world, you work in a world of dealing with cryptographic signatures and picky algorithms and stuff like that. So I just wanted to give a shout out to JWT.io. So this is a place that allows you to decode, verify and debug JWTs. It's pretty cool. So you come down here and what you do is you put in some encoded token and you say, which algorithm of the encryption algorithms are using.
And then what pops out is the separated JSON result that says, here's the header. It says what algorithm and what type it is, what version of JWT and so on. And then what the actual data was like, this person is a subscriber. Their name is John Doe. I shouldn't scroll it because it doesn't seem to work.
And while you're at it, there's somewhere in here, the libraries, you can say, see the JWT libraries. And let me make that smaller ish. So the way it shows, it's a little bit weird. It has the technology and then a whole bunch of checklists. And then if you go down to the bottom, you can see the actual package name.
So like there's a bunch of .NET ones here. Don't care about those. But the Python ones are down here and says, who's created them, right? Like CMO source or Michael Davis. And then this one's called Python Jose JW crypto or PI JW. And it shows you which algorithms are supported and how it works and so on.
So I think this is pretty cool if you're going to work with these things. What do you think? I don't have a lot of expertise with authentication and tokens of this sort. How is this different from something like macaroons where it's more like an advanced cookie? Is this separate from the browser or?
And basically it allows you to do single sign-on and federated sign-on across different platforms without just taking and using straight cookies. Okay. So it works both for APIs and for other types of apps. You can do it within an app or with an API. So like if I call an API, if I log in with me and I call an API and I want to communicate onto my identity onto the APIs that API is calling.
I have a new project I'm calling Jupyter Temphars. So one of the really powerful things about, you know, Jupyter notebooks are great. You can do a whole lot with them. They're obviously being used everywhere, data science, scientific analysis. And one of the features of at least the Python kernel of Jupyter is that you have a global namespace that you work in.
And this really adds to the power of it in some ways because everything you do in the notebook flows from one cell to another. You don't have to worry about shuttling things back and forth. But, you know, as has come up, you know, countless times here and elsewhere, you have namespace contamination problems where you accidentally assign something in one cell and then you foot on yourself because either, you know, you use something and have it.
Have a typo and accidentally use something from another cell or something's lingering on and you have the same variable name in multiple cells. And all of a sudden, you know, you close down for the day and start back up and the whole worksheet blows up. And so what I put together is a notebook extension for Jupyter.
And then in this cell, I've got as a context manager tempvars, and I declare to it, all right, anything, this syntax says anything that starts with T underscore is going to be treated as a temporary variable. And so when I run this, the first line is checks to see if T underscore A is in the namespace, and it's not because it's inside the temporary variables context.
So that's using the underlying library. But what I did, it's like, you know, okay, fine, it works, but you have to have this whole thing that you type out, and it's cumbersome. So what the Jupyter plugin, the Jupyter extension does is it lets you, you can turn on this toolbar for tags for each cell, and then if you define, go away.
Then if you define a tag with this syntax, you can also do a tempvars end, but here tempvars start T underscore. Now, this variable will automatically be treated as a temporary variable. It's no longer in the namespace when you execute the cell. And what it's doing behind the scenes is it's actually taking the code, patching the execute functionality for the cell, and wrapping it in a tempvars context manager behind the scenes, so that anything you use in here, T underscore, is a temporary variable.
I love it. Yeah. Animated to boot. So readme has the user's instructions. It's on PyPI, just a pip install, Jupyter tempvars, and then I have a shortcut script to actually install the extension into your Jupyter environment. I have a number of features that could be added to it, different things that the underlying library could have added to it.
Yeah. Yeah, nice work. This looks great. Those are good. Yeah, the problem of having variables shared across those things when you didn't intend them to be, so tricky in so many ways. I mean, Jupyter cells are like go-to statements with no traceability, right? Because you could run them down, then you could go back and run the one in the middle again, and then you could go run another.
They're the worst. All right. Real-time follow-up. Brandon Brainer, former co-host here, says, this is talking about going back to why JWT over something like cookies. So imagine having something like auto zero when you log, maybe auth zero. When you log in, it gives you back this JWT, which has a timeout.
The front end has this. It can send it to your API. And then also it has the signature that verifies it wasn't tampered with. And you can verify the sender because you can decrypt it and stuff like that. Okay. Better chain of custody. Okay. All that tricky cryptography stuff. Speaking of other things, extra things, you guys got some extras we should cover?
I have a few, actually, some quick ones. All right. Bring it on. So we've got GitHub issues are finally live. So their Python issues are now on GitHub. We didn't jinx it this time. It really is there. So enough said. I was, you know, I've used lorem ipsum before. I think everybody doing front end stuff has.
But I didn't know. There's a cool page like lorem ipsum.com that has a translation. So you can read what it means. At least a 1500s, 1914 translation. So it's sort of an interesting read. I won't get into it here, but it's worth a read if you're curious. And then one of the things we do sometimes at the end is funny stuff.
And one of the things we've covered is various O'Reilly covers. So I found this Dev2 O'Reilly cover generator. I didn't know where it was. Somebody had. Oh, nice. And you can just make up your own. So I made one up. Passed it around last night. So it's kind of a fun thing. Yeah. I pulled that from the show notes and passed it on to my friends.
And it's this idea to bring some of the Py ENV virtual environment features to Windows. I haven't really played with this, but I guess some of the features there for the virtual environments don't work on Windows, but his sort of plug-in script does. So you can check that out, which I think will be helpful for some people, for the Windows people.
They also, there was a posting for an infrastructure engineer to assist with the facilities that the link now 404s. So maybe they've made their hire. I don't know. But the posting was there and now it's not. And then actually in the steering council notes released for March, there is beginnings of discussion about hiring a second developer in residence, which would be terrific.
So anybody who is interested, submit, submit, submit. Nice. And then, and then one interesting tidbit relevant to, you know, we have to talk about Pydantic at least once, I think. Right. Along with Anthony Shaw and Wilma Guggen. This was a couple of days ago. Samuel Colvin of Pydantic fame posted this somewhat cryptic tweet here showing over a tenfold increase in speed or some sort of Pydantic features here.
The Pydantic unicorn. No, that's great. All right. I got no more extras, but I have some jokes. Yay. Bring them. All right. I think this first one might be from you, Brian Skin. Is that right? Yeah. I can't. You want to tell us this joke here? Give us this one. Yeah. So it's a riff off of the various elements of a business enterprise trying to bring a product to a customer that's what they actually want.
And on the right, it says user needs. And it has a cat peeking up out of a cardboard box. Exactly. Slightly over designed, would you say? Just a bit. And, you know, I think there was somebody responded to that. There's a tweet lower down saying, this is exactly my life. I have an untouched, you know, cat tree in the corner and all the cat sits in is the box.
So. This is also true for children. A lot of times the box is the best part. Definitely. All right. I brought two more for us just because they're both, they're all short and I thought this would be fun. So here's one that says junior developer. How did you find the bug so fast? And it has a senior developer who has this sort of lion meme.
I was there when it was written. Lion witch and the wardrobe reference there, I think. I think so. All right. And then this one really, I really appreciate this one. So there's two sort of time-lapsed Google search pages with text overlaid on it. And it says 831 C++ hello world. 833 alternatives to C++.
There's so many new things coming on. It, it was fairly stagnant for like, like decades. And then, but in the last 10 years, there's been a lot of new changes. I feel like I've, I've read people griping that they're making C++ too much like Python or something. Adding, I don't know exactly what that means, but, but.
