Latest / Talk Python To Me / #2: Python and MongoDB
Transcript
- 0:00Talk Python To Me. Episode number two with guest Jesse Davis recorded Sunday, April 5th, 2015.
- 0:09Hello and welcome to Talk Python To Me, a weekly
- 0:39podcast on Python, the language, the libraries, the ecosystem, and the personalities. This is your
- 0:45host, Michael Kennedy. Follow me on Twitter where I'm @mkennedy and keep up with the show and listen
- 0:50to past episodes at talkpythontome.com. This episode, we'll be talking to Jesse Davis from
- 0:56MongoDB about PyMongo and of course, MongoDB. Before we get to the interview, I have a quick
- 1:02message to share. Since we launched a week ago, the response has been overwhelming. I've received many
- 1:09feedback. I want to thank everyone who contacted the show. However, I could use your help to make
- 1:15sure the show continues to grow and thrive. If you know someone who would be interested in listening to
- 1:19the show, please send them a link to talkpythontome.com or share this on Twitter or Facebook. Do you know of
- 1:26someone who would make a great guest or have a great show topic in mind? Send me a note and I'll set it up.
- 1:30In other excellent news, we have a show sponsor. I want to thank Python Gear from pythongear.com for
- 1:36sponsoring this episode and you'll hear more about them later. If you'd like to sponsor a future episode,
- 1:42please contact us at talkpythontome.com slash sponsor. Now onto the show.
- 1:48Let me introduce Jesse. Jesse Davis is a staff engineer at MongoDB in New York City. He works
- 1:56on the MongoDB driver team and develops PyMongo and the MongoC driver. He's the author of the async
- 2:04MongoDB driver called Motor and he contributes to Tornado and AsyncIO.
- 2:09Jesse, welcome to the show.
- 2:11Thanks, Michael.
- 2:13It's really great to have you here on the show. And, you know, we've known each other
- 2:17sort of as acquaintances for a couple of years. As you know, I'm a MongoDB master,
- 2:23which is kind of like an MVP community expert program you guys run. So yearly, we'll come up there and we'll have some really interesting conversations.
- 2:31And we've always enjoyed the sessions where you come down and talk to sort of the external experts about working with MongoDB from Python.
- 2:40Yeah, we've been doing those about once a year and we've got the next one coming up in a month. And I really look forward to those too. We get some of our best ideas. It definitely creates a year's worth of ideas, if not more, to kind of mull over and implement after each one of those sessions.
- 2:58Yeah, those are really fantastic meetings. I really, really enjoy them. So I've seen that you've done a ton of stuff with Python. You know, before we get into the details of MongoDB and PyMongo and all that, you know, how'd you get started?
- 3:10So it's a funny story, really, as they say. I began when I graduated from Oberlin College 15 years ago, I was a C++ guy, to the extent that I knew any programming language, really, particularly well at the age of 22.
- 3:29I thought that I was a C++ and graphics guy.
- 3:59flight patterns.
- 4:00Wow, that sounds like a really interesting thing to jump into.
- 4:03It was a great gig and I did really, really poorly at it. So I spent about two years there and realized that I wasn't yet a grown-up. I was really screwing up my life and I was a bad software engineer. So I quit the job and went out into the world to try to get my head straight. And I spent a summer biking through France.
- 4:29And then I spent a year at a Zen monastery in Southern California. And when I checked back with Austin Digital whether they wanted me to come back to work for them, they said no, because I had not proven myself there.
- 4:44So I came to New York to continue my Zen study with a place called the Village Zendo here and to start being a layman and a software professional again. And there were no C++ jobs in New York at the time.
- 5:02What kind of jobs were there?
- 5:03What kind of jobs were there?
- 5:04Well, this was fall of 2004. So the whole market was kind of in bad shape. There had been the NASDAQ crash in July of 2001 and then there was September 11th. And New York hadn't recovered from that yet. So all of the C++ people from all of the banks were still unemployed and I couldn't compete with them.
- 5:30So what I did find was an educational startup called Wireless Generation in Brooklyn. In recent years, it's become Amplify Education. And they were willing to take a shot at me, even though the job was in Python and Oracle. And I didn't know either of those.
- 5:53That's a long ways from graphics and C++.
- 5:56Yeah, it was a huge leap. And it was pretty tough, but I had good mentors and I started using Python there.
- 6:06That's excellent. So then you carried on digging into Python and I saw that you have a ton of open source projects on GitHub that are successful or contribute to them.
- 6:19And somehow you found your way over to MongoDB from there, huh?
- 6:22Yeah. So after a few years working for Wireless Generation, I wanted to get a little more breadth. And I also wanted to make sure that I didn't become so senior that I couldn't continue to program, which was a pressure that I experienced there to move into management.
- 6:41That's kind of the curse of success for some programmers is, you know, you're really good at this. Stop doing it now. Go manage people, right?
- 6:47Yeah, exactly. And so to jump ahead a little bit, now at MongoDB, we've figured out how to do that by creating this whole separate track of staff engineers, which is the track I'm on now.
- 6:59Oh, that's excellent.
- 7:29Data storage layer for applications like that.
- 7:32Even though MongoDB was brand new at the time, like I started using it at version like 0.8 or something.
- 7:38Yeah, is this like 2009, 2010 timeframe or something like that?
- 7:42Yeah, exactly.
- 7:44And it was such a cool product.
- 7:48And within the New York tech startup scene, it was such a rarity as a big infrastructure systems project in a New York City startup that when I finally got tired of freelancing and I wanted to settle down and make a substantial contribution to a single product, I called Elliot and I said, I'm ready to come in from the cold.
- 8:12And he said, great.
- 8:12That's excellent.
- 8:13That's Elliot Horowitz, who's the CTO of MongoDB, right?
- 8:16Yeah, exactly.
- 8:18Yeah.
- 8:18So I suspect most people who are listening to this show have heard of MongoDB, although maybe not everybody.
- 8:26And they might maybe just know it as a buzzword.
- 8:29Can you give us the quick elevator pitch of what MongoDB is?
- 8:32Sure.
- 8:32Sure.
- 8:32So it stores your data.
- 8:36It's a database.
- 8:37And it stores your data not in rows and columns, but in a non-relational document format.
- 8:45And the format is called BSON, which is a binary JSON format.
- 8:50So if you know JSON, MongoDB's data format is very familiar.
- 8:56It consists of objects, which have a set of key value pairs.
- 9:00And these documents can also contain arrays, strings, numbers, dates, and about a dozen primitive data types.
- 9:11MongoDB lets you index and query this kind of object-oriented data in a very rich way.
- 9:20So among the document databases that we compete with, we have a particular advantage when it comes to our ability to declare multiple indexes on a collection,
- 9:36the sophistication of our query language and our statistical aggregation capabilities,
- 9:42and our ability to let you do very complex update operations where you can add a member to a set within a document
- 9:52or do math on numbers within those documents.
- 9:56One of the things that I find people coming from a relational database world feel like,
- 10:02a lot of times they're like, well, it's really cool you can have these kind of hierarchical structures
- 10:06that more closely match the way your objects look in memory in your program.
- 10:12But you probably can't query properly deep down with this stuff.
- 10:16So if I've got, let's take a super simple example, like a bookstore,
- 10:19and the bookstore has books and the books have reviews as nested, like a nested array.
- 10:25Well, what if I just want to know all the books that have five-star reviews?
- 10:29Could I query that?
- 10:31Right, exactly.
- 10:32And we do provide that, and that distinguishes us somewhat from the much simpler sort of key value store
- 10:41or other simplified document database product.
- 10:45Yeah, definitely.
- 10:47And I think, you know, of all the NoSQL databases,
- 10:50MongoDB is one of the few that would reasonably be something you could consider
- 10:55as your standard general purpose database, not just some kind of high-scale special use case.
- 11:01Yeah, that's exactly right.
- 11:02And MongoDB is not the best answer to every single question, obviously.
- 11:07There is data that is naturally relational,
- 11:11and then there is data that should naturally be put in some other simpler,
- 11:17more specialized NoSQL database.
- 11:19But MongoDB is very much targeted to be the best answer to many questions
- 11:24questions and a pretty good answer to an even broader set of questions.
- 11:28So you can use it as your default database in the way that you might have in the past been used to,
- 11:35MySQL or Postgres being a pretty good answer to many questions and the best answer to many others.
- 11:42This episode is sponsored by Python Gear.
- 11:45We know you're a huge fan of Python,
- 11:47and Python Gear has an excellent way to put your enthusiasm for Python on display.
- 11:52Visit pythongear.com and pick up Python or Django t-shirts, stickers, and more.
- 11:57Hand screen printed on American apparel,
- 12:00these are shirts that are made to last and are very comfortable.
- 12:04What's more, a portion of all sales will benefit either the Python Software Foundation
- 12:08or the Django Software Foundation.
- 12:10Tell Python Gear thank you for sponsoring this podcast
- 12:13by visiting their site at pythongear.com and ordering a t-shirt.
- 12:17They're also helping us with a small contest.
- 12:20We're giving away a free t-shirt to one lucky listener.
- 12:23Visit talkpythontimi.com, click on Friends of the Show,
- 12:27enter your email address, and we'll pick a winner before the next episode.
- 12:31Now, back to the show.
- 12:32So, I've got MongoDB, and by the way, in case people didn't know,
- 12:38it's open source, you can go to GitHub and check it out or see the progress.
- 12:42I've gotten it, but probably I downloaded it from mongodb.org,
- 12:46and it's running.
- 12:48Now I've got my Python app.
- 12:49What do I do?
- 12:50Right.
- 12:50So, MongoDB's network protocol is called the MongoDB Wire Protocol,
- 12:56and it's a basic TCP protocol.
- 13:01So, you need something that knows how to talk that protocol
- 13:04and knows how to convert between your Python data structures,
- 13:10your dicts and lists and strings and numbers,
- 13:13to BSON and back.
- 13:15So, you need a driver.
- 13:16And the standard driver for MongoDB is called PyMongo,
- 13:21and you install it from PyPI via pip, install PyMongo.
- 13:26The current version is about to be 3.0,
- 13:32which we'll release in just about a week,
- 13:34which is very exciting.
- 13:35Yeah, that's big news.
- 13:37Like, you guys have been trying to have a sort of a major unification
- 13:41of all the different drivers for the different languages.
- 13:44Is this part of that effort?
- 13:45Yeah, that's exactly right.
- 13:46So, PyMongo 3 has big behavioral and API improvements
- 13:51and standardizations,
- 13:52and that those changes are matched by the MongoDB Ruby driver 2.0,
- 14:00the C driver 1.2,
- 14:02the nose driver 2.0,
- 14:03and so on.
- 14:04And much more than ever before,
- 14:08we are all converging on the same set of behaviors
- 14:11and the same set of APIs.
- 14:13That's really cool.
- 14:14One of the real benefits of Mongo, I think,
- 14:16is it has great support for so many languages.
- 14:18So, if you choose your database,
- 14:20you're like, oh, wait, maybe this is better from, you know,
- 14:22Java for some reason.
- 14:23It still has a good data access story.
- 14:26So, that's fantastic.
- 14:27That's getting even better.
- 14:28Yeah, right.
- 14:29That's exactly right.
- 14:30So, we have drivers in 10 programming languages,
- 14:35and plus, even if you're using something weird like R or Haskell or Erlang,
- 14:41there's something out there in the community for you
- 14:43because writing a basic driver is actually fairly easy.
- 14:46We're really focused on making sure that each of these drivers
- 14:50feels right to experts in that language.
- 14:54So, PyMongo is very Pythonic,
- 14:56and it's written by Python experts,
- 14:59and its style and its documentation and so on
- 15:02are all very Python-y
- 15:04while at the same time balancing that
- 15:06with some degree of consistency
- 15:07with the nine other programming languages that we support.
- 15:10Yeah, there's got to be some interesting tension there.
- 15:13Huge, huge tension.
- 15:14It's the toughest problem that we face,
- 15:17and we are just in the last year or two
- 15:19really figuring out good bits to tackle that
- 15:22and to make those decisions correctly.
- 15:24Yeah, cool.
- 15:25So, you play a pretty big part in PyMongo, right?
- 15:28Yeah, I've been Bernie Hackett.
- 15:31My boss in Palo Alto is the PyMongo developer and maintainer,
- 15:36and I've been assisting him for the last three years
- 15:40as his second-in-command.
- 15:42And my main contributions to the driver are its concurrency design,
- 15:48its implementation of distributed systems type problem solving,
- 15:55and the connection pool.
- 15:58And with the 3.0 release, that's actually kind of done for the moment.
- 16:06And so I'm putting a lot of that work to rest now
- 16:11and moving on to become the primary maintainer of the C driver for MongoDB
- 16:16so that that part of the team can move into the kernel team
- 16:21and make contributions there.
- 16:22Oh, that's excellent.
- 16:23And that's even a little bit back to your roots from Austin,
- 16:26in some ways, I guess, right, with the C++ story.
- 16:30Yeah, exactly.
- 16:31Parts of my brain that has been idle for a decade are coming back online,
- 16:37and it's a really fun feeling.
- 16:39I know it is.
- 16:40Yeah, yeah.
- 16:41If audience members, if you've been programming Python for 10 years straight,
- 16:46like I have, I really can't recommend enough
- 16:49learning a very different programming language or reviving one.
- 16:53It's incredibly satisfying.
- 16:55Yeah, and gives you interesting problem solving skills
- 16:59that you don't necessarily develop if you stay in just one language.
- 17:03So that's great.
- 17:03Yeah.
- 17:04Now, there's a bunch of ways to talk to MongoDB,
- 17:07even just from Python, right?
- 17:08So there's PyMongo.
- 17:10What else is there?
- 17:11So PyMongo is the general purpose driver,
- 17:15and it's the most featureful, the most standard,
- 17:18the best maintained,
- 17:19but it's not optimized for some specialized use cases.
- 17:26And you can think of these as CPU-bound versus I.O.-bound use cases.
- 17:33Right, okay.
- 17:34So for the I.O.-bound,
- 17:36cases where you've got a web application
- 17:39that has a huge number of client connections,
- 17:43but they're often kind of idle or sleepy connections,
- 17:46like if you're implementing a chat server
- 17:50or something with web sockets,
- 17:52you want to use an async framework in Python,
- 17:56like Tornado or Twisted
- 17:59or in the Python 3.4 standard library,
- 18:03we've got async.io now.
- 18:04Yeah, that's a cool new feature.
- 18:06Right, so these are awesome async frameworks,
- 18:09and they solve that problem brilliantly,
- 18:11but they've got a gigantic compatibility issue.
- 18:16none of the existing libraries work with them.
- 18:18None of the existing sort of outside MongoDB libraries don't work with them,
- 18:24or like PyMongo itself doesn't work with them,
- 18:26or how do you mean?
- 18:27Well, I mean both of those.
- 18:28So if you've got basically a driver for any database
- 18:33that's not written specifically for one of these async frameworks,
- 18:36then it won't work with that async framework.
- 18:41So you need a specialized database driver for Tornado and MySQL.
- 18:44You need a specialized database driver for Tornado and Postgres.
- 18:49Right.
- 18:51And you need a specialized driver for Tornado and MongoDB.
- 18:55So I wrote that over the last few years,
- 18:57and it's called Motor,
- 18:58because it's taking the beginning of Mongo and Tornado.
- 19:02Excellent.
- 19:03Right.
- 19:04Plus it's a cool name,
- 19:05and somehow it was not yet taken on PyPI.
- 19:08So Motor is the now standard official async driver for MongoDB and Tornado,
- 19:15and over the next year I'm going to be expanding it out to cover async.io next,
- 19:21and then eventually twist it as well,
- 19:23so that it will just integrate with whatever you're using right now.
- 19:26Nice.
- 19:27And does that work with Python 3 and 2,
- 19:29or is that sort of a 2 thing for now,
- 19:30or what's the story there?
- 19:32That will work with Python 2.6 plus,
- 19:35so 2.6, 2.7, 3.3, 3.4, 3.5, when 3.5 is out.
- 19:41So how does that work with different implementations,
- 19:44like PyPI, for example?
- 19:45Sure.
- 19:46In the past, Motor and PyPI didn't work together very well,
- 19:50but that was about a year ago that I last personally tested them.
- 19:53It was correct, but it was slow,
- 19:56due to some very specific details about PyPI.
- 20:01In recent months,
- 20:03somebody that I didn't know posted benchmarks
- 20:06that showed that Tornado, Motor, and PyPI were actually blazingly fast,
- 20:12but I haven't personally reproduced that,
- 20:14so at the moment it's just kind of a hopeful sign
- 20:18rather than something that I would officially endorse.
- 20:20Sure.
- 20:21That's really good news, though.
- 20:22It looks like PyPI is moving on and has a lot of activity there,
- 20:25so that's really cool.
- 20:26I agree.
- 20:27Yeah.
- 20:27I've also heard of something called Mon Area.
- 20:29What's that?
- 20:30Right.
- 20:31So we've got this other branch of specialization.
- 20:34So the three categories that I think of are general purpose,
- 20:39PyO bound, and that's for Motor,
- 20:41and then there's CPU bound, and that's what Monary is for.
- 20:45Monary is a NumPy driver for MongoDB.
- 20:50Oh, that's interesting.
- 20:51Wow.
- 20:52Isn't it?
- 20:53I found out about it a few years ago.
- 20:55It was written by a quantitative analyst named David Beach.
- 21:00He needed it for something, some specific financial application that he was doing.
- 21:05And he noticed that if you stream BSON data through PyMongo and then into NumPy from there,
- 21:13it's pretty slow.
- 21:15And your data conversion is typically your bottleneck.
- 21:18MongoDB is fast.
- 21:20NumPy is fast.
- 21:21But converting each number from one data format to the next is very expensive,
- 21:27and it's a lot of wasted work.
- 21:29So he wrote a little bit of C code, which queries MongoDB using the C driver rather than PyMongo,
- 21:38converts the BSON data directly into NumPy arrays without passing through any Python data structure,
- 21:46and then hands you giant buffers of numbers that it got from MongoDB.
- 21:52And then you can use NumPy's incredibly fast statistical methods on that data.
- 21:59That's really fantastic.
- 22:00So if maybe you're storing a bunch of data in Mongo for big data on numerical type stuff,
- 22:06this would be the thing for you from Python.
- 22:09Exactly.
- 22:10And that's a pretty common use case among financial institutions.
- 22:14There's also a lot of universities doing big bioinformatics with MongoDB.
- 22:20And there's generally a lot of use within the scientific community for storing numeric data in MongoDB.
- 22:28Since NumPy has such a rich set of statistical routines that you can just take off the shelf,
- 22:37being able to go between the two in Python incredibly fast is an awesome feature.
- 22:44So Monary can do upwards of a million queries per second on commodity hardware.
- 22:50And, or query upwards of a million documents per second.
- 22:55That's amazing.
- 22:56We've been adding features to it over the years.
- 23:00We had a couple of interns last summer, Matt Cotter and Kyle Suarez.
- 23:04And now a new hire who's working for me, Anna Hurley,
- 23:10is adding more and more features to Monary every month.
- 23:13So it's becoming better documented.
- 23:15It's now read-write.
- 23:17So you can insert some NumPy arrays into MongoDB.
- 23:22And it's similarly optimized along that path.
- 23:24And we're adding SSL and authentication, which financial institutions will probably want if they're analyzing financial data.
- 23:32And that's kind of, that fills in the other portion of the environment where you're doing single-threaded CPU-bound calculations on numeric data within MongoDB.
- 23:48Yeah, that really does open up the whole science story for MongoDB a little bit more from Python anyway.
- 23:53That's really cool.
- 23:54So what surprises you most about what you see people doing with Mongo from Python or even with PyMongo specifically?
- 24:01What most often surprises me is there are certain mistakes that are incredibly common.
- 24:09And I wish we could figure out how to stamp them out.
- 24:11And the main mistake that I see people make is that they create a new Mongo client class instance for every HTTP request.
- 24:23And so they pay the price of TCP setup, very often SSL and authentication setup, and then the TCP slow start algorithm.
- 24:35All of this incredible overhead involved in opening a socket.
- 24:40And then they do one query and shut it all down.
- 24:44And when they say, oh, and they defeat connection pooling as well.
- 24:49And there's this sort of strange resistance to just creating a single global variable, which is the Mongo client.
- 24:58And I don't understand.
- 24:59I think they're coming from Java, where it's frowned upon to have one module-level global variable.
- 25:05But it means that among Python programmers who make this mistake, which is a huge number of people, their throughput is probably a third or a quarter or a fifth of what they should be seeing.
- 25:19Wow, that's amazing.
- 25:21And it's easy to fix.
- 25:23I don't understand apps to persuade people.
- 25:24It's incredibly easy to fix.
- 25:26That's the thing, right?
- 25:27Right.
- 25:27Doing it correctly is easier than doing it wrong, and yet doing it wrong is very common.
- 25:31Yeah.
- 25:32Well, hopefully people out there listening will go make a global Mongo client.
- 25:37I hope so.
- 25:38And we're also adding a best practices document to the PyMongo documentation in the next release that I hope will further dissuade people from making this error.
- 25:48Yeah, that'd be great.
- 25:49Almost would be cool to have a list of, like, these are the top five worst things you could do that we see out in the wild, so don't do them.
- 25:55You know, something like that would be nice to put up somewhere.
- 25:57That's a good idea, although honestly, it's really only top one.
- 26:01Like, if you don't do that, you're probably doing a good job.
- 26:06Excellent.
- 26:06So you guys just had a big release as well.
- 26:09You've kind of changed the entire underlying file system with something called WireTiger, and you've released version 3.0.
- 26:15What's the quick rundown of that?
- 26:17That's pretty exciting.
- 26:18Right.
- 26:19So it's not the default at the moment.
- 26:21It's opt-in.
- 26:23But with MongoDB 3.0, we made the option available to swap our old storage engine with WireTiger.
- 26:32And the performance characteristics are still a little complex, so I'm not going to make any inexpert pronouncements on that.
- 26:41Sure.
- 26:42But for the large number of use cases, WireTiger seems to be much, much higher performance, and it especially has much better concurrency.
- 26:54So if you're doing a lot of simultaneous writes on certain kinds of hardware, you should see a lot better throughput with WireTiger.
- 27:02So it's really exciting.
- 27:04And we also acquired that company.
- 27:07It was our first acquisition so that we could...
- 27:09The WireTiger open source project continues, but it means that we have that expertise in-house to make sure that WireTiger and MongoDB work perfectly together.
- 27:19That's right.
- 27:20They were from Berkeley DB or something like that originally, right?
- 27:23I think a lot of the WireTiger people were among the Berkeley DB developers, yes.
- 27:29Yeah, excellent.
- 27:29You have some opinions on editors, right?
- 27:32Like Vim versus PyCharm.
- 27:34What are your thoughts there?
- 27:36Yeah.
- 27:37So in recent years, I've spent a lot of time mentoring young people or just working together with a lot of junior developers.
- 27:46And what I particularly noticed is that everybody uses Vim for everything.
- 27:50And it's kind of sad to watch because I say, go find this method.
- 27:57And then I sort of have to sit around for a little bit, drinking tea and watching them grepping their files and doing like an incremental search through each file with Vim until, you know, they're searching for like death space, create collection or something in order to find this method.
- 28:16And it's just sad.
- 28:23And when people watch me, it's just, you know, this isn't bragging.
- 28:30It's just, if you use the right tool for the job, you can leap around really easily.
- 28:36And it's not just navigation.
- 28:40It's for huge search and replace jobs.
- 28:43PyCharm has all of these modes and all of these wonderful ways of breaking down big code change tasks to make sure that you complete them correctly.
- 28:55Using a visual debugger is also completely invaluable.
- 28:58Like when I see somebody say, I have this bug.
- 29:02And I say, well, what if you try it?
- 29:03And they say, well, I added 100 print statements.
- 29:05I know that something's wrong.
- 29:07And invariably, even though they've spent hours on it, I say, well, let's get it into PyCharm.
- 29:14And I use a couple of breakpoints and a few watchpoints.
- 29:18And we find it because that's what a debugger is for.
- 29:22That's right.
- 29:23A picture is worth a thousand words and you can kind of say the same about a visual debugger, right?
- 29:27Yeah, exactly.
- 29:28You don't have to ask via a print statement, is this what I expect?
- 29:33Oh, it is.
- 29:34Okay.
- 29:34Well, is this what I expect?
- 29:35Oh, it is.
- 29:36Right.
- 29:37You just have everything displayed for you and you can immediately see what it is about the code that isn't matching your expectations.
- 29:44Yeah, that's awesome.
- 29:45I totally agree with you.
- 29:46And I'm a big fan of PyCharm as well.
- 29:48I use it for all my Python work.
- 29:50And you can just hit like shift two times and type something and it'll just take you to a file or to a method or to a variable.
- 29:57It's fantastic.
- 29:58Yeah, I agree.
- 30:00It also shows you your unused imports and it checks your style while you go.
- 30:05So you start making that error as well.
- 30:06Yeah, you're sort of PEP 8 compliant straight away.
- 30:09Exactly.
- 30:10Awesome.
- 30:12All right.
- 30:13Well, let me ask you one more question.
- 30:15So out there on PyPI, there's tons and tons, you know, 65,000, 56,000, something like that packages.
- 30:22There's some great ones out there.
- 30:24Do you have any favorites?
- 30:25PyMongo and Motor maybe, huh?
- 30:27Yeah.
- 30:29PyMongo is a great package.
- 30:31It's one of the most popular.
- 30:32It's one of the most popular.
- 30:32And Motor is a fun little project written by some smart guy somewhere.
- 30:38I wonder who that was.
- 30:41I'm also a big fan.
- 30:42And so another package I wrote that I'm very fond of is called Toro.
- 30:47It's T-O-R-O.
- 30:49And it's a set of things that are like locks, queues, conditions, event variables.
- 30:56But it's not for multi-threading.
- 30:59It's for Tornado coroutines.
- 31:01Oh, okay.
- 31:03So it kind of extends the analogy between coroutines and threads.
- 31:07And it makes it possible for your asynchronous coroutines, which are optimized for I-O-bound applications using something like Tornado.
- 31:17It lets them coordinate using the same kinds of patterns you're used to with threads.
- 31:23So you can make consumer-producer coroutines using the exact same pattern as you're used to for producer and consumer threads.
- 31:32I'm working with Tornado's author, Ben Darnell, to contribute Toro piece-by-piece into Tornado so that Tornado will have those features built in with Tornado 4.2.
- 31:47It has nothing to do with MongoDB.
- 31:50I think it's one of the things I like about it is that it's just this separate project that I kind of use recreationally.
- 31:56And it's also just got a lot of really fun patterns that it's fun to think about.
- 32:02Yeah, that's really cool.
- 32:03You know, that kind of programming, trying to coordinate asynchronous coroutines, sounds like a really interesting sort of problem or puzzle to solve, you know?
- 32:12Right.
- 32:13And a lot of those questions have already been answered for threads.
- 32:16So if you have the same primitives or if you have analogous primitives to use with coroutines, then you can use the same answers that people have developed for threads for the last few decades.
- 32:28Fantastic.
- 32:28So, yeah, people should check out Toro.
- 32:30Very cool.
- 32:30People have been listening to us talk and rave about MongoDB.
- 32:33And in case you guys don't know, I'm a huge fan of MongoDB as well and use it for many projects.
- 32:38If people are excited, they want to get started, what do they need to do?
- 32:42So you can pip install PyMongo and then you can go to mongodb.org and download the MongoDB server.
- 32:50It's among other awesome things about MongoDB.
- 32:54You install it by untarring it and then starting it, period.
- 32:59And if you want to learn more, the PyMongo documentation online at api.mongodb.org slash python has a complete tutorial for you.
- 33:09And if you want to go a little deeper, there's an excellent online course called M101P.
- 33:16So that's MongoDB 101 for Python.
- 33:19And the next section of that class starts on May 26th, I think.
- 33:24Excellent.
- 33:25And is that education.mongodb.org?
- 33:29I forget the URL.
- 33:30Yeah, that's correct.
- 33:31Yep, exactly.
- 33:32Excellent.
- 33:33Okay, well, is there anything else you want to sort of give a shout out to or get people's attention focused on?
- 33:37I'm just really excited to be on this podcast.
- 33:40And I think that this podcast is excellent.
- 33:43And I'm looking forward to listening to the next episodes while I'm on the subway.
- 33:48Excellent.
- 33:50Thank you, Jesse.
- 33:50It's been a really great conversation.
- 33:52And I think people are going to be super interested in this stuff.
- 33:55It's good.
- 33:55MongoDB is such a fun project to work with.
- 33:58When I was working with relational databases, I always felt like, oh, there's this sort of database and it's a necessary evil.
- 34:03And it's kind of resisting what I'm trying to build in my app.
- 34:06And you switched to Mongo and it's just sort of frictionless design and evolution in your app.
- 34:10And so thanks for all your work on making that a possibility.
- 34:14Thanks so much, Michael.
- 34:15You bet.
- 34:16Talk to you later.
- 34:16Bye.
- 34:17This has been another episode of Talk Python To Me.
- 34:23I want to thank our sponsor, Python Gear, for making this show possible.
- 34:27Please visit pythongear.com, get an awesome T-shirt or sticker, and let them know you heard about them on Talk Python To Me.
- 34:34Smix, take us out of here.
- 34:36Bye.
- 34:58Thank you.