Hello and welcome to Python Bytes, Python news and headlines delivered directly to your earbuds.
I'm Michael Kennedy.
And I'm Brian Okken.
We're here to share the Python news with you and basically share the cool stuff that Brian and I found for the week.
Brian, you know what I think is cool?
That I can open up, I can basically go to any Python object or module or even function or whatever and just say,
tell me what is in you, dir this thing, and out pops all of its capabilities, mostly anyway.
Yeah, I love that.
Do you know what REPL stands for?
REPL?
REPL.
Read Val Print Loop.
Just what you get when you type Python.
Yeah.
Like most of the time now, the only time I open that is to try out something little or to actually to use the dir command.
You know what?
I do do that as well.
I'm like, I'm going to open this up and just do a dir here.
Okay.
Back to work.
Yeah, exactly.
Just to look at the interface for something.
So I was excited to see a new project from Leica 9M on GitHub called pdir2.
And when you use it, so it's pdir2 when you're installing it.
But when you use it, it's just pdir.
And it's just a replacement.
And it's cool because it's all colorized and it splits it out and splits it up into one line per item.
And it pulls the dock string out of each item so that you can see that.
And for what I'm using it for, when I pull up the REPL, it does what it should do automatically.
And I like it.
Yeah, it's cool.
I mean, it's kind of like if you typed help a thing, but it gives you meaningful stuff even if there's no real help to be had.
And it'll categorize things like, here are all the classes.
Here are all the functions.
Here's the stuff that I have no idea what it is, but it's also there.
So we'll put it over here.
And if there's dock strings, it'll put the dock strings there for like, here's the description of each thing.
It's really nice.
Yeah, and it does, it like puts all the dunder functions out of the way so those aren't in the middle of everything too.
Yeah, yeah, those land in the other.
Yeah.
Anyway, it's just, it's part of my repertoire now.
I'm going to, I'm never going to let it go.
One of the things I would like to ask somebody to do is to help out with the project and convert the README to whatever that other thing is.
Restructured?
Yeah, restructured so that it looks good on PyPI because it's in, the README is in Markdown.
And PyPI still doesn't like Markdown.
I wonder, did you look at it on PyPI.org?
No, I haven't.
No.
Versus the older one?
It's worth looking at that one.
I have no idea what it'll look like there either, but that's the new one.
Maybe it understands Markdown.
Who knows?
I would also like to recommend that people pair this with PtPython.
Do you know PtPython?
I don't.
Oh my God.
PtPython is awesome.
Like I don't use the REPL very much.
Everyone knows I love PyCharm and I kind of live there.
But when I do go into the REPL, it really annoys me that I need to completely type everything that is there.
That it doesn't autocomplete.
Especially when I'm exploring something new, which is like why we said often we go into the REPL.
Well, PtPython is basically, I think it's a little bit based on Emacs, but it's like a different version of the REPL that has code completion and a little bit of a UI over the terminal.
It's really nice.
So these days, if I want Python, I type PtPython.
Okay.
Well, I'll have to check that out.
And just to let people know, I did.
Okay.
So I'll take back that request because I looked it up on PyPI.org and it looks great.
It even has that animated GIF on there.
Oh, yeah.
So there's a little animated GIF that shows you how it works, which is quite cool.
So, yeah, check out this project.
It's easy to use.
The one thing to notice is you've got a pip install peter2 versus peter, but then the module's just pdir, right?
So there's a little bit of a nomenclature funkiness, but it is cool.
You know what else?
Go ahead.
I just want people to remember that.
And speaking of memory.
Speaking of memory, absolutely.
So this has happened to me once in my life.
I have not used these tools to solve it.
But here's the deal.
Like, suppose that you somehow, through probably your fault, but it could have been like a hard drive failure or something, somehow you've lost your source code.
So there's a guy who was using a source control wrong and wiped away all of his files off of his directory.
But he still had the program running in memory.
It was a Python program.
So he used two really interesting packages that I'd never heard of.
Had you heard of these?
No, I haven't.
One of them is Pyrocyte, like parasite, but for Python, P-Y-R-A-C-E.
And the other one is un-compile 6.
Because apparently it's one of the few that supports both Python 2 and Python 3, and multiplication is awesome.
So un-compile 6.
So the idea is with Pyrocyte, you can attach to any running Python process.
And you basically get this REPL, like we were talking about, to just explore its memory, to see what its values are.
You can even, like, force it to load other scripts and run them.
You can go to, like, an in-memory, like, singleton object and, like, work with its data.
All sorts of stuff you can do in real time while it's still running around.
That's pretty cool.
So basically what he did is he said, all right, I'm going to hook up to it with Pyrocyte.
I'm going to force the thing to load un-compile, and I'm going to call un-compile on itself and get my code back.
Wow.
But mostly the core.
It worked.
Yes, it worked.
There are people, there's, like, a whole bunch of people.
It's a, I get a gist.
At the bottom of the gist, they're like, oh, my God, I just had to try this because I couldn't believe it would work.
Oh, that's so awesome.
Yeah, it works.
I think there's either a video or a little GIF that is just, like, that basically shows you how it works if you go to Pyrocyte.
Pyrocyte.com, which that's the coolest takeaway for me on this whole one.
That's awesome.
Good job.
Cool.
Yeah.
All right.
You know what I think?
You and I were on a mission, right, to make sure that Python is modern Python, not legacy Python, right?
Yes, definitely.
And I was really surprised.
They're still adding quite interesting and new data types to Python 3.
Even stuff that's been around for a little while that I just haven't, like, heard of.
Because of this show, I've learned about the simple namespace as a, wait, no, that's not it.
The name tuple class, the capitals.
But let's get into this.
There's an article called New Interesting Data Types in Python 3.
And it just goes through three that I really like.
And the three types are types.mappingproxytype, types.simple namespace, and typing.namedtuple.
And the mapping proxy type is, like, really cool.
It takes, like, something like a dictionary.
Or it says, I can't think of anything other than dictionary.
It says it only takes mapping types.
Yeah, it's really cool.
But it's, like, a read-only dictionary, basically, right?
Yeah.
So you take a normal, like, maybe a normal dictionary.
And, like, if you had an API or something, you wanted to expose that dictionary through the API,
you could wrap it in this mapping proxy type and return that.
And I tried it out.
And so, for instance, one part of your project could use the mapping proxy type version and read everything.
And the part of your system that can have, that still has write access, that is synchronized.
So it isn't a copy.
You can, when one part writes to it, it gets updated in the other place, too.
Oh, it's like a view into an existing dictionary, huh?
Yeah, it's a read-only view.
Sweet.
So that's nice.
And then not too long ago, I started using where I really wanted classes or something.
And I was using things like tuples or lists where there really should have been something more structured.
I've been using the lowercase named tuple.
Right, out of the collections names, out of the collections module, right?
Yeah, out of collections.
And there is this thing in types called types.simple namespace that uses a similar sort of functionality.
You can just, if you define a type to be that type, you can just, the parameters when you instantiate it,
those just become elements inside the object.
It's pretty convenient.
Yeah, that's cool.
So you can do a little more organization.
And then, of course, the typing.name tuple class is really nice.
I hadn't been using it.
I've always just used collections.name tuple.
But I think I'm going to be switching.
Now, one word of caution, I suppose, is a lot of these are, they require pretty modern Python.
Some of the techniques they show require 3.6.1.
Like, 3.6.0 is not enough.
So just be aware that some of these require pretty new versions.
Yeah, and that's, I guess, it's hard for me to remember because I'm usually trying to stay.
I don't go into the in-development Python, but I try to use the latest released one.
I do as well.
You know where that bites me, though?
Is on my DigitalOcean servers.
It's running the version of Ubuntu that only has 3.5.2 or something like that.
So if it's literally a 3.6 feature, I'll put it in my app and I'll ship it like, oh, it doesn't work.
What was I thinking?
Yeah, and I forget that.
That 3.5 is really, for version 3.x, 3.5 is being used more than 3.6 right now.
Yeah, just because of the distributions, I think.
In my mind, that's like the minimum bar for 3.5 stuff is 3.5.
Yeah, okay.
But I think these are great things to start adding to your repertoire.
If you have control over where it's going to run, those are good things.
Yeah, and some of them come from like Python 3.3 or 3.4.
They're fine.
There's just a few techniques there that are brand new.
And what I like about this, one of the things I like about this article is it's pretty short
and it gives examples of how to use these pretty concisely.
So that's good.
Yeah, very nice, very nice.
Speaking of how do I use things, wouldn't it be awesome if I could just go to my Bash shell
and just type, how do I and type a thing?
Like I'd like to say, maybe I want to know how to print a stack trace or trace back in Python.
I could say, how do I print stack trace Python and just type that?
Yeah, that'd be cool.
It'd be cool if my computer knew that, right?
Well, it turns out we ran across a project called How Do I?
And if you install How Do I, if you pip install it, it will give you instant coding and shell answers on the command line.
So I can say, how do I connect SQLAlchemy?
And it'll give me the Python code to connect for SQLAlchemy.
I can say, how do I Python save dictionary?
That's three words.
And it'll show me how to use the JSON load s dump functionality right there in the command line.
Now, sometimes it gives me like a stupid answer.
Like if you type that, how do I Python save?
How do I Python load JSON?
It just shows you JSON, which is stupid.
But you can do a dash A and it'll give you all the answers it's found on the internet related to that.
Usually somewhere in that list is something decent.
It has some sources like Stack Overflow and I don't know where they all come from, but they're all over the place.
It's cool.
I can say, how do I debug Python?
It'll show me the PDB commands.
I can say, how do I change my path in macOS?
And it'll show me how to do that, assuming I'm running Bash.
Things like that.
Okay.
I'm going to try that.
Yeah.
How do I put a worm on a hook?
Exactly.
Yeah, it doesn't work.
Yeah, it's got to be something technical, I think.
There's another one that I want to point out that I thought was really funny,
but actually it's kind of useful.
Oh, what's that?
It starts with a command.
It actually starts with a cartoon.
And basically the idea is if you type in a command that you think you know on the shell,
but you get it wrong, you can curse at your shell and it will potentially fix it for you.
Yeah, I love this.
So this thing is called the F.
I'm not going to complete it so we can keep our clean rating in iTunes,
but the link is in the show notes.
And basically you type that after you've made a mistake on the shell and it goes,
oh, you probably meant this.
Are you trying to do this get checkout branch thing?
You did a little bit wrong.
The F.
Oh, here's the command.
Enter.
And it'll just automatically fix it for you.
It's beautiful.
Yeah, nice.
So plus you get a little, yeah, you get to let some frustration out on the thing, right?
Yeah.
All right.
What you got for us?
What's next?
Oh, yeah.
I got to go back to that tab.
We have a, yeah, we're at a listener.
So, you know, it just seems like we just did the last episode.
Just a few days ago.
How did that work?
That we had a listener commented on the last episode.
Last episode, we did mention some feedback from a listener about async speeding up their
some work.
And we have another one from a comment this time.
And this is a project that a listener shared with us.
And we've got a link in the show notes.
But it's a project called PyMarsis.
And I wasn't familiar with eMarsis.
It doesn't really matter.
But it's a cloud-based CRM.
And it's a Python interface.
But I'll just read this.
The gist of it is it sped it up.
And this is from Diego.
Thanks, Diego.
Another awesome episode.
Thanks, Michael and Brian.
And if you say that we do something awesome, we'll totally put you on the show.
Okay.
About async.io being awesome.
I had my own experience.
I had to send information to about 100 information about hundreds of thousands of users to a CRM
through their public API daily.
And with the synchronous stuff, it would have taken 50 hours a day, which you can't do that.
And they added async.
And it went down to 20 minutes.
So that's 150 times faster, which is awesome.
Yeah.
They were using requests before.
And in order to update their CRM, it took 50 hours per day problem.
So they switched to the AIo HTTP client stuff that has async and await in 20 minutes.
In fact, he told us an interesting story.
He said, the first time I ran it, it opened so many connections that it crashed his Mac.
And so he actually had to implement a semaphore limiting system, which is pretty cool.
Yeah.
And I did like that he added that, that he added the semaphores.
But the GitHub link that he had put up, I didn't see any semaphore usage in there.
So I've also, in our show notes, linked another article that talks about using asynchronous I.O.
with semaphores to limit how many connections you're making.
Yeah.
No, thanks, Diego, for putting that up there.
Anybody who wants to have a comment on the show, you know, you can contact us on Twitter where we're at, Python Bytes.
But also, every episode has a discuss section at the end.
So if you want to talk about an episode, share a link or whatever, drop in there.
So what's the link for this episode?
Pythonbytes.fm slash 18.
Yeah, yeah.
There you go.
Cool.
Yeah, it's super, I made it super easy to find.
And do you know what would be super easy is if somebody would make an easy way for me to do a pyramid installation.
That's right.
Because, so the way I made that slash 18 work, and you can still go to like slash episode slash list or whatever, is I use constraints in the routing infrastructure.
And so one of the things that I've been doing a lot of work with lately is with building pyramid web apps and trying to really help people jumpstart what they're up to, right?
Like I can go to pyramid and create a web app, and I get basically a web app that runs, and here's the view function, and here's a template.
Go.
Go write the web app from scratch.
And I kind of wanted to help the world not start from scratch, but start from near the end.
So I've been doing a lot with cookie cutter.
More on that later.
But I decided to create a cookie cutter template that is an opinionated cookie cutter template for creating pyramid web apps that have most of what you need pre-built and pre-configured.
And factored the way you would for a large professional app, not for like a one-file starter thing.
Yeah, that's great.
So I created a cookie cutter thing called cookie cutter dash pyramids --talk Python starter.
And so this came out of my Python for Entrepreneurs course, but you don't have to have anything to do with that to play with this template.
So what you do is it comes out with like when you just say create the website, it'll create like a shared layout.
So there's one place where all your general navigation and look and feel goes.
It has handlers for class management.
It has like secure user management using things like pass lib and other techniques, bootstrap, logbook, rollbar integration, MailChimp integration, outbound, email integration, power for static file management.
All just the list goes on and on.
But it's very much closer to where you need to be for a professional pyramid app to get started, in my opinion, rather than like basically here's one file.
Now create the whole thing from scratch.
So if people want to check that out, that's on GitHub.
You can just cookie cutter space the GitHub URL and you're off to the races.
It needs a little bit more documentation.
I'm going to work on that this week, but it's really close.
But it's a good start and I'm actually pretty excited about it.
And you've got one, your course is one of the very few that I've seen that really teaches people how to do pyramid as well.
Yeah, thanks.
Yeah, it's definitely one of the few ones on pyramid, which is great.
So here's like one more resource.
Basically, this is going to be part of the end of that course.
And, you know, the first time I heard about cookie cutter, I really kind of thought it was a little silly.
But it's actually turning out to be quite a useful tool for a lot of spaces.
Yeah, I definitely.
Yeah, the more I use it, the more I like it.
So I've definitely been putting some effort into it.
It's great.
Well, that's the end of our six.
So do you have anything to share with us, Michael?
No, nothing.
Nothing other than this template thing.
That's really all I have to share.
I've been just cranking on my classes.
I hear that you're probably still writing on your book.
That's getting close, though, isn't it?
Yeah, it is.
It's getting a lot closer.
And I wish it was closer than it is.
But I've got a whole bunch of...
Actually, I'm kind of overwhelmed with both work and with gratitude.
That I've had a lot of great people, incredible programmers and good writers help me out with
technical reviews on the first four chapters and a lot of great feedback.
And now I've got to go rewrite everything.
Thanks a lot, guys.
Thanks a lot.
No, that's awesome.
Yeah, I'm looking forward to the day where we can announce your book on here.
That'd be great.
Any day now with that book, huh?
No, any...
Hopefully, the goal still is to have something to sell by PyCon.
Beautiful.
All right, well, thanks, Brian, for sharing your news.
And thank you, everyone, for listening.
We'll catch you next week.
All right, thank you.
Thank you for listening to Python Bytes.
Follow the show on Twitter via at Python Bytes.
That's Python Bytes as in B-Y-T-E-S.
And get the full show notes at pythonbytes.fm.
If you have a news item you want featured, just visit pythonbytes.fm and send it our way.
We're always on the lookout for sharing something cool.
On behalf of myself and Brian Okken, this is Michael Kennedy.
Thank you for listening and sharing this podcast with your friends and colleagues.