Latest / Talk Python To Me / #99: Morepath: Super Powered Python Web Framework
Transcript
- 0:00One of the areas where Python truly shines is on the web.
- 0:02Many well-known websites like YouTube, Pinterest, and Spotify are powered by Python.
- 0:07In the mid-2000s, a number of powerful and popular web frameworks were created,
- 0:12such as Django, Flask, and Pyramid.
- 0:13It may feel like the choices of web frameworks and innovation in that space is basically baked and done.
- 0:19But we're actually seeing an explosion of new frameworks because of some new web paradigms.
- 0:24In this episode, you'll meet Martin Fassen, who created MorPath,
- 0:28a relatively new web framework built to be a first-class citizen of this JavaScript,
- 0:33client-side, heavy web paradigm that's popular in many apps today.
- 0:37This is Talk Python To Me, episode 99, recorded January 19th, 2017.
- 0:57Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the ecosystem,
- 1:14and the personalities.
- 1:15This is your host, Michael Kennedy.
- 1:17Follow me on Twitter, where I'm @mkennedy.
- 1:19Keep up with the show and listen to past episodes at talkpython.fm,
- 1:23and follow the show on Twitter via at Talk Python.
- 1:25Martin, welcome to Talk Python.
- 1:28Hello.
- 1:28I'm excited to have you here.
- 1:30I really love web development in Python.
- 1:33And I think web development in Python is actually one of the really early places that Python
- 1:39became super relevant.
- 1:40And we've seen it spread to other places really well, like data science is the most recent of
- 1:46these.
- 1:46But, you know, at the heart, I think a lot of Python developers are web developers.
- 1:50When people ask me, hey, what do you do?
- 1:53And I don't want a long conversation.
- 1:54I just want a quick answer.
- 1:55Like, oh, I write web apps.
- 1:57I'm a developer.
- 1:57Something like this.
- 1:58So I love web apps.
- 1:59And I think it's really cool, even though there are many Python web apps around, that you've
- 2:04created a new one relatively recently, within the last couple of years.
- 2:07So I'm excited to talk to everyone about MorePath.
- 2:10Before we do, though, let's hear your story.
- 2:12How did you get into Python and programming?
- 2:14Well, programming I've been doing since I was a child, trying to create games in BASIC on
- 2:22various computers, first at my father's office, because we had no computer at home, and then
- 2:28later on, on home computers.
- 2:30What was that first computer?
- 2:31The very first computer that I remember using, I think that's actually the very first computer
- 2:37I used, was called a Triumph Adler, which is, I don't know what kind of brand that is.
- 2:44It was a CPM machine, and then after that, moved to early PCs, Olivetti M24s are the ones
- 2:53I recall also being very early.
- 2:55And my home computer was an MSX2, which was C80-based and more popular in Japan and Europe
- 3:02than the United States.
- 3:04Okay.
- 3:04And so you started out originally just poking around at these things, and did you try to
- 3:08write some games?
- 3:09Yes, yes.
- 3:10Like, I imagine many programmers tried to write some games, very simple things.
- 3:14I think it's interesting.
- 3:15Like, people really want to get into it and write games, and games are some of the hardest
- 3:19types of software to write.
- 3:20Yeah, it used to be easier, I think, back then, because even mobile phone games are more complicated
- 3:26than the games that were commercial back then.
- 3:28But even, there are a lot of sort of details, like real-time requirements and things like that,
- 3:33that you don't really have so much in other contexts.
- 3:36Yeah, absolutely.
- 3:37So where'd you go from there?
- 3:38Are you planning on it at home?
- 3:39Did you study computer science in university, or where?
- 3:42Yeah, I did something more artificial intelligence-oriented, but that's a very long time ago.
- 3:47But I had some courses, various languages, LISP, Prologue, taught myself C.
- 3:52I had a Pascal course.
- 3:54I did some work with Delphi for a while, back in the 90s.
- 3:58And then I was programming in C++, was writing this artificial life simulation.
- 4:04And then I heard about scripting languages, read an article in some magazine at some point
- 4:11that listed Perl and Tickle and Python, maybe one or two others.
- 4:17And I basically just wanted to write some tools that could help me manage my C++ code base.
- 4:23And I looked at Perl, because that was sort of the obvious candidate at the time, and it was on my computer.
- 4:30And messed around with it for a while, and I could see how that would be a useful language.
- 4:36Like, it had made things like data types really easy.
- 4:39But it never quite clicked in my brain.
- 4:43Then I remember printing out the Python tutorial from python.org.
- 4:48And I read it one evening before sleeping, and the next day I was a Python programmer.
- 4:53That's awesome.
- 4:54I'm sure it's one day, right?
- 4:56I've done this as well, but it's been very, very long that I printed.
- 5:01Like, I remember printing like 100 pages of source code in C++, trying to understand some application.
- 5:07And printed it and took it with me, because I was going away somewhere for the summer,
- 5:10and I didn't have a computer with me the whole summer.
- 5:13Like, the world has changed so much, right?
- 5:15Yes, yes.
- 5:15This was just without a computer for during the evening, but I just had printed out the tutorial.
- 5:21And yeah, then a few weeks later, I actually managed to get a job writing Python code in 1998,
- 5:27which was kind of...
- 5:28That's awesome.
- 5:28...kind of surprised myself.
- 5:31But I was at a...
- 5:33Well, it was actually the veterinary department of Dutch University in Utrecht,
- 5:37and they were looking for somebody who would clean up some script that had fallen apart
- 5:42that was written in some combination of DOS batch files and D-based code.
- 5:48And they wanted me to rewrite it.
- 5:52And I said, can I use Python?
- 5:53And they said, what's that?
- 5:55And I said, well, it's a programming language.
- 5:57And is it readable?
- 5:59I said, yeah, yes.
- 6:00It's very readable.
- 6:02Which is really what they were looking for.
- 6:05And then I found myself having a job writing Python code, which then quickly sort of moved into the web as well.
- 6:11I started...
- 6:13That was 98 as Zope was released as an open source product back in 98 as well.
- 6:20So I started playing around with that and then moved into web development from there.
- 6:24That's cool.
- 6:24Yeah.
- 6:25That first week or two of the job was just like, what am I doing here?
- 6:29I can't believe they just hired me.
- 6:30I just barely know this.
- 6:32Well, I mean, I guess I had just been playing with Python for like a few weeks, I guess.
- 6:37But it just clicked in my brain so much that I thought, okay, this is the right tool for the job.
- 6:42And it was sort of more or less a scripting job anyway.
- 6:45So that fit.
- 6:46And I remember I was reading like complex Python, the Python news group.
- 6:50And people were saying, oh, I wish I had a Python job and I'm stuck here programming in this other language.
- 6:55That it looks really unrealistic to get a real Python job.
- 7:00You know, back then those were very rare.
- 7:02And I was like, hey, I actually have a Python job.
- 7:04And I, you know, I didn't even particularly look for one.
- 7:08I just had one.
- 7:09So I was lucky.
- 7:10Yeah.
- 7:11Yeah, that's really lucky.
- 7:12I still hear that from people today that, you know, they're working in some other technology.
- 7:16But they play with Python at home and they're looking to get there.
- 7:19So that's really cool.
- 7:21Yeah, it's everywhere though now.
- 7:22I mean, Python, it's really a different world.
- 7:25I remember Python.
- 7:26I had to explain to everybody what Python was.
- 7:29I mean, even other software developers.
- 7:30And these days, I don't have to do that anymore.
- 7:33It's really everywhere.
- 7:35Yeah.
- 7:35There's some stats.
- 7:36Somebody that did a study recently analyzing active, non-trivial,
- 7:41GitHub repositories, which was something like they have 10K lines of code.
- 7:46No, 10K is worth of file content.
- 7:48And they've been updated within the last year.
- 7:50And if you take that in there, Python is the number two most popular language on GitHub
- 7:55behind JavaScript, which I think is overcounted.
- 7:57So it's definitely a different world.
- 7:58Uh-huh.
- 7:59Yes, yes.
- 8:00And there's just lots of commercial projects that use Python in one another way that don't
- 8:05even show up on GitHub as well.
- 8:07Yeah, absolutely.
- 8:08So you talked about Zope and some of the, I think, you know, the successors a little
- 8:12bit like Pyramid and whatnot.
- 8:15It seems to me like those were kind of inspirations in your new web project because you reference
- 8:21them somewhat positively in your documentation and things like that.
- 8:24Sure.
- 8:25Yeah.
- 8:25No, I started with Zope in 98 and I was very involved with it until I think even, yeah,
- 8:31about up to about 2010.
- 8:33I was even chairman of the Zope Foundation for a few years.
- 8:38And Zope was really, it was really a killer app for Python in a way because there are a lot
- 8:45of the, as you mentioned, web development was an early thing for Python though.
- 8:50I think data science was there very early as well.
- 8:52But the conferences like the early EuroPythons and the International Python Conference that I
- 8:59went to even before then, a lot of the people there were there because of Zope.
- 9:05That's how they were attracted to the conference and to Python.
- 9:08So it drew in a lot of people similarly to, I imagine, Django does now.
- 9:13Zope was a web framework before we even had a word for that because web framework only arose
- 9:20as a concept later.
- 9:23So it was called a web application server, I believe.
- 9:25These frameworks were extracted out of like, let's build this web app.
- 9:28Oh, and actually there's some kind of framework we could almost use here, right?
- 9:31In that sense.
- 9:32Zope was actually, yeah, it was a very strange beast.
- 9:36And in part it's because there were no, there was no normal beast out there at the time because
- 9:41everybody was exploring.
- 9:42And in part it's because it was enormously creative.
- 9:46What it had was a web-based user interface, which doesn't sound very amazing now because
- 9:53lots of things do.
- 9:53back then that's kind of unusual for web application development framework.
- 9:59And through that you would add templates.
- 10:02And later on you could add little pieces of Python code.
- 10:04And then it sort of slowly morphed into doing more and more sort of larger scale Python projects
- 10:11using Zope's plugin architecture.
- 10:13And fairly quickly we were dissatisfied with Zope's plugin architecture.
- 10:19And then this whole Zope 3 project emerged,
- 10:22which was sort of intending to rewrite Zope and make it all better and create the future paradise.
- 10:29And while we created a lot of interesting technology and we learned a lot and actually built some real applications
- 10:35with Zope 3, it never really took off because we sort of overshot in the other direction as you tend to get.
- 10:43Yeah, you rarely make one rash decision.
- 10:45It's usually swing back the other way, right?
- 10:47Like it's just, I see that all the time in technology that people have some kind of monolithic thing
- 10:52and they're like, oh, we're going to fix this.
- 10:53We're going to make it extensible.
- 10:54You can enable, disable, et cetera.
- 10:56Yes.
- 10:56And then it just becomes like, well, wait, this is no longer easy to use.
- 10:59I liked it because it was easy.
- 11:00And now it's like there's a hundred choices and it's hard to fix when it's broken and all that kind of stuff.
- 11:05Yeah, the early Zope was never really easy if you were going to build a larger Python-based project with it.
- 11:10But if you just wanted to write something quick, sort of using the web user interface, then yeah, it was very easy.
- 11:16And yeah, I actually spent time in making the Zope 3 technology available in Zope 2.
- 11:23So I created this little glue framework that I called 5, which is what inspired the Python name for 6.
- 11:32The name 5 was already taken.
- 11:34So they multiplied 2 and 3.
- 11:36Yeah, oh, that's cool.
- 11:37I didn't know you were behind that.
- 11:39Yeah.
- 11:39So I'm not behind 6, but 2 plus 3 was already taken.
- 11:43So they had to go to 6 instead of 5.
- 11:45Nice.
- 11:46Yeah, you already had the package name.
- 11:47So that's all that debate.
- 11:48That technology is still in use inside of the blown CMS to this very day.
- 11:52And then what I did in 2006 is actually started together with a bunch of other people.
- 11:57But sort of I kicked off that project.
- 12:00The Grok web framework, which was based on the Zope 3 technology, tried to put a friend of your face on it.
- 12:06Also inspired by sort of the new wave of web frameworks that had been coming then.
- 12:12Right.
- 12:12Right.
- 12:12That's like Flask and Django time.
- 12:14Yeah, Ruby.
- 12:15Flask was not around yet.
- 12:16But yeah, Ruby on Rails and Django were new at the time.
- 12:20So we tried to do something like that.
- 12:23So with Grok, we had some sort of moderate success because it sort of benefited also from the larger Zope community.
- 12:31People did start using it.
- 12:33And it was a lot easier to start a new web framework project back in 2006 than it is in 2013.
- 12:38Yeah, the expectations were way lower of what a web framework had to be, right?
- 12:42It didn't have to be as polished.
- 12:44And the web itself was simpler, right?
- 12:46I think the web itself was simpler.
- 12:49But I think the main thing that I think has changed a lot is documentation.
- 12:54Back then you could start a new web framework and have, you know, some documentation, but not really exhaustive documentation.
- 13:01Or very good documentation and still get some traction.
- 13:05And these days that's a lot harder, I think.
- 13:07The web was simpler, but the basics of Ajax, I remember I implemented those early on in Grok as well.
- 13:15So that hasn't changed all that much in some ways.
- 13:18But of course, client-side development was still very different.
- 13:22There wasn't as much of it going around back then.
- 13:25Yeah, it was much, much smaller scale.
- 13:27I mean, maybe jQuery was around then.
- 13:29I don't even remember the time.
- 13:30Maybe not.
- 13:31I think it was right.
- 13:32Yeah, I remember.
- 13:32I think I used MochiKit for a while.
- 13:34But yeah, I don't know where the jQuery is around then.
- 13:36But definitely not AngularJS and a lot of those types of things, right?
- 13:41No, I did a framework there as well.
- 13:43I just keep creating stuff.
- 13:46You do create a lot of frameworks, I know.
- 13:47Yeah, because I can't help myself.
- 13:49So back in, I think, around 2010, it was just before all those client-side frameworks started emerging.
- 13:58I thought, oh, I have a great idea.
- 13:59I'll take my experience from server-side frameworks like templates and models and views and things like that.
- 14:07And I'll take some of those ideas and then see what happens when I use them on the client.
- 14:13So I created this JavaScript framework called OVL, which was based around jQuery, but allowed you to create views, view components for little bits of JSON that could identify themselves with a type.
- 14:27And then it would look up the appropriate view for it.
- 14:29And then you could just basically render a tree of client-side components driven by the server.
- 14:34And just around that time, Backbone emerged and then Angular and then all the others.
- 14:41And then I thought, okay, yeah, it was a good idea.
- 14:44But I just, because other people are having the same idea.
- 14:48And yeah, it was definitely an idea ripe for its time to take some of these server framework concepts and move them to the client.
- 14:54So OVL didn't get any traction.
- 14:56But I did learn a lot from creating it, which helped me.
- 15:01That's cool.
- 15:01It was absolutely the time.
- 15:03Yeah, it was definitely the time when there was many, a lot of evolution and creation around that kind of stuff.
- 15:09There still is, but a lot of, it was like every, every month you'd hear about something that's going to change the world.
- 15:16Yes.
- 15:16As you know, right.
- 15:17It's still changing quite rapidly.
- 15:19I, myself, I mean, people complain about JavaScript fatigue, but I kind of like it because I like the creativity around it.
- 15:25Yeah, and I can say I'm a client-side web framework hipster because I was doing that before it was cool.
- 15:31Definitely doing it before it was cool.
- 15:33Yes.
- 15:33Very interesting.
- 15:35So let's talk about your project, MorePath.
- 15:38One of the things, I watched a nice talk from you at EuroPython in 2014.
- 15:44I'll be sure to link to the video.
- 15:46And one of the things you started out talking about was why would one go and create a new web framework when Flask, Django, Pyramid, and lots more exist already?
- 15:55Yes.
- 15:55Yes.
- 15:56And that's basically because I can't help myself.
- 15:59It's just a creative urge.
- 16:03I mean, of course, there are reasons why I created one.
- 16:05I had a customer at the time who wanted something that could do REST APIs really well and was small enough to plug into a larger application.
- 16:15So I could have used an existing framework for it.
- 16:18But I said, you know, what if I just take some ideas I already have and I had some pieces of code lying about and I just put them together and I'll create a little framework.
- 16:26And that's where MorePath came from.
- 16:30And it's still a relatively small framework.
- 16:32It hasn't grown that much.
- 16:33Yeah, you describe it as a micro framework and it seems certainly like it fits well in there.
- 16:38It seems like somewhere between Bottle and Flask, maybe.
- 16:42I cheat a little bit because MorePath, the core itself, is just a couple of thousand lines of code.
- 16:48It's built on top of this predicate dispatch library called reg, which I also created, which is just 500 lines of code, I think.
- 16:57But then I spun off another library from MorePath called Dectate, which is a configuration Python sort of decorator configuration library that MorePath then uses to implement its directives.
- 17:08And that's also some, I don't know, hundreds of lines of code as well.
- 17:13So, you know, you can still be micro if you depend on a few libraries that you're also maintaining.
- 17:19But nonetheless, it's still pretty small.
- 17:21I think it's about the size of Flask.
- 17:23So it depends a little bit on what you count.
- 17:26If you count the template language implementation or you count the request response implementation, which is WebOp in case of MorePath.
- 17:33How do you add up these things?
- 17:36How many lines of code is a micro framework?
- 17:38But yes, it's small.
- 17:39Yes.
- 17:40Yeah, in my mind, micro framework is more about the exposed feature set and how much I have to learn to work with it.
- 17:47More than whether it's a thousand or two thousand lines or whatever.
- 17:51That's true.
- 17:51Yeah, that's true.
- 17:52And in that sense, I feel like your framework is something you can pick up pretty quickly and you can kind of understand a good portion of it.
- 17:59Yes.
- 17:59Yes.
- 17:59Pretty quickly.
- 18:00So let's talk about the goals first.
- 18:02Like what were the goals of this project?
- 18:04So one of the things that I had been doing with Grok is I started using...
- 18:11So I have to go back to ZOPE again.
- 18:13ZOPE and also Grok use this database called the ZDB, the ZOPE object database, which is a pretty nice object store for Python.
- 18:23You can just put in any almost arbitrary Python object, hook it up to another Python object just as an attribute.
- 18:31And as long as there's some path to a root object, then everything gets persisted automatically for you.
- 18:37That makes it really flexible because you can just basically store any kind of Python object to represent any model that you'd like.
- 18:45It sounds like a kind of early concept of what document databases became.
- 18:50Yeah.
- 18:50I mean, it's very tied to Python, which is both its strength and its weakness.
- 18:54Because, you know, if you change your class, then suddenly the instances need to be updated.
- 18:59But it used to be very hard to explain because when you said database, the late 90s, early 2000s, people just assumed you were talking about a relational database with SQL on it.
- 19:08And there was nothing really else that people were familiar with.
- 19:12And then no SQL happened, and then it became a lot easier to explain.
- 19:16It's like a hipster NoSQL database because there was NoSQL before there was NoSQL also.
- 19:21Yes.
- 19:22Yes.
- 19:23I mean, that makes some things very easy, but I needed to integrate a relational database with Grok.
- 19:29And one of the nice features about the ZOPE database is that you can vary.
- 19:35Well, okay, we have to go back to the ZOPE publisher.
- 19:38ZOPE has this sort of publisher that's based on traversal.
- 19:42So you just traverse a Python object.
- 19:44So if you have a path A slash B slash C to resolve that to an object and then call a method on that object to represent it as HTML or JSON or whatever,
- 19:54it would basically just do a lot of get that there and get item into the object tree.
- 20:00So you would just get attribute A from the root, and then you would get item B from the item that you just got.
- 20:09And then you ask for get item from that object, and then you get another object, and then you call it represent me as HTML method on it.
- 20:19So that's how ZOPE worked.
- 20:20So that's how ZOPE worked.
- 20:21And the nice feature of that is that it also allows you to construct URLs really well because you can retrace the path that you took.
- 20:28So if you have an object like a document and you want its URL, you just can construct it automatically.
- 20:35So I like that feature of object database and traversal.
- 20:39So then with Grok, I wanted to integrate a relational database, and I was using SQLAlchemy, but I wanted to retain that feature.
- 20:46And then first I sort of tried to coax SQLAlchemy to become a traversable tree.
- 20:55And while SQLAlchemy, it being very flexible, made that possible.
- 21:00It was not really very – it didn't really fit the models very well.
- 21:03And to have to adjust the models just so you can actually traverse to it with URL paths, this didn't really work very well.
- 21:09So then I had this idea, okay, I'll do it another way.
- 21:12I'll create a routing framework, but one with the property that you route not to a view but to the model, just like I was used to from the ZDB.
- 21:20And also I have the property that you can take instance of a class that is in the routing system and ask for a link to it.
- 21:30And then it will just construct it automatically from the routing information that it has.
- 21:34Right.
- 21:35So you could do something like if you had, say, like a customer, let's say.
- 21:39Uh-huh.
- 21:39Your routing URL might look like something like slash customers slash seven.
- 21:45Sure.
- 21:45It might know that, okay, well, that seven actually corresponds to the customer ID.
- 21:49And then you have attributes – you have decorators that will indicate, like, well, here's the function that you call to actually do that query and represent it however it's going to be represented.
- 22:00Yes.
- 22:00Yes.
- 22:01That's how it works in mobile path.
- 22:02In Crockett still had a slightly different sort of – there were no decorators.
- 22:06But otherwise, yeah, that's more or less the principle.
- 22:09So to resolve something, you first look up the model instance.
- 22:13You first do your query or you construct some kind of Python instance.
- 22:17You return this from a function that's connected to the route.
- 22:20And then after that, you look up a view function for it, and it can do this based on the class of what you just found and information in the request and things like that.
- 22:29So you can find this view function, and the view function gets the request and also the instance that you just returned from the path function.
- 22:37And then you do your rendering in there.
- 22:39And that has the nice property that you can link to any class that you exposed to that routing system.
- 22:45Do you, like, register documents or type entities?
- 22:49Can you say these are the entities that you might be able to go to?
- 22:52I register whatever models my views need.
- 22:56So in some cases, those are backed by a relational database like a customer.
- 22:59And in some cases, I need to create a model that represents, for instance, a collection, which is not really backed directly by a relational database.
- 23:07But you can implement it in terms of queries as well.
- 23:11And then you just attach views to that collection class.
- 23:15So, yeah, with Grok, I figured this out.
- 23:18And then with Moapath, I sort of took that idea and cleaned it up and made that sort of one of the central principles of the web framework.
- 23:27And I think sort of besides the easy linking, which was sort of the primary motivation, I think it also really helps structuring code.
- 23:36With other web frameworks, you often you see some kind of get this object from the database or if you can get it, do a 404 error kind of convenience function.
- 23:46And if you don't use that convenient function, you have to watch for, you know, a failure to find the object.
- 23:53And if you do so, you have to remember to raise a 404 error yourself.
- 23:57And with Moapath, because it has more knowledge about being able to find the model or not.
- 24:01It's not hidden inside of a view function like you would have in Flask or Django.
- 24:06Right.
- 24:06And if you screw that up in, let's say, Flask, you probably get like a none type does not have like whatever property you're looking for error, right?
- 24:14Yeah.
- 24:14You'll get a 500.
- 24:15Yeah.
- 24:15You're getting a 500 error.
- 24:17That surfaces as, you know, cannot process requests, 500, which always gives people confidence in your application.
- 24:23Yes.
- 24:23Yes.
- 24:23Yeah.
- 24:24It turns out that if you have to write that boilerplate code anyway in your application, it almost doesn't cost anything anymore to just write a separate function to separate it into two stages.
- 24:35And you get other features from that as well.
- 24:37You can do permission checks also because you have an idea of the instance that is being represented.
- 24:43So you can say, okay, well, customers are only accessible.
- 24:46Views for customers are only accessible if you have a certain permission.
- 24:51And you can actually make sort of the concept of customer play a part in your authorization system as well.
- 24:58That sort of all these, because you constrain yourself to really route to a model instance first and then to a view you get from that constraint to framework and benefit and build on top of it.
- 25:10Let me take just a moment and tell you about Metis.
- 25:13Metis, a sponsor of this episode.
- 25:15A data scientist's responsibilities can range far and wide.
- 25:19How can you be sure you have the necessary skills and training to enter the field or keep up with emerging technologies?
- 25:24Metis, a data science training company based in New York City, San Francisco, Chicago, and Seattle, provides full-time immersive boot camps, evening part-time professional development courses, online resources, and corporate programs.
- 25:38All with a goal of training you to become a data scientist and help you stay on top of new and necessary skills.
- 25:44Metis has a long list of professional development courses starting soon in any of these four cities taught by industry leaders.
- 25:52Interested in honing your skills?
- 25:53Then these courses are for you.
- 25:56How do they work?
- 25:56Courses on topics like data visualization, deep learning with TensorFlow, machine learning, and statistical foundations run two nights a week for six weeks during the evening hours that fit into your busy schedule.
- 26:07These courses are laser-focused on relevant topics and skills that are sure to enhance your career.
- 26:12They have a special offer for you at thisismetis.com slash talkpython.
- 26:17Be sure to check out what they're offering.
- 26:18It helps support the show.
- 26:20Sounds to me like you focused very heavily on RESTful type of ideas, right?
- 26:28Like the routing framework assumes that there's some kind of resource or model at the end,
- 26:35and you can use like get to do default queries on it and things like that.
- 26:39Yeah.
- 26:40One of the sort of the basic ideas behind Moapath when I started developing it is to be good at doing REST.
- 26:46It turned out that actually, you know, a framework that's good at doing REST actually is also pretty good at doing traditional server-side web applications as well that do generate HTML.
- 26:57Those things are not in conflict with each other at all.
- 27:01But, yeah, the initial goal was to do REST well.
- 27:05And actually template language implementation took, I think, a year and a half or so until I finally got around to doing that.
- 27:12Okay.
- 27:12So some of the origins was almost to make this something that you can serve up almost static HTML with rich JavaScript that reaches back to the server for all sorts of data and whatnot.
- 27:22Yeah, because I had been developing, you know, even with OVL, I had been developing that way.
- 27:27So I had some ideas of what I wanted my framework to be able to do also from the client-side perspective.
- 27:33And one of the things that I sort of always have been is I tried to actually do real REST.
- 27:39These days, REST, the term has become so eroded that it basically just means, yeah, it means endpoints that the client just needs to know about.
- 27:49And it returns some kind of data format, but it doesn't involve linking or anything like that.
- 27:54So I always actually try to do and work with real REST where your JSON data structures also include links to other structures to sort of the other endpoints and that you can sort of enter your application with one root endpoint and then find sort of all the links and follow them.
- 28:14And perhaps also embed objects if you want to get to me.
- 28:18To me, REST has become a synonym for HTTP-based services.
- 28:22Yes.
- 28:22Usually that return JSON.
- 28:23But I think the two things that are often neglected that you are hinting at is one is content-type negotiation.
- 28:29Uh-huh.
- 28:30And the other is the dynamic linking and discovery, right?
- 28:33You request an original resource and it tells you like how you can continue to explore the service.
- 28:38MorePath has good support for content-type negotiation, right?
- 28:42Well, actually, that's a thing I have cared less about.
- 28:46So it's actually, we do have a really powerful system which allows you to build that should you want to.
- 28:54But I haven't seen a lot of people actually try.
- 28:57So the idea that if you request HTML, you'll get HTML from the same URL as where you, if you request JSON, then you'll get JSON.
- 29:05Or perhaps you have multiple, even multiple versions of your API that are sort of negotiated that way.
- 29:11In practice, I haven't seen a lot myself yet.
- 29:14That doesn't mean very much.
- 29:16Sure.
- 29:17But you can go to like a view and say, you know, at app.json, at app.html and things like that, right?
- 29:24Like theoretically.
- 29:25Yes.
- 29:26What you can do is you can name multiple views and then you can do, well, it's not negotiation,
- 29:31but you can just say, okay, I want my different version of this or a different view entirely, actually.
- 29:37Because views are looked up by the class of the model, but also by the request method
- 29:43and also by the name of the view, which is the last part of the path.
- 29:47If it's there, you can use an add sign.
- 29:49And you can also look up views if they have a body.
- 29:53You can actually look, interpret somehow the post body if it's JSON and then switch to a different view if you post something else.
- 30:02Just have it dispatched to a different function.
- 30:04And that whole system is extensible.
- 30:06So you could just write a new directive and add more criteria for your views in your own application.
- 30:13And it's actually possible to have, in the same runtime, to have one application that uses more criteria than another one.
- 30:19And they will just live next to each other because of more path configuration system.
- 30:24So you can add stuff that looks at the accept header.
- 30:27That's pretty easy to implement sort of in a basic case.
- 30:30But if you want to do full accept header support, it tends to get a little bit hairy because there's a lot of different possibilities there.
- 30:36I find, yeah, right, that's a very rarely used feature of services.
- 30:42Usually people say, go to this URL, do a get, and you're going to get JSON or something like that.
- 30:47Yeah, because the information is encoded in the URL, right?
- 30:51You can just see it.
- 30:51And if you suddenly have to worry about, I mean, yeah, content types that you do the request with,
- 30:57it becomes a lot harder to sort of get an idea in your head of what's going on.
- 31:01Yeah, yeah, for sure.
- 31:02So one of the things that you talk about that I thought was cool, and you even had some nice hand-drawn pictures.
- 31:09Nice, yes.
- 31:11In your presentation, yeah.
- 31:12And one was like a web framework and embodied as a person pulling their dress shirt open,
- 31:20and there's like a more path superman type suit underneath.
- 31:24You talk about the superpowers of more path.
- 31:27Do you want to touch on those a little?
- 31:28Right.
- 31:28So some of them I've touched on already, but one of the superpowers, I would say, is the dispatch system.
- 31:36So the view dispatch system, but it's also used in other areas like this authorization system uses it, for instance,
- 31:43allows you to write Python functions that dispatch on not just one argument like you have normally in Python with a method that dispatches on self.
- 31:53At least you can look at it that way.
- 31:55So the class of the self-argument of a method with the same name determines which actual method gets called.
- 32:02You can also dispatch on other arguments as well, and not just its class, but also other attributes of those arguments.
- 32:11And that allows the view system to dispatch on the class of the model.
- 32:14The request methods get boot post of the request, the view name, which is also stored on the request, the last part of the path.
- 32:22But also if the accept header or, you know, the type of the JSON body that you submit or whatever else you come up with.
- 32:30Yeah, I can tell linking is super important in this whole routing and linking is really a key part of what you're trying to focus on.
- 32:37Right.
- 32:38But yeah, this is the dispatch system.
- 32:40Okay.
- 32:40That's not the linking or the routing system.
- 32:42It allows you to write views that can be really general, work for, you know, any subclass of a particular base class, or be really specific for a specific class as well.
- 32:55And you can dispatch a lot of different factors.
- 32:58So that's the reg bit.
- 32:59Yeah.
- 32:59There's almost like an inheritance thing that you can do with that stuff, right?
- 33:03Yes.
- 33:03You can kind of override a view in a specialized class.
- 33:06Okay.
- 33:07Gotcha.
- 33:07Yes.
- 33:07Yes.
- 33:08So it's like, basically, if you just look at the model bit of how you register views, it's very much like you define methods, but you don't define them inside of the class.
- 33:17You define them just as functions outside of the class.
- 33:20And your decorator says where they belong.
- 33:23But basically, that's just one factor of what it does to look up with.
- 33:28And authorization also works that way.
- 33:30It's like, do I have this particular permission for this particular model instance?
- 33:35And then it also knows about inheritance.
- 33:37So you can be very specific about, well, this subclass needs to have a different permission rule than everything else.
- 33:42And that's reg.
- 33:43Then there is the, well, the automatic link generation already talked about, which I think is really neat.
- 33:48Most frameworks don't really do it.
- 33:52I mean, they do it sort of halfway, where you say, okay, well, you need to give all your routes a name.
- 33:58You need to come up with a name and remember that and maintain that.
- 34:00And then when you want to generate a link from your Python code or your template or whatever, you need to use a special API or do this special thing.
- 34:08And then you need to give it all the variables that are needed to construct the link again.
- 34:14So you need to know still what those things are, whether that's the ID or whatever the link construction is based on.
- 34:22Yeah.
- 34:22And it usually appears in multiple places.
- 34:24There's usually some configuration thing where you define the route for the URL dispatch.
- 34:28And then there's the actual template where you put the thing.
- 34:31And you have to know, okay, I have to replace, you know, these two parts of the URL with this part of data.
- 34:37And then in your actual view, you've got to pull that data out of the route data that was passed.
- 34:44And it's at least in three places.
- 34:45So you have to do that.
- 34:47And if you have multiple places where you link to the same thing, you have to do it sort of in multiple places.
- 34:53And that also makes the code less generic because suddenly it's dependent on sort of the particular structure of what you're linking to.
- 35:00And if you were to change that, then you would have to change all the templates to link to it.
- 35:03Yeah.
- 35:04Everything breaks.
- 35:05And so what I do on my web apps is on my model, I will use like some kind of rich class and then convert it to a dictionary at sort of render time.
- 35:15But I'll put like a method like here's the function or the property that gets me the URL with all the pieces filled in.
- 35:22So I'll go in like template and say, you know, dot like purchase URL or whatever.
- 35:26Yeah, exactly.
- 35:27You kind of bake this concept directly into more path in a sense, right?
- 35:31Yes, yes.
- 35:32So it's that concept.
- 35:33But then you don't have to burden your classes, your model classes with information about the web, which is basically, I mean, it's a reasonable compromise.
- 35:41I see Django.
- 35:42You can also do it with Django.
- 35:43There's a convention there as well.
- 35:45It's still, I mean, why would my model class know about URLs?
- 35:49That's the whole point about routing framework is to not have to worry about that kind of stuff in the model classes.
- 35:55Exactly.
- 35:56You look at the standard MVC design pattern.
- 36:00There's, you know, an arrow from down to the model, but there's no arrows back from the model, right?
- 36:06Which is like these basically what I'm proposing, right?
- 36:08That it knows how to get back to these things.
- 36:10Yeah.
- 36:10And more path knows how to do that.
- 36:12But the information is stored outside of the model classes themselves.
- 36:18Nice.
- 36:19In the configuration system.
- 36:20But that allows generic code as well.
- 36:22If you, you know, make, have a list of objects and you just want to create a list of links to it.
- 36:27And those objects might be completely different places in your website.
- 36:30I mean, if you were to solve that with, well, you can solve it if you, again, burden your model with this get URL method, then you can do it.
- 36:38And without that, you would have to use a lot of special cases in your template or whatever to create the right link.
- 36:44So more path does that for you.
- 36:46It gets the information that it needs from the models.
- 36:49By default, just there's a convention that the name that you use in the route is the name of the attribute, but you can override that to reconstruct it.
- 36:57So that's really powerful.
- 36:59And then there's the configuration system.
- 37:01So more path has an actual sort of thought through configuration system as an entity by itself, which should not be that unusual for web frameworks, but it actually is.
- 37:15And what I mean with the configuration system is the system that lets you express things like, okay, well, this route exists and this view exists and I have this permission to access that view.
- 37:29Or I want to install a middleware that sits between the request and the handler and the response and sort of can interfere in there.
- 37:37Or I have a template rendering engine that I want to plug in.
- 37:41All those things I consider to be configuration.
- 37:44And that's really my SOAP history speaking, because in SOAP 3, that was one of the big innovations.
- 37:50We created this XML-based confirmation language called ZCML, where you would express all of this in XML files, which sounded really cool at the time.
- 37:59But one of the things that I did...
- 38:01You just put this namespace here on this XML element that it'll...
- 38:05Oh, yeah.
- 38:06Just kidding.
- 38:07Oh, yeah.
- 38:08Well, you know, you would just have an XML, a little XML language.
- 38:12That was namespaced, of course, where you would say, okay, well, this...
- 38:14Well, you did have routes, but you would say, this view has this permission.
- 38:18And if you...
- 38:20There were all kinds of things that could be configured.
- 38:23You would have adapters and things like that.
- 38:25But that's all pretty low-level stuff.
- 38:28But also services like, you know, the service that can send email is here.
- 38:33So if the application asks for it, just look at the configuration, basically, for the service that can send email.
- 38:38That kind of pattern you tend to see a lot in larger applications that need to be customized in different contexts, like a CMS, for instance.
- 38:51This portion of Talk Python is brought to you by Hired.
- 39:01Hired is the platform for top Python developer jobs.
- 39:04Create your profile and instantly get access to 3,500 companies who will work to compete with you.
- 39:09Take it from one of Hired's users who recently got a job and said,
- 39:12I had my first offer on Thursday, after going live on Monday, and I ended up getting eight offers in total.
- 39:17I've worked with recruiters in the past, but they've always been pretty hit and miss.
- 39:20I tried LinkedIn, but I found Hired to be the best.
- 39:23I really liked knowing the salary up front.
- 39:25Privacy was also a huge seller for me.
- 39:28Sounds awesome, doesn't it?
- 39:29Well, wait until you hear about the sign-in bonus.
- 39:31Everyone who accepts a job from Hired gets $1,000 sign-in bonus.
- 39:35And as Talk Python listeners, it gets way sweeter.
- 39:37Use the link Hired.com slash Talk Python To Me, and Hired will double the sign-in bonus to $2,000.
- 39:43Opportunity's knocking.
- 39:45Visit Hired.com slash Talk Python To Me and answer the door.
- 39:48What I did with Grok is already tried to merge that back into Python, so you could express it.
- 40:00Well, we didn't really have class decorators at the time, and function decorators were very new,
- 40:05so we did it in another way.
- 40:07But you can express it inside a Python code.
- 40:09And then with Morpath, I express it with decorators.
- 40:12And all those decorators are attached to classes, application classes, subclasses of the Morpath application,
- 40:18that allows you to be classes you could inherit.
- 40:23So you can say if you want to inherit all the configuration of a particular base class,
- 40:26and then override specific bits of configuration, like one view or added piece of middleware or whatever,
- 40:33you could just do that with subclassing.
- 40:35And then you add your configuration to the subclass, and then your base class still has the original configuration.
- 40:40So if you were to run that by the WSGI server, it would still behave as it did originally.
- 40:45But your subclass has the new, if you instantiate that, you again get a Whiskey app,
- 40:50and that will have the new behavior.
- 40:52And that's really powerful.
- 40:54And that was also powerful is that you can actually compose those little applications together into a larger one.
- 41:01So Morpath allows you to mount applications onto other applications,
- 41:04which all could have their complete different configuration.
- 41:08It could even override some very basic behavior of Morpath and run in the same runtime.
- 41:13Sure.
- 41:14So give me some examples of what two or more applications might look like,
- 41:18how do they work together, what's a practical story there?
- 41:21Well, so for instance, if you wanted to develop something like a GitHub,
- 41:25where you have projects, projects could have issue trackers.
- 41:30And you also have a wiki, perhaps, in a project.
- 41:33Now those issue trackers and wikis could be implemented as separate applications
- 41:38that don't know anything about projects or each other.
- 41:41So you could configure them with their own routes and views and things like that.
- 41:45And then you can mount them together onto the project application,
- 41:49should you want to use the wiki and the issue tracker there.
- 41:53But if you wanted to mount them somewhere else in a completely different project,
- 41:56you wanted to use the wiki, you could mount it there.
- 42:00And in the mounting, the active mounting, you define sort of how to translate from the
- 42:05sort of the outer applications set of concepts to the, for instance,
- 42:10find the idea of the wiki app or whatever to find the wiki in the database.
- 42:13So they're really isolated from each other.
- 42:16But you could combine them with composition.
- 42:18And then, you know, if you have a customer that likes the wiki and it's all perfect,
- 42:23but just wants to tweak this one little thing, you know, in their deployment,
- 42:27then you could subclass the wiki and change it in that one little way.
- 42:31Hopefully, your wiki will let you do that.
- 42:33That's still up to the design of the application.
- 42:36But yeah, that kind of sort of feature is something that I was used to from Zope 3.
- 42:41And Pyramid is the other Python web framework that has this kind of capability,
- 42:46though it does not have the mounting system.
- 42:48I don't believe Pyramid allows you to run multiple configurations in the same application.
- 42:52But I might be wrong.
- 42:53Sure.
- 42:54You might have to just merge it.
- 42:55But at least it has this notion of configuration, override, extension, that kind of thing.
- 42:59And Moopart tries to let you do that while also being really simple to use.
- 43:06So you just, you know, you have application classes and you can subclass them.
- 43:10Sure.
- 43:10That's really cool.
- 43:11So instead of having one big monolithic app,
- 43:13you could write a bunch of small apps and then sort of glue them together.
- 43:17Yes.
- 43:17Yes.
- 43:18Okay.
- 43:18That's really, yeah, that's really cool.
- 43:20You have a couple of ways to get started.
- 43:23Like if I want to get started with Moopart, like what are the few steps?
- 43:26You know, obviously pip install, Moopart, then what?
- 43:29Well, there is a...
- 43:29Do you scaffolding?
- 43:30Yeah.
- 43:30We have a cookie cutter template out there now.
- 43:33It's in the documentation.
- 43:34So you could use that and then you get set up with a slightly bigger Moopart application.
- 43:41I've been resistant sort of to doing something like this for quite a while
- 43:46because I find that if you do a lot of scaffolding,
- 43:50it sort of becomes tempting to put a lot of,
- 43:53sort of generate a lot of code basically when your project starts.
- 43:56And then I always think, okay, why is that not a library?
- 43:59Why cannot, is that not configuration?
- 44:01Why is there so much sort of stuff that gets generated just to get an application going?
- 44:06Yeah.
- 44:06I think that, you know, Django sort of has that, right?
- 44:08Yes.
- 44:09It's a sense that people think Django is huge, but you can actually create like a one file simple Django app.
- 44:16It's just nobody does it.
- 44:17So it feels larger.
- 44:18I think it's so...
- 44:19Yeah.
- 44:19I think also Django is larger in other senses, but I believe...
- 44:23No, yeah.
- 44:23It is larger, but it has its ORM and a template language and a lot of other things.
- 44:27You know, and I think Pyramid suffers from this as well in that it feels really big
- 44:32because when you create it, there's so many pieces.
- 44:34I don't necessarily mind that, but I think that's the message that it does send, right?
- 44:38It's a different philosophy, I think, and both of them have their benefits.
- 44:42So Pyramid, I think, really tries to keep a lot of options open and to be sort of a little toolkit
- 44:48that you can use in very different ways with a ZDB, with a relational database, with routing,
- 44:55with traversal.
- 44:56Sort of it has all those different options and it tries to be pretty neutral about sort of
- 45:01what the way that you pick is.
- 45:04And that's...
- 45:08I mean, that's useful, but with Moopata, I try to be a little bit more opinionated.
- 45:12I mean, it's still a micro framework.
- 45:13You can still do a lot of different things, but I do say, okay, there's routing and you
- 45:17route the models.
- 45:18There's no traversal.
- 45:19There's no routing to views.
- 45:21You could plug it, the OPEC database is completely database agnostic, but it tries to be a bit
- 45:26more opinionated about some bits in the hopes that that also makes it more approachable
- 45:30so that basic application is not so much heavy lifting.
- 45:35Sure.
- 45:35Well, I think opinionated has been the success of Ruby on Rails.
- 45:39It's been the success of Django to some degree.
- 45:42So it's not necessarily bad.
- 45:44No, no.
- 45:45Opinionated is not bad, but it's sort of a tricky balance between being a micro framework
- 45:49and being flexible, but still being opinionated.
- 45:52But, you know, if you're going to be a framework, you have to have some opinions because otherwise
- 45:56there's no point at all, right?
- 45:59You're a framework.
- 46:00You're supposed to guide people in one direction or another.
- 46:03And Pyramid does have opinions.
- 46:05It has opinions about the configuration system, about these.
- 46:10It uses the SOAP component architecture to put things together, and those things are pretty
- 46:15fundamental to its use.
- 46:17Yeah, absolutely.
- 46:18So there's a place in MorePath where I can plug in some kind of middleware?
- 46:22Like, what are the options for that?
- 46:24Are there many things I can choose from and wire together?
- 46:27There's a tween system, and I just took that term and the concept from Pyramid.
- 46:31I stole a lot of ideas from Pyramid and Chris McDonough because he went there first, right?
- 46:36He was coming from SOAP, and then he thought, okay, I'm going to do it better.
- 46:39And then he was very successful doing that.
- 46:43And then I thought, okay, well, let's try as well, see where I end up.
- 46:46So tell people about what tweens are in case they don't know.
- 46:49It's a slightly higher level abstraction of what a whiskey middleware is.
- 46:53A whiskey middleware is a little bit too low level because whiskey is very low level.
- 46:57But a tween is a function that takes a request object and calls some kind of handler, which
- 47:04is your application or another tween that's sitting below, that returns a response object.
- 47:11And because you have this function that you plug in, you can do stuff to the request just
- 47:14before it goes into the handler, or you can do stuff to the response just before it comes
- 47:19out of the handler.
- 47:19And that allows you to do all kinds of neat stuff like commit transactions or do stuff
- 47:26to the HTML that comes out of the system or whatever.
- 47:28Right.
- 47:28Like I think rollbar is a tween in Pyramid, and you can install it.
- 47:35And anytime there's a 500 error, it'll capture all the details and send that off.
- 47:40And all you've got to do is like pyramid.include rollbar middleware name.
- 47:44It's like pyramid.trib.rollbar or some variation of that name.
- 47:48Yeah.
- 47:48Django also has its own middleware system, which is very similar.
- 47:52With Moabot, it plays sort of into the configuration system.
- 47:55Though, of course, only the outer application, mounted applications, they all share the same
- 47:59middleware of the other application.
- 48:01But with inheritance, yeah, it allows you to basically make available a Moabot application
- 48:07that has some middleware installed.
- 48:09And then if you subclass that, then that middleware is there as well for you.
- 48:13So you don't have to know very much to use middleware.
- 48:16And you can also configure a middleware to go on top of that or just under it.
- 48:23And then Moabot takes care of doing the sorting so that everything happens in the way you specified,
- 48:29if it's possible at all, of course.
- 48:30Sure.
- 48:31Of course.
- 48:31Okay.
- 48:32Yeah, very nice.
- 48:33What kind of templates are supported?
- 48:35Like, do you have Chameleon?
- 48:36Do you have Jinja 2?
- 48:38Yes, so Chameleon, Jinja 2, and Mako, I believe.
- 48:40Okay.
- 48:41Yeah, those seem to be...
- 48:43Much plugins.
- 48:43They're not out of the box.
- 48:44You just need to install the template dependency, more.chameleon or more.Jinja2, etc.
- 48:50And then you just subclass from a base class that those packages expose.
- 48:54And then you have that template language available.
- 48:57So then when you use that extension, those particular extensions, like .pt for Chameleon
- 49:03and .Jinja2, I believe, for Jinja 2, then it will just render using that template
- 49:07language.
- 49:08You could even use both in the same app if you wanted to.
- 49:10Yeah, and one of the other types that you have is just straight-up JSON, right?
- 49:14You can just put it in decorator save.
- 49:16This thing renders as JSON.
- 49:18It just converts directly.
- 49:19Yeah, then you just return a Python structure that can be serialized to JSON.
- 49:23Okay, excellent.
- 49:24What's the deployment story?
- 49:28Like, this is just a straight-up WSGI application, so I can put it on uWSGI backed by Nginx
- 49:34or Gunicorn or whatever I want, right?
- 49:36Yes, yes.
- 49:37If you take the application class and you instantiate it, then you get a WSGI application
- 49:42and you could just hook it into whatever you like.
- 49:44Okay, excellent.
- 49:45Excellent.
- 49:46How about Python 3 versus Python 2?
- 49:50What's the status of the various versions?
- 49:53Well, we support both.
- 49:55We have for some years now.
- 49:56For more path, that's fairly simple.
- 50:00For reg, there's a few very dark corners of Python that we have to be aware of.
- 50:05But yeah, both are supported.
- 50:06Okay.
- 50:07Yeah, excellent.
- 50:08It's good to see lots of projects supporting Python 3 these days.
- 50:11Nice to hear that one does.
- 50:12Yeah, it's easier for libraries than for applications.
- 50:15So if you have a test suite, that's pretty comprehensive.
- 50:18It's pretty doable.
- 50:20Okay.
- 50:21Excellent.
- 50:21So you're also involved in some other projects, and we're getting kind of the end of the show.
- 50:25So maybe we just really quickly say what they are and then one or two sentences about it.
- 50:32I don't want to go deep on it, but just to let people know the other projects that you've worked on.
- 50:36So we talked about Zope and Grok already and Ovil, more path.
- 50:43But you've also done some stuff with LXML, right?
- 50:45Yeah, I created LXML years ago.
- 50:48I've been messing around with XML and Python.
- 50:50XML was way cool back in 2000.
- 50:52I remember.
- 50:53So I messed around with Python and XML, and I tried to write my own DOM implementation a few times
- 50:59and created sort of a start of an XPath implementation at one point.
- 51:04And it was all very interesting, and I learned a lot, but none of them sort of became anything very useful.
- 51:10And then at one point, I had already worked with the LXML2 library, which is this really fast,
- 51:17very featureful XML library and LXML2 on top of that, written in C.
- 51:22And they had Python minings, but they really sucked because it was like programming C in Python.
- 51:28So if you were to initialize something wrong, then you get a sec fault in Python.
- 51:34And if you forget to freeze something, you would just get a memory leak in Python.
- 51:40And those things are not something you want from a Python library.
- 51:44So I decided, okay, let's be minimally ambitious and build on top of this LXML2 library because it's really fast.
- 51:53And I tried to create a Pythonic API and also not invent a Pythonic API for XML because Fred DeKlant already had done that.
- 52:00He created element tree.
- 52:03And there wasn't any C element tree at the time, just element tree.
- 52:06So what I did is, okay, let's create an element tree API with extensions for XSLT and XBot and all those things on top of a libxml2.
- 52:16So that's what I did.
- 52:17That actually is quite tricky because of trying to do garbage collect C objects that can be in tree shape to each other.
- 52:27Things that, I mean, can be separate from each other, but maybe, you know, there's all kinds of sort of interesting details there.
- 52:33And I used a technology called Pyrex at the time, but it's now been renamed to Cython.
- 52:38So I was a very early adopter of Pyrex because I didn't want to write all that secret myself.
- 52:43And then one of the best things in my open source career sort of happened.
- 52:47So I worked on Alex Melt for maybe a year or so, and I got sort of it working, and I was doing garbage collection, and there was an element tree API, and it was all working pretty nicely.
- 52:57And then this German guy, Stefan Benel, he started sending me lots and lots of patches and all kinds of enhancements and features and things like that.
- 53:09And I basically, I was busy.
- 53:10I couldn't really keep track of all the patches, and then I made the conscious decision at one point.
- 53:15I remember it being the end of the year at one point, and I mailed him, and I said, you know, now you're co-maintainer of the project.
- 53:22You can do whatever you like.
- 53:23So I gave him that power and responsibility.
- 53:27And that was a very good move because he's been maintaining Alex Melt since then, which is like, I don't know, more than 10 years now.
- 53:35And added lots of features and improvements and things to it.
- 53:38And he also descended down the stack because he ran into Pyrex because I was using that, and he wanted to improve that as well.
- 53:45And in the end, he and some sort of people from the data sciences angle, they forked Pyrex, and they basically created Cython because, you know, he was descending through that as well.
- 53:57And I sort of always wondered, like, if he keeps descending, you know, eventually he'd be doing microcode architecture for CPUs or whatever.
- 54:05But he stopped there.
- 54:07As far as I know, he's only doing Cython, but he's been a very capable maintainer.
- 54:12So I always say that I put AlexML in the open source bank, and I'm getting interest on it because people have added features to it since then.
- 54:22And I still use – I was using AlexML just this week in a project.
- 54:26It's still – I still run into it, and I just use it as a library now, but I did create it originally.
- 54:32It's probably a good feeling, though, to run across other people's projects and go, oh, there it is.
- 54:36Yeah.
- 54:36It's a very good feeling.
- 54:37It's also very useful to say to Potential, because I'm a freelancer, so it's very useful to tell Python people that you created AlexML because then, oh, yeah, we used that.
- 54:46Most people know.
- 54:47Yeah, yeah.
- 54:48Oh, prove to me that you actually know what you're doing.
- 54:50Yeah, that library you're using?
- 54:51Yeah.
- 54:51I read that already.
- 54:52Yeah.
- 54:52Oh, all right, then.
- 54:54So that's pretty neat.
- 54:56Plus, yeah, I've been drawing interest on the – I mean, usually when you have an open source project, you don't really draw interest on it.
- 55:01This is an exception.
- 55:02Yeah, there have been features added to AlexML, like HTML parsing and all that stuff that I've used in the past that they were just pure interest payments on my initial investment.
- 55:13Oh, absolutely.
- 55:13Cool.
- 55:14You also did something called Fantastic and Bower Static.
- 55:17What are those two?
- 55:18Yeah, FanStatic, actually.
- 55:20Yeah, it's very hard to pronounce.
- 55:21Oh, FanStatic.
- 55:21Yeah, I got to read more carefully.
- 55:22Yeah, it's a joke.
- 55:23I mean, it's the plain words.
- 55:24But it's about – those projects came out of something I actually started with, hurry.resource, which was a SOP project.
- 55:35So what I needed was sort of JavaScript files in my application, and those JavaScript files had dependencies, and there was no dependency system for JavaScript.
- 55:46So I created one in Python, and a resource eventually got sort of renamed FanStatic and refactored into it.
- 55:54And the idea was to piggyback on Python's packaging infrastructure and Python's dependency infrastructure by just having modules where you declare that you have a JavaScript file or maybe a CSS file, other statistics resources, and how they depend on other ones.
- 56:09And then it can automatically generate include statements or generate rollups for you in a web page.
- 56:15Okay.
- 56:15Oh, very nice.
- 56:16And that's FanStatic, and it was sort of piggybacking, so you could release, like, jQuery as a Python package, and then you could just install it like that and start using it.
- 56:26And it would be – you could use it as a whiskey middleware, so you would just insert FanStatic on top of your web framework.
- 56:35And then inside of your view code, you would say, okay, I need this jQuery or whatever, or jQuery UI, and then it would figure out it would need jQuery as well, and then it would just include the right script text for you automatically.
- 56:46By the middleware, we just automatically do that.
- 56:49So that became an open source project a bunch of us worked on.
- 56:53But, of course, JavaScript now does have a dependency system.
- 56:56It took a long time, but – and a packaging system.
- 56:59So that became –
- 57:01And Power is one of those, right?
- 57:02Yeah, Power is one of those.
- 57:03And, you know, when I started BowerStatic, it was basically, okay, I'll just whip up something that's based around Power because there's a packaging system already there.
- 57:11In some ways, BowerStatic is less powerful than FastStatic, but at least you can install a Power package.
- 57:16You don't have to wrap all your JavaScript code inside of a Python package and then upload it to PyPy anymore.
- 57:22You can just use the Power package database.
- 57:25These days, you know, I use BowerLess and less as well.
- 57:28I tend to just go for CommonJS packages on npm and then use the tools that exist for that to package up my JavaScript code.
- 57:37There are still use cases like BowerStatic can solve.
- 57:40They're a little bit harder to solve with those tooling because you have a – if you have the use case that you have that's typical for enterprise software, where you have one core application that needs to be deployed in multiple places with particular extensions.
- 57:57And if those extensions are also JavaScript code, bundling everything up for one deployment is not good enough.
- 58:04You would need to do something to bundle up things in pieces.
- 58:08And then if you want to ship them separately, it all becomes pretty hairy because the bundling tool needs to be run sort of at the very end.
- 58:16So for use cases like that, something like FastStatic or PowerStatic can still work better if at least your native enterprise installation system is something like Python packages.
- 58:31So that's a very specific use case.
- 58:33Those are both really nice touches.
- 58:34All right.
- 58:35So I think I'll have to leave it there for more, Pat.
- 58:37We've definitely got into a lot of detail, but I know there's a lot more we could touch on.
- 58:42All right, Martin, before I let you out of here, how about your favorite editor?
- 58:46When you write some Python code, what do you open up?
- 58:48I use Emacs.
- 58:49I sometimes try out other editors and then I go back to Emacs.
- 58:52I realize now what it is because I'm not really an Emacs power user.
- 58:56At least that's what I say, but I've been using Emacs so long that I...
- 58:59Probably are.
- 59:00...I, you know, learn more and more features over the years.
- 59:03But nonetheless, I wouldn't call myself an Emacs power user.
- 59:05But, you know, if you use it for 10 years and you learn a few features every year, you do know a bunch of features in the end.
- 59:12But the thing I really like about Emacs is that it just knows how my Python code is supposed to be indented.
- 59:18And if I press tab, it tends to do the right thing.
- 59:21Also in other languages, it indents stuff.
- 59:24And I'm so used to that that I tried Atom a while ago and it just didn't do indentation right for my tastes.
- 59:31I could press tab, I could install an extension and edit.
- 59:33It would let me press tab, but then it would just indent stuff wrong.
- 59:37And then I went back to Emacs again.
- 59:40So, yeah, we'll see.
- 59:43Yeah.
- 59:43All right.
- 59:43Cool.
- 59:44Yeah.
- 59:44There's a lot of...
- 59:45There's increasingly more options around the editors that are good, I think.
- 59:48Yes.
- 59:48That's cool.
- 59:49Yes.
- 59:49Yes.
- 59:49And favorite PyPI package?
- 59:51We've got 96,000, almost 97,000.
- 59:53I have trouble deciding.
- 59:55I mean, I like AlexML, of course, because I mentioned already I'm drawing interest on that one.
- 1:00:00So maybe I'll just stick to that.
- 1:00:02All right.
- 1:00:02I use so many and there are so many very nice ones, but I just can't really think of anyone in particular that stands out.
- 1:00:09Sure.
- 1:00:10It's like, which one of your children do you love the most, huh?
- 1:00:13Well, yeah, it's not even my own children.
- 1:00:15It's not even my own children.
- 1:00:15It's other people's children do I love the most.
- 1:00:18That's true.
- 1:00:18That's true.
- 1:00:19No, there are a lot of nice packages there.
- 1:00:21Let's see, whatever.
- 1:00:22I mean, I used Click recently.
- 1:00:24I like that.
- 1:00:24Yeah, that is nice.
- 1:00:25That's a nice little library.
- 1:00:26What else have I used recently?
- 1:00:29Well, I like, I've been messed around with numeric and pandas recently, but I was playing around with developing a data-driven game engine because, you know, why use numeric and panda for what they're really for?
- 1:00:45So I was trying to blast data into OpenGL with pyglet.
- 1:00:49pyglet is also a very nice library.
- 1:00:50See there?
- 1:00:51I remember packages now.
- 1:00:54So I blast OpenGL data into pyglet coming out of, oh, sorry, NumPy.
- 1:00:59I mean, of course, not numeric.
- 1:01:00So out of NumPy arrays, blast them into OpenGL to try to reduce overhead.
- 1:01:06Okay.
- 1:01:07That's a pretty interesting use case.
- 1:01:08Yeah.
- 1:01:08Yeah.
- 1:01:09All right.
- 1:01:09Awesome.
- 1:01:10Well, very interesting answers.
- 1:01:12Okay.
- 1:01:13So you got a final call for action.
- 1:01:15Like, how do people get started with MorePath?
- 1:01:17Like, what can they do?
- 1:01:18What do you need?
- 1:01:19Do you need contributors?
- 1:01:20What's on your radar that you'd love to have?
- 1:01:22Well, contributors are always great.
- 1:01:25We have a few core contributors now, which I'm very happy about.
- 1:01:28And I noticed that if I do, like, one major outreach thing, like, when I spoke at EuroPython in 2014 for, like, hundreds of people, one guy started using MorePath and he became a core contributor.
- 1:01:43So that's just a few core contributors already, such a wealth in an open source project.
- 1:01:48So those things I like very much.
- 1:01:50We have a documentation website, morepath.read.docs.io.
- 1:01:55There's also a link to a Discord chat.
- 1:01:57So it just opens in your web browser and you can talk to MorePath developers and other people use MorePath.
- 1:02:04Create an issue on the issue tracker.
- 1:02:06That's also a way to reach us.
- 1:02:08And, yeah, I started thinking a little bit about, I was looking at Django a little bit recently.
- 1:02:13So I started a little bit about trying to create something like the Django admin UI, but then for MorePath using client-side technology somehow and perhaps using, I've never used it before, but I looked at the Pony ORM.
- 1:02:28And that looks like a nice ORM, so maybe I'll try that one day.
- 1:02:32Yeah, Pony ORM is really nice.
- 1:02:34I had those guys on the show about 10 weeks ago, and it's really cool.
- 1:02:39Yes, yeah.
- 1:02:39That's excellent.
- 1:02:40Everyone get out there and check out MorePath.
- 1:02:42And, Martin, thank you for being on the show.
- 1:02:44It was great to talk with you.
- 1:02:45Thank you very much.
- 1:02:46Thank you for letting me talk.
- 1:02:48Absolutely.
- 1:02:50This has been another episode of Talk Python To Me.
- 1:02:53Today's guest has been Martin Fasson, and this episode has been sponsored by Metis and Hired.
- 1:02:59Thank you both for supporting the show.
- 1:03:01Want to learn data science?
- 1:03:03Well, don't forget to visit thisismetis.com slash talkpython to learn more about their upcoming courses.
- 1:03:09Get the skills that you need to succeed in the fast-paced world of data science.
- 1:03:15Hired wants to help you find your next big thing.
- 1:03:17Visit hired.com slash talkpython to me to get five or more offers with salary and equity presented right up front,
- 1:03:23and a special listener signing bonus of $2,000.
- 1:03:26Are you or a colleague trying to learn Python?
- 1:03:28Have you tried books and videos that just left you bored by covering topics point by point?
- 1:03:33Well, check out my online course, Python Jumpstart, by building 10 apps at talkpython.fm/course
- 1:03:39to experience a more engaging way to learn Python.
- 1:03:42And if you're looking for something a little more advanced, try my Write Pythonic Code course at talkpython.fm/pythonic.
- 1:03:49Be sure to subscribe to the show.
- 1:03:52Open your favorite podcatcher and search for Python.
- 1:03:54We should be right at the top.
- 1:03:55You can also find the iTunes feed at /itunes, Google Play feed at /play,
- 1:04:00and direct RSS feed at /rss on talkpython.fm.
- 1:04:04Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.
- 1:04:09Corey just recently started selling his tracks on iTunes, so I recommend you check it out at talkpython.fm/music.
- 1:04:16You can browse his tracks he has for sale on iTunes and listen to the full-length version of the theme song.
- 1:04:21This is your host, Michael Kennedy.
- 1:04:24Thanks so much for listening.
- 1:04:25I really appreciate it.
- 1:04:26Smix, let's get out of here.
- 1:04:28Stay tuned.
- 1:04:30Stay tuned.
- 1:04:30Stay tuned.
- 1:04:30Stay tuned.
- 1:04:30Stay tuned.
- 1:04:32Stay tuned.
- 1:04:33I'm sleeping, I've been using lots of rest. I'll pass the mic back to who rocked his best.
- 1:04:38I'm first developers.
- 1:04:40I'm first developers.
- 1:04:47Developers, developers, developers, developers.
- 1:04:50you
- 1:04:50you