- Podcasts
- Talk Python To Me
- #58: Create better Python programs with concurrency, libraries, and patterns
#58: Create better Python programs with concurrency, libraries, and patterns
Talk Python To Me
- May 10, 2016
- 55 min
- Episode 58
About this episodeSee the full show notes for this episode on the website at talkpython.fm/58
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#58: Create better Python programs with concurrency, libraries, and patterns
If you're a data scientist, import pandas, numpy, matplotlib need to be something you type often and intuitively. But then what? Well, I have a few topics for you. This week, you'll meet Mark Summerfield, a prolific author of many Python books. We spend our time digging into the ideas behind his book, Python in Practice, Create Better Programs Using Concurrency, Libraries, and Patterns. What I really like about these topics is that they have a long shelf life.
Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the ecosystem, and the personalities. This is your host, Michael Kennedy. Follow me on Twitter, where I'm @mkennedy. Keep up with the show and listen to past episodes at talkpython.fm and follow the show on Twitter via at Talk Python. This episode is brought to you by Hired and SnapCI.
Thank them for supporting the show on Twitter via at Hired underscore HQ and at Snap underscore CI. Hey, everyone. A couple things to share with you. First, we'll be giving away an electronic copy of Mark's book this week. As always, just be registered as a friend of the show on talkpython.fm. I'll pick a winner later in the week.
Next, I had the honor to spend an hour with Cecil Phillip and Richie Rump on their laid-back, technical but casual podcast, Away from the Keyboard. I really enjoyed the conversation, and I think you'll like their podcast, too. Give them a listen at awayfromthekeyboard.com. Finally, those of you taking my Python Jumpstart by Building 10 Apps course, I have a few improvements for you.
I added transcripts to the player, the website, and the GitHub repository, as well as added some activity tracking across devices so you know which lectures you've watched. I hope you find these additions useful. Now, let's chat with Mark. Mark, welcome to the show. Oh, thank you very much. I'm glad to be on it.
Yeah, I'm super excited to talk about all these great books you've written, and one of them in particular really caught my attention, called Python in Practice, Create Better Programs Using Concurrency, Libraries, and Patterns. And that just really speaks to me on some of the most important parts of sort of design pattern and improving your overall skill, not just focused on libraries, like Flask or something.
Yeah, sure. One of the motivations for writing that particular book was I wanted to write something for people who were already comfortable writing Python, but showing more of the high-level things you could do with Python. You know, if you wanted, for example, to do really low-level networking with TCPIP, you can do that in Python.
It's got the libraries. All the facilities are there. But if what you're more interested in is application programming, you might not want to go so low-level. And Python, either built-in or in third-party libraries, has wonderful facilities for doing high-level stuff, whether it's networking, concurrency, and GUIs, and things like that.
So I wanted to look at some of the facilities that are available, both built-in and third-party, that allow you to do some fantastic things with Python without having to get right down into some nitty-gritty details. Yeah, that's beautiful. I find that when people are new to Python, and this includes myself when I'm working in some area that I haven't worked in a lot, I'll not realize there's some really simple thing that I can use.
And I think it's really great. There's a lot of those little tips and tricks in your book. But before we get into the details of your book, let's start at the beginning. Sure. How did you get into programming in Python? I started programming on paper in the late 70s. I started reading computer magazines.
I taught myself basic purely off the magazines. And I wrote my code on paper, and I executed it on paper. Then eventually, I bought a home computer. I don't know if your listeners will remember what they are, but they were things before PCs. Very limited, but quite a lot of fun. And eventually, I went on to do a computer science degree, which I absolutely loved.
And I hated the book. And that put me off Python for about a year. And that was one of the motivations for writing my first Python book, was to write one that would actually encourage people to use it. But once I started using it, within a year, all of my utility programs and tools that I use for my daily work, they were in Python, because I just loved it.
So that was around 1999. And now, everything I do, the first choice language is always Python. Yeah, the Python ecosystem and, frankly, the language is fairly different from the late 90s today. Oh, massively different. I mean, I actually didn't like the indentation at first. That took me like 48 hours before it really clicked.
But I really liked Python pretty well from the get-go. Yeah, so did I. I think the indentation does catch a lot of people off guard. And to me, it's kind of like good science fiction. You have to sort of take this moment, the suspension of disbelief. Like, just imagine for a minute this white space concept is a good idea and work with it for a week.
And then it just dawns on you, like, wow, this really is a good idea. Like, I went back to working in some C-based languages right after I sort of learned Python and started working in it. And the white space was a shock to me at first. But what was even a bigger shock was these C-based languages that I loved.
And so is C++ and Java and all of these languages. So you can do anything in one of them that you can do in the other. So why choose one particular language rather than another? And I think part of that is, well, what's the libraries and ecosystem like? And part of it is what fits the way you think best.
I'd ported everything from Python 2 to Python 3 right at that stage. And I think it's excellent. Yeah. You know, maybe that's a good segue to sort of taking a survey of the books that you've written. Because you've written many books. Is something, how many, around eight, seven? Depends whether you count second editions.
Without second editions, it's seven. And with them, it's nine. Okay, excellent. Yeah. And one of them you wrote is a pretty sizable Python 3 book, right? Yes. That's Programming in Python 3. Yeah. That book is really aimed at people who can program in something or other. And it's to port them over to Python 3.
But it should also work for people. And the something or other could be Python 2. Right, right. So that's who it's aimed for. It's not aimed at beginners. The subtitle was poorly chosen by me. A complete introduction to the Python language. Sometimes people think that introduction means it's introductory, which wasn't the intended intention.
It was just, it's introducing everything that Python 3's got that you're going to use in normal, maintainable programming. The only things I don't tend to cover in my books are things that I think are dangerous and obscure. So, for example, in Python, you can disassemble Python bytecode, rewrite it, and put it back.
And that's brilliant. But I wouldn't ever cover that in my books because I wanted to cover stuff that people can maintain. Understand that it runs. That's right. Absolutely. Absolutely. Maintainability and understandability are really important to me because, in my experience, you live with code for quite a long time.
I like cross-platform GUI programming. And that book, the first part of it is actually a very brief introduction to Python programming itself. And I was quite pleased. I had very good feedback on that. Many people said, well, I already knew Python, but I read the introduction because, well, I bought the book.
And that's how I'm earning my living now because I'm earning my living writing on the back of commercial Python applications for desktop users. So they're written in Python, Python 3, PySidem Qt. Oh, wonderful. And do you ship those with something like CX Freeze to sort of package them up or was it PyToApp?
And so I started to learn the language. And I thought, yeah, I can write something better than what's available on this language. But one of the authors of Go has come out with a book on Go now. So I should think that will kill mine. You never know. You never know. I mean, well, I still think mine's a good book, actually.
But there we are. In terms of C++, I have written a few. But they're all C++ with Q. So I co-wrote with Jasmine Blanchett, C++ GUI programming with Q3 and then with Q4. And then I did a solo one, advanced Q programming. Okay. But again, they're all C++. I still use them for PiSide programming, you know, to remind myself how to do things.
Sure. Given your background there. I just saw, when was this, back in mid-April, there was an announcement saying we're bringing PiSide back to the Qt project. That's right. I'm really delighted. Fantastic. It's going to be PiSide for Qt 5. Now, you can use PiQt with Qt 5. But PiSide has been Qt 4 only so far.
But they're actually putting money behind it and investing in it. So PiSide 2 will be for Qt 5. And I'm really looking forward to that. Yeah. So am I. Do you know the time frame on when that kind of stuff will be out? They're doing the development in the open. I think there's like a GitHub or some equivalent of that.
As you know, programmers, we love reinventing things. And when they did PiSide, they invented a new way of doing bindings. And I think that hasn't proven to be quite as maintainable and flexible as they'd hoped. So I think that's where they're going to have to do quite a lot of work, getting that to work with Qt 5 and the new C++.
Right. Okay. Yeah. So it's more with the PiSide version than it is the Qt itself. Got it. I think so. I think so. Yeah. All right. Excellent. So I know there's a lot of interest in GUI apps from a Python perspective. And maybe another time we can dig into Qt even more. But let's talk a little bit about creating better Python apps.
Yeah, it makes a lot of sense. So I want people to be aware of that, that these kind of facilities exist. You can basically write a wide range of different types of networking apps in Python, right? You can go all the way down to the raw sockets with Byte. I just talked with Mahmoud Hashemi from PayPal.
And those guys are writing services that take over a billion requests a day. Wow. They're doing network programming in Python, but down below the HTTP level. Wow. And these custom APIs. And then you can, of course, go up higher, right? Like XML RPC or maybe REST service with requests, things like that, right?
Yeah, absolutely. I think the right way to start is start simple and then, you know, then go do crazy network stuff if you need to improve the performance. But generally, you don't have a performance problem. No, no. And that actually brings us nicely to concurrency. Python, you know, people say, oh, is Python slower?
Python can't do concurrency. And I really wanted to address those issues because how slow is Python really? Well, I developed a program in C++ that was very CPU intensive. And I rewrote that program in Python and it was 50% slower. And I think that's not bad going from C++ to an interpreted language, a bytecode interpreted language.
But of course, I then made it concurrent. And you could make it concurrent in C++, but it's much easier. They're doing that in Python. And so on a dual core machine, suddenly it was as fast as C++. Give it more cores. And it was faster than the C++. So even though baseline, yeah, it's 50% slower on real hardware using concurrency, it was much faster.
Yeah. And I think specifically around concurrency, it's easy to get yourself into a situation where you've been very clever and you've thought really hard about the algorithms and the way it works. And you've kind of written something just at the limit of your understanding. Like you totally understood what you did, but it's at the very edge.
But of course, understanding multithreaded code, debugging it is harder than writing it. And so maybe it's like, you know, you've sort of gone a little too far. You're like, okay, I could write this, but I don't really understand how to fix it when it goes wrong. Yeah. And that is a real problem with concurrency.
In some languages, you're stuck because the concurrency facilities, they offer pretty basic. So they don't make it easy. But Python offers higher level concurrent approaches to concurrency as well as low level. For example, you've got the concurrent futures module, which makes it much easier to create either separate threads or separate processes where Python takes care of lots of the low level details.
Within the first week, and there are no obligations ever. Sounds awesome, doesn't it? Well, did I mention the signing bonus? Everyone who accepts a job from Hired gets a $1,000 signing bonus. And as Talk Python listeners, it gets way sweeter. Use the link Hired.com slash Talk Python To Me and Hired will double the signing bonus to $2,000.
I think you really put this together quite nicely in terms of sort of breaking out the different types of concurrency. And it helps you understand if you sort of think, okay, well, what are the types of concurrency? What type of problem am I solving? Then you have a pretty good recommendation for if it's this type of problem, solve it this way.
So if it's CPU-intensive and you need concurrency, then you need to use a different method. And Python offers, for example, multi-processing, where you can split your work over multiple processes rather than multiple threads. And each of those has its own separate interpreter lock so that they don't interfere with each other.
Right. But I think the key to getting real performance from concurrency is to avoid sharing insofar as you can. And that means either you don't need to share in the first place, or if you've got data that needs to be looked at by your multiple threads or multiple processes, then it may be cheaper to copy that data rather than have them share some kind of locking to look at it.
Right. And that's a mistake I think a lot of people make is they see the way that their program is working now. They've got some shared... They've got a pointer they're passing to two methods or whatever, two parts of the algorithm. And they're saying, well, this part's going to work on this part of the memory and this one's going to work over here.
And so they think, well, when I parallelize this, this is shared memory access. And of course, you have to take a lock or somehow serialize access to that data. And it's easy to forget that, you know, if that's like a meg or even maybe 50 megs of data, it might be so much easier both for you and advantageous for performance to just say copy.
Make a copy and just pass it over and then correlate the differences later. Absolutely. The other possibility is to share the data without copying, which is fine if you never write to it. So if you've got data where you're just reading in information like a log or some data stream, and you're never changing the information you're reading, you might be producing new output, but that's separate.
The best way if you're writing data is write or save the data in separate chunks and gather it together at the end. That will often be less error prone and faster. Yeah, absolutely. But of course, sometimes there isn't a choice. Sometimes you do need to lock. And then that's when it becomes quite difficult to reason about because you've got to be clear when you need to lock and when you need to unlock and all the rest of it.
But when you said copy data, one way to say copy a data structure, like obviously you can't just pass the pointer over or get another variable and point to the same thing, right? Because it's a pass by reference, not pass by value type of semantics. So there's actually a copy module in the standard library, right?
Yeah. And basically, what I would contend is this. If you use copy.deepcopy in a non-concurrent program, then there's almost certainly something wrong with your logic. But if you're using a concurrent programming, then it may well be the right solution for you. Because deep copying can be expensive if you're using like nested data structures, like dictionaries with dictionaries and things that are quite large, for example.
But nonetheless, it may be the right tradeoff. Of course, the only way you're going to know for sure is to profile and actually time things. Because that's the other sort of big issue, isn't it? That, you know, we have an intuitive feeling this will be fast or that will be slow. But unless you back it up with numbers, you could be optimizing something that makes no difference whatsoever.
Yeah, you had some really interesting points there that I thought were both interesting and good advice. One was, if you're going to write a concurrent program, write the non-concurrent serial single threaded version. Absolutely. first, if you can, and then use that as the baseline for your future work, right?
And of course, one is much slower than the other. But I found that incredibly useful in the early days, particularly for debugging. And I still use the non-concurrent one if there's some tricky area that I want to focus on without having to worry about concurrency. So I found it's paid off in terms of saving my time as a programmer.
Get the non-concurrent version working first. And of course, it may turn out that that's actually fast enough anyway. Absolutely. And then you've saved yourself a whole lot of trouble. It's sort of the whole premature optimization issues. Yeah. Yeah. It's easy to get seduced into doing things concurrently because it's very fashionable and you can brag about it.
But quite honestly, it's got to be the right solution. And you're not going to know that until you've done a non-concurrent one first, I think. Yeah, that's a good point. And sort of related to that is the performance story. So you have some examples in your book where you write the concurrent version and then you have the concurrent version, but you write it in several ways.
And of course, if you use threading, it kills performance. Yeah. Ironically, in CPython, it's actually several times slower if you do it in parallel. Yeah, because it's only actually running on a single call at a time and you've got context switching on top of it. Whereas if you use multi-processing, Zoom, it can run free.
But then you also have the sort of memory usage. You have the L1, L2 caches and registers. And so like when you switch from one thread to the other, it could pull in data that trashes your cache and you've got to go get it from main memory, which is like 100 times slower. And it's just, it's very subtle.
So if you have something that's running with Python threads and actually the work is being done by say a C library, if that C library is written well, it'll release the GIL, do its work and then reacquire it when it needs to pass data back. So it's, it's, it's not a simple story, no matter how you look at it.
Yeah. Okay. So you still have, you've got a performance test, but you've got to have that serial version to give you a benchmark so that you know whether you're getting better or worse. Right. Absolutely. And also just doing that serial one, it will give you insights into the problem you're solving anyway.
And it's better to make mistakes with the serial one than with the concurrent one because you've got less to think about then. Yeah, that's for sure. If you really do have a problem and it is slower, the trick is to use sub processes. Yeah, use the multi-processing module, which prior to 3.2, I found not terribly reliable, but they did loads of improvements in 3.2 and certainly in 3.3 and 4.
It's absolutely rock solid, both Windows and Linux, which are the ones, the platforms I use. And it's brilliant. It's absolutely an excellent library. Yeah. And I just want to point out to people, like when you hear say use sub processes, that doesn't mean just go kick off a bunch of processes and manage it yourself, right?
In one of my applications, I do that. And there's an asynchronous function. You can basically just give it a Python function and some arguments and say, okay, go do this somewhere else on some other processor. And it'll just do that work. If that's like expensive work, that's great because it doesn't stop your main process at all.
And when it's done the work, it lets you know. And you can pick up from there. Right. So there's the concurrent futures module, which can be, which is a very high level module, which makes it really easy to just execute either with threads or processes stuff. Or you can go use the multi-processing module itself with its pools and stuff.
Let's do this as sub processes. Let's switch it to have like a pool of sub processes. All of those things. Right. Yeah. The other thing about multi-processing is by default, it doesn't share memory, which is the opposite of threading. Which means you're not going to clobber yourself by writing to something that's shared.
Continuous delivery isn't just a buzzword. It's a shift in productivity that will help your whole team become more efficient. With SnapCI's continuous delivery tool, you can test, debug, and deploy your code quickly and reliably. Get your product in the hands of your users faster and deploy from just about anywhere at any time.
Yeah, there's some built-in data structures for sharing across process, right? There are. I mean, I only use them personally for flags. You know, I tend to gather my data separately if I've got results data and then join it all up together at the end. So I just use flags basically to say, like, this bit's at this stage or a flag to say, look, just stop now because the user's cancelled.
Yeah. To give me a clean termination. But, you know, I mean, I cover all that sort of stuff in the book. But it's a really great module, multiprocessing. But concurrent futures gives you that high-level approach, which makes it as simple as it can be for this kind of stuff. I mean, I'd still advocate not using concurrency unless you need it, you know, because it does make your program more complicated and harder to reason with, you know, or reason about.
Yeah. And, you know, it is easy to switch between concurrent futures using subprocesses or using threads. But that doesn't mean the code that you write can be just flipped from one to the other because of the serialization issues and all, you know, the locking shared data. So that's maybe a really subtle thing you could run into.
Well, if you're doing threading, the memory is shared by default. So any thread can stomp on anything, which can be a problem. But on the other hand, if you're using multiprocessing, any data that you're passing around has to be picklable, for example, which doesn't apply as a limit in threading because you're just accessing the same data in the same memory space.
So there are differences and there are tradeoffs. And the API for multiprocessing started as mimicking the threading API, but it's actually grown considerably since then. So it's worth digging in and learning. But I start with the concurrent futures because that is the easiest conceptually and impractical code.
It requires the least code to get stuff done. Yeah, absolutely. So both the multiprocessing and the threading are pretty good for when you're doing basic IO bound work, right? Because the key thing to know about that is a thread when it waits on a network call in CPython will release the gill, right?
And I also have not used that a lot. But my understanding is that's a little like the Node.js style of programming. I don't know because I avoid JavaScript as much as I can. But basically waiting on the IO bits and releasing it to process other bits of code, other methods while you're waiting on IO, right?
So it's going to let you know rather than you having to poll or be blocked. Right. Very callback driven. Yeah. Yeah. Which is a perfectly good approach. Yeah. And then Python 3.5 added the async and await keywords. Yeah. Which I haven't used. I'm still using 3.4. Partly because I had some compatibility issues with CX Freeze at the time.
And partly because of the installer. For my commercial software, I released both 32 and 64 bit versions on Windows. And up to 3.4, it's really easy to install both of those side by side. There's no problem. But with a 3.5 installer, what I found was that some third party libraries couldn't find one or the other.
I mean, I have done it with 3.5. But what I haven't managed to do is get my third party stuff. PyWin32 and APSW, which I'll mention at the end. I couldn't get them working properly with it when I had both. They work fine when I've just got one Python, but not when I had both. But hopefully that problem will go away.
Because, I mean, sometime I'm going to, like, stop doing 32-bit versions of my apps. I really want to look into the async and await stuff more. Because that programming model is so beautiful. It's just I haven't been writing any code that requires that type of work. I like that model because it's very similar to the GUI event loop model.
I mean, the GUI event loop basically sits there and says, I'll let you know if something happens. And you say, okay, well, if this thing happens, call this. Yeah. GUIs are inherently event-driven, right? Absolutely. They've got their message pump and everything. So you actually, one of the, maybe the last section in the concurrency bit of your book, you talk about special considerations for GUIs.
Yeah. I mean, I did this using TKinter simply because that's in the box. You know, comes with Python out of the box. Although, personally, I use PySide and Q. But it would work. The method works with both. And I'm sure it would work with WX or with PyG objects, any GUI system. And what I discovered was, how do you make, well, the question that arose for me was, okay, I've got a GUI application.
And it's got to do some CPU intensive work. But I don't want to freeze the CPU. Because what if the user wants to cancel the operation? Or what if they just want to quit the application? I don't want it frozen for like, you know, minutes on end when they can't do anything. One of the quickest ways you can make a user believe that your application is crappy is to have it just lock up.
And on Windows, like, get that sort of white, opaque overlay saying not responding. Or on OS X, it says force quit. You're like, hmm, I'm a little suspicious now. Yeah, and sometimes those messages come too early because sometimes, you know. But anyway, so that was the problem that I had to address.
And what I found was, if I use threading, I do have a work thread and a GUI thread, the GUI still freezes. So what I needed was some way of not having the GUI freeze. And the model that I came up with was I have two threads, one for the GUI, and what I call, rather sarcastically, the manager thread.
And the thing about the manager thread is the GUI gives it work. Whenever there's work to be done that's like CPU intensive, it gives it to the manager. But like a good manager, the manager never does any work. And that means that the GUI thread always gets all the CPU of its core, so it's never blocked.
Right, because you still have the preemptive multithreading that gives you enough time slice that your user feels like your app's working. So basically, you've got two threads. The GUI thread gets all the CPU for its core. And whenever it has work, it gives it to the manager who immediately hands it on to a process in a process pool.
Stop work. That model I cover in the book. And as I say, it'll work with any, although I show it with TK Enter, it's not TK Enter specific. Yeah, absolutely. I think that's a pretty good summation of the concurrency story. The other part of performance that you talked about that I actually don't know very much about and I haven't talked a lot about on my show is using Cython to speed up your code.
Can you tell everyone what Cython is and give a quick summary there? Okay. Cython is basically, it's a kind of compiler. So, if you have an application written in pure, ordinary Python and you run it through Cython, it will create a C version of your code. And my experience is that will basically run twice as fast, just without touching it, without doing anything, just because it's now C.
But you can then go further. You can actually give it hints and say, well, you can give it type hints. So, basically, you can say, well, this is an int or this is a string. And if you give it hints, it can optimize it better. It's also got optimizations for NumPy. So, for people who are interested in that kind of processing.
So, that's good. But, of course, a compiler could use that type hinting information to produce more optimized code. And I expect that's where things will go. Yeah, absolutely. I'm hoping that Cython will actually adopt that syntax. And that, I mean, there are other compilers like Nuitka and so on may adopt that.
Now that typing is a standard module, one hopes that the third-party compilers will adopt it. Yeah, at least there's an option, right? Yeah. And it would mean consistent code then. It would mean you could write your code using typing and know that whichever one of the compilers you chose would give you some kind of speed up.
I thought those were kind of interesting. Oh, yeah. The game was just a bit of fun. I did it in one of my books. I think it's actually in Python practice because I'd never put a game in a book. And I thought, well, why not? I wrote it in TK Inter, but I have got cute versions. And on the website, I've got a JavaScript version that I did using the canvas, you know, the HTML5 canvas.
It's basically the same game or tile fall, but with the things gravitating to the middle rather than falling to the bottom and left. That's it. And yeah, you can do fun games with Python, no problem. And of course, there is a Pi game library as well for people who are more sort of heavily into games.
Yeah. Diff PDF is paying my salary. Basically, it compares PDFs and you might think, well, that's easy. You just compare the pixels and it can do that. And lots of other tools can do that. But what turns out to be quite tricky is comparing the text as text because PDFs are really a graphical file format.
Yeah. And I thought it'd be used by publishers. I wanted to use it originally to compare. If you do a second printing of a book, not a second edition, a second printing, the publisher will let you make minor corrections as long as it doesn't change the pagination. And having to like check that I hadn't messed up by looking at 300 or 400 or 500 pages was pretty tiring.
And it's a Windows-specific product. It uses a third-party PDF library that I bought, a royalty-free library. And yeah, that's been paying the way. But I've come up with another program, one that I originally wanted to write more than 20 years ago. But I didn't have the skill then, and the tools weren't available anyway.
And that's X-Index. And it's for book indexes. And there are a couple of – well, there are some existing products out there for book indexes. But this one uses Python, and it uses SQLite, which I adore as a database. I really like it. Yeah, I'm a fan of it too. Yeah. So I get all the reliability and also the convenience.
I mean, SQLite has full-text search, which I think people from Google added to it. And that's just absolutely superb. Oh, yeah. That's excellent. So that application has only gone on sale the end of last month. Wow. Congratulations on that. That's excellent. Thank you. So I'm really pleased about that.
And I'm waiting to see – like people can use it for 40 days free trial now. So I'll see in a couple of months if people actually buy it. Well, good luck on that. That's great. Yeah. So before we end the show, let me ask you a couple of questions that I always ask everyone. Yeah. So there's close to 80,000 PyPI packages out there.
But the – and obviously, I use CX3s. And I use PyWin32, which is very useful for Windows. And I use – and another Windows one I use is WMI, which is Windows – Windows management infrastructure, I think. Thank you very much because I'd forgotten. But the one that I want to sort of boost, if you like, is APSW, another Python SQLite wrapper.
And as you know, the Python standard library has a SQLite 3 module, which is perfectly good. Nothing wrong with that. But APSW is absolutely excellent. It provides you as a Python programmer with all the access to SQLite that you would get if you were a C programmer, but with all the pleasure of programming in Python.
Oh, wonderful. So you can create your own custom functions in Python that you can feed into it. So you can create your own collations. You can even create your own virtual tables. Everything that you can do in C, you can do in Python. And it's just a fantastic library. It doesn't follow precisely the DBAPI 2 standard.
It does where it can, but it favors – if there's a choice and like SQLite offers more, it offers you the more. Because it's designed to give you everything that SQLite has to offer. I mean, if you're wanting to prototype on SQLite for transferring to another database, then use the built-in SQLite 3.
But if you want to use SQLite in its own right, for example, as a file format or for some other purpose where you're only going to be using SQLite, then APSW is the best module I've ever seen for doing that. Yeah, that's wonderful. While we're on database packages, I'll also throw out records by Kenneth Wright, which he called SQL for humans, which is like the simplest possible sort of alternative to DBAPI that I can find.
It's like the opposite end. It's like super simple, not like, you know, we're going to give you access to everything. Okay. I mean, I like writing raw SQL, so APSW suits me for that as well. I mean, I know there are things like SQLAlchemy and, you know, that give you a higher level, but I love APSW.
Yeah, wonderful. Wonderful. Okay. Last question. When you write some Python code, what editor do you use? I use gvim. gvim. Okay. Okay. So graphical vim. Now, I'm not saying that I'd recommend that. I think that it could drive, you know, someone insane trying to learn it because it is a strange editor, but I've been using it for more than 20 years now.
I just, I would find it hard to use another one for daily work. All right. Excellent. Well, thanks for the recommendation. Okay. And thank you very much for having me on your show. Yeah, Mark. It's been a great conversation. And I'm really happy to shine a light on this whole concurrency story and the GUI story as well in Python because they don't get as much coverage as I think they should.
Hired wants to help you find your next big thing. Visit Hired.com slash Talk Python To Me to get five or more offers with salary and equity presented right up front and a special listener signing bonus of $2,000. SnapCI is modern, continuous integration and delivery. Build, test, and deploy your code directly from GitHub, all in your browser with debugging, Docker and parallels included.
Try them for free at snap.ci slash Talk Python. Are you or a colleague trying to learn Python? Have you tried books and videos that left you bored by just covering topics point by point? Well, check out my online course, Python Jumpstart by Building 10 Apps at talkpython.fm/course to experience a more engaging way to learn Python.
You can find the links from today's show at talkpython.fm/episodes slash show slash 58. Be sure to subscribe to the show. Open your favorite podcatcher and search for Python. We should be right at the top. You can also find the iTunes feed at /itunes, Google Play feed at /play, and direct RSS feed at /rss on talkpython.fm.
