Latest / Talk Python To Me / #35: Turbogears and the future of Python web frameworks
Transcript
- 0:00Do you have a new web project coming up?
- 0:01Are you thinking about choosing Django or maybe Flask?
- 0:03Those are excellent frameworks,
- 0:05but you might also want to check out TurboGears.
- 0:08It was created and released around the same time as Django.
- 0:10It lets you start your project as a micro framework,
- 0:13kind of like Flask,
- 0:14and yet you can scale up to a full stack solution,
- 0:17more like Django.
- 0:17It has built-in support for both relational databases
- 0:21via SQLAlchemy and MongoDB.
- 0:24This week, Alessandro Molina
- 0:26is here to tell us all about TurboGears.
- 0:28This is episode number 35 of Talk Python To Me,
- 0:32recorded October 28th, 2015.
- 0:57Welcome to Talk Python To Me,
- 1:01a weekly podcast on Python,
- 1:03the language, the libraries, the ecosystem,
- 1:05and the personalities.
- 1:06This is your host, Michael Kennedy.
- 1:09Follow me on Twitter where I'm @mkennedy.
- 1:11Keep up with the show and listen to past episodes
- 1:13at talkpython.fm,
- 1:14and follow the show on Twitter via at Talk Python.
- 1:18This episode is brought to you by Hired and CodeShip.
- 1:21Thank them for supporting the show on Twitter via at Hired underscore HQ and at CodeShip.
- 1:26Hey, everyone.
- 1:28Before we get to the interview, I want to tell you about a project I'm working on,
- 1:32and I need your help to make it happen.
- 1:34I've been asked by many listeners something along the lines of,
- 1:37how do I get started learning Python?
- 1:38Or, I'm new to Python.
- 1:40What should I focus on?
- 1:41And sometimes people even ask,
- 1:43how do I get a job as a Python programmer?
- 1:46I've decided to answer this question via a roundtable discussion format
- 1:50between people who just got into the industry as new developers
- 1:53and people who make decisions about hiring new developers on Python teams.
- 1:57This is where you come in.
- 1:59If you're a newly hired Python developer,
- 2:01maybe you got your job in the last year or so,
- 2:03would you come on the show and spend 10 minutes talking about
- 2:06how you learned Python and how you got started in software development?
- 2:10Maybe what it was that got you your first job?
- 2:13That kind of stuff?
- 2:14On the other hand, if you're a technical leader
- 2:17responsible for hiring Python developers,
- 2:19would you come on the show for also 10 minutes
- 2:21and give us recommendations for new and aspiring developers?
- 2:25Maybe what you look for, what skills are really important to you,
- 2:28and just what you think they need to do to get started
- 2:32and land that first interview and that first job.
- 2:34You can read about the whole project in a blog post I just wrote
- 2:38at bit.ly slash talkpythonhiring.
- 2:42Talkpythonhiring.
- 2:44What do you say?
- 2:44Can you come be part of the show and help your fellow developers?
- 2:47I'm looking for maybe three to four people from each group.
- 2:50If this isn't you, but you know someone who is the perfect fit for this little project of mine,
- 2:56send them the link and encourage them to be part of it.
- 2:58All right, now let's get on to the show.
- 3:00Alessandro, welcome to the show.
- 3:04Hi, Michael.
- 3:05Thank you.
- 3:05Hey, thanks for being on the podcast.
- 3:08We've got some cool web stuff to talk about today.
- 3:10So we're going to talk about TurboGear, its history, its evolution, why it's so awesome, and its future.
- 3:17But before we get into all that cool stuff, let's talk about your story.
- 3:21How did you get started in programming in Python?
- 3:23I actually started programming in a totally different language, which was C++, and I actually hated Python at the beginning.
- 3:32I was forced to use it at work at the company of a friend of mine, and then using it day by day, it's impossible to not fall in love with it,
- 3:41because it's so clear, so fast, to rapidly prototype things, especially when compared to C++.
- 3:47And so at the end, I started using Python for everything in my career.
- 3:52And since I moved here in Turing and founded Accent, we worked on Python on practically everything.
- 4:00That's really interesting.
- 4:02So why didn't you like it in the beginning?
- 4:04Well, it's really strange.
- 4:06If you are a C++ developer, you're probably used to structuring your things a lot, thinking a lot about how you should make a class,
- 4:17or everything is pretty much like the beauty behind the architecture of your code.
- 4:24While Python is more direct, you can rapidly prototype things.
- 4:28And at the beginning, I thought it was not a great idea to start throwing code which you can also like monkey patch or use mix-ins,
- 4:37which are really powerful concepts, but if you don't pay attention to them, you might misuse them and end up with some chaos in your code,
- 4:48which C++ somehow forced you to avoid doing that.
- 4:53But at the end, clarity and simplicity of the language clearly wins over much of the other benefits of a mild structured language for me.
- 5:04Yeah, I think a lot of people have that reaction.
- 5:06It manifests itself in different ways.
- 5:09So I think one of those common ways is people see Python so simple, doing things so simply, and they think, oh, well, this is so simple, it must not be a real language.
- 5:21Like, where is the compile and link step?
- 5:24And where is all of this, you know, other structure?
- 5:28And so, you know, what good is Python for?
- 5:32Is this just like kind of like a better scripting language rather than bash?
- 5:36Right.
- 5:36I mean, I get asked that question literally often.
- 5:38Yeah.
- 5:39My first impression was that too, but it was clearly wrong.
- 5:43Yeah.
- 5:45I mean, you can give some really interesting examples.
- 5:48Like the guy from PayPal, Mahmoud Hashemi, who was on show number four, actually has a bunch of amazing examples of, you know, sort of discrediting that idea.
- 5:59But it's a very common idea.
- 6:00So you started there, and then you worked with Python, and over time you just fell in love with it, huh?
- 6:06Yeah.
- 6:07I think I went through something similar, I guess, in the beginning as well.
- 6:11But it didn't take long to convince me that, you know, it was a good idea.
- 6:15Let's talk about TurboGears.
- 6:18What's TurboGears?
- 6:21Well, TurboGears is a web development framework.
- 6:23There are actually a lot in the Python ecosystem.
- 6:27But I think it's one really particular one because that's some of the key concepts that you do not see often in other frameworks.
- 6:35For example, TurboGears started as a collection of the best libraries available when TurboGears was created.
- 6:44So it didn't start as a framework from scratch, okay?
- 6:48It saw that there were really good ideas around and started and tried to collect them together.
- 6:54And then moved into something more complex and more architectured into a real framework itself.
- 7:03So the idea was, the original idea was, hey, look, here's a really cool templating engine.
- 7:09And over here is some sort of HTTP processing library.
- 7:13And here's a great little web server.
- 7:15And if we just stitch these together into a package and kind of wire them together, hey, we have a web framework, right?
- 7:22Yeah.
- 7:23Practically, the core idea was that one.
- 7:25So the team at the time started with Cherry Pie, with KID, with SQL objects, which were the most used technologies at the time, because we are talking around 2005 or something like that.
- 7:38And they collected them all together, put a widgets library on top of that, which was at the time the TurboGears widgets library.
- 7:49And then they started to create extensions and whatever was possible to evolve over that set of libraries and ended up having TurboGears, which at the time was something really powerful.
- 8:04Because we are talking in years where even Django was just getting started.
- 8:11Django was launched like two months before TurboGears.
- 8:14So they got, like being created at the same time, whereas not much was available around.
- 8:20So who was the original creator?
- 8:22Well, TurboGears has been created at the version one, was created by Kevin Dungor, who works right now, I think, at Mozilla, if I'm not wrong.
- 8:33And I don't know if he still works on web stack or web development and things like that.
- 8:40But then he moved away from TurboGears and Mark Ram to cover the development of the 2.0 version and started rewriting it on top of pylons, which was like more modern technology at the time, was just getting at its peak of usage.
- 9:01And new technologies like SQLAlchemy and new technologies like SQLAlchemy and Genshi was available.
- 9:07So they decided to rewrite TurboGears from scratch and move from Cherry Pie and so on to pylons and Genshi and SQLAlchemy.
- 9:18So to a totally different stack, which was better from their point of view.
- 9:24But of course, it was totally different in new technology.
- 9:28Yeah.
- 9:29Did that make upgrading challenging?
- 9:30Yeah.
- 9:31Yeah.
- 9:31Actually, one of the core reasons why TurboGears lost in user base and popularity at the time was because a lot of people had been scared by this move away from everything they were using for their daily development and had to rewrite most of their web application to a different framework, different template engine.
- 9:57I actually were just getting started with TurboGears at the time.
- 10:04I did like two web application with TurboGears one.
- 10:08And I remember that I was really frustrated because I had to rewrite everything from scratch, like especially for the database part, because SQL object and SQLAlchemy are really, really different.
- 10:21SQLAlchemy is far more flexible, more powerful, but it's a lot different from the syntax and the way you use SQL object usually.
- 10:32Yeah.
- 10:32Yeah.
- 10:32So it's not just a, you know, pip install TurboGears upgrade and off you go.
- 10:39It's a pretty serious thing to make that change.
- 10:41And so that caused a lot of problems, like you said, for people getting frustrated.
- 10:45Yeah.
- 10:46That's, I think one of the reasons why we learned the lesson.
- 10:51And then we tried to avoid breaking backward compatibility from version 2.1 and forward.
- 10:59We never brought backward compatibility again, even when we switched away from pylons and we brought things.
- 11:06That's been one of the core targets for TurboGears to try to not make the same error twice.
- 11:14So going forward and for a long time since you upgraded to, it's like basically, all right, we're guaranteeing that you can more or less just continue to upgrade as we do releases.
- 11:26Right?
- 11:27Yeah, exactly.
- 11:28For example, now we support Python 3, which as we know has a lot of differences and some libraries are not available on Python 3.
- 11:38Like when TurboGear started, there was a paste.
- 11:43And then we moved to a tool we created ourselves, Gearbox.
- 11:48But the commands are the same and the options are the same.
- 11:52And you just pick install one or the other.
- 11:54And if you are on an old version of Python, you can also install paste and go on using that one.
- 12:01So even when we replace technologies, we guarantee that you can use the new one or the old one and both will work for the long term.
- 12:09And when we write a technology ourselves, we try to make sure that it's the same as the previous one as for the interface for the user and so on.
- 12:21Okay, that's really great.
- 12:22I think that's the right path.
- 12:24You know, these apps are going to probably be long lived.
- 12:28And so you want to be able to keep supporting them, right?
- 12:31Before you mentioned a lot of interesting technologies like Gearbox and some of the other stuff that are the building blocks of TurboGears.
- 12:40But before we get into that level of detail, let's talk a little bit about the philosophy of TurboGears.
- 12:48On the webpage for TurboGears, on TurboGears.org, you have a couple of sort of reasons that TurboGears 2 was created, right?
- 12:59So you say TurboGears 2, it's kind of based on the good ideas from Django, TurboGears 1, and Ruby on Rails and those types of things.
- 13:07But you guys had frustrations with all of those frameworks.
- 13:12Yeah, well, one of the core ideas behind TurboGears is to actually make possible to make a structure of your web application,
- 13:23which is really simple and organized.
- 13:25Okay, like one of the core parts that got frustrated me with frameworks like Django, Flask, or even Pylons itself,
- 13:35which TurboGears was based on, was their routing.
- 13:38Because while regular expressions are really, really powerful, if you have a huge project, they start to get somehow messy.
- 13:46You have a lot of regular expressions.
- 13:48You have to try to resolve them to understand where the code that serves that page or performs that action is actually.
- 13:55And so if you work on a team and you have to test this project to another developer who has never seen that project before,
- 14:03he will need a lot of time to get started into the project and understand where things are going, how things are done,
- 14:12and where the code that does something is actually is.
- 14:15And TurboGears actually uses a totally different dispatch model, which is called object dispatch,
- 14:21on top of which everything, every URL, by default, is the path of your object.
- 14:30So it's much like the pyramid traversal, if you have ever seen it, but it doesn't use dictionaries.
- 14:35It uses objects.
- 14:37So every controller has actually methods, which are the URLs you expose, and it can have subcontrollers, which are subparts of your website.
- 14:49And if you do not provide any regular expression or any special routing on top of that,
- 14:54they just get served exactly where you will find the object itself.
- 14:59So if I see a user new URL, I know that it will be properly served by the new method inside the user file,
- 15:09and I can go there and start doing whatever I need to do without needing to understand the structure of the project and things like that.
- 15:18And this philosophy of having a framework which is easy for big projects and for people having to get started on an already existing project
- 15:29is also visible on the template engine, because TurboGears uses one of the few template engines that is able to validate your HTML code.
- 15:39So if you did something wrong with your HTML code, you do not discover it when you see the page and see that it's actually broken.
- 15:47But you discover it at compile time when the template engine is compiled.
- 15:53It will provide you with errors, for example.
- 15:55You forgot to close the tag or things like that.
- 15:59Oh, that's really cool.
- 16:00Yeah, you know, I'm a big fan of both Pyramid and Flask.
- 16:04This thing that you point out about the routing is, it is really annoying to have to configure that somewhere else
- 16:11rather than just, hey, the way my files are laid out, boom, this is how it works, right?
- 16:16Which is really, really nice.
- 16:17And then down into the classes and so on.
- 16:19So in TurboGears, you've got sort of the way of writing code that handles the requests are by creating controller classes, right?
- 16:28So you derive from like a base class and then you add methods to that base class, right?
- 16:34Exactly.
- 16:35Of course, not everything that you write in your class is exposed as a URL because that would be a security issue.
- 16:42But you can easily make things from a method to a web page.
- 16:47The difference is just you have to put a decorator on top of the method and it becomes available.
- 16:53Yeah, I really like the way that you guys are doing that there.
- 16:57That's cool.
- 16:57The other thing that you mentioned that's pretty nice is the templating engine is sort of self-verifying.
- 17:04Like I'm using the Chameleon templates right now on my website.
- 17:09And if something goes wrong, it's usually just a 500 server error.
- 17:14You know, something is wrong.
- 17:16Sorry.
- 17:17Yeah.
- 17:18It's really hard often to track down what's going on when you get that wrong.
- 17:23Sometimes it gives you a good error message and sometimes it doesn't.
- 17:26Well, you are already lucky because I remember that when I started working with Ruby on Rails,
- 17:33there was Herb, which was the template engine.
- 17:37And if something was wrong, you actually didn't get any error.
- 17:40Your users were a broken page and nothing else.
- 17:44So at least Chameleon provides you errors.
- 17:48And what Genshi and the template engine to Ruby is using, try to do,
- 17:54is actually trying to parse the structure of your file.
- 18:00So your template must be valid HTML.
- 18:03And they parse it and they try to understand how it's made.
- 18:07They try even to optimize it.
- 18:10And they point out the exact error.
- 18:13Like you forgot to close this tag at this line.
- 18:16So you know where something was broken.
- 18:18And as they actually parse the code, when you need to translate your web page,
- 18:25it's really, really easy because everything which is inside the tag can be translated.
- 18:31You don't have to mark with get text calls and things like that around.
- 18:35If it is inside the call, it's a string that can be translated.
- 18:39Yeah, that's really excellent.
- 18:41So I don't know much about that template engine.
- 18:44Is it possible to write like semi-structured HTML5?
- 18:49Or does it have to be sort of pure XHTML?
- 18:52So for example, with like HTML5, it's fine to just put like an angle bracket BR
- 18:58with no, you know, closing, like auto-closing slash or self-closing slash
- 19:04and things like that.
- 19:05What's the story around that?
- 19:07This episode is brought to you by Hired.
- 19:20Hired is a two-sided curated marketplace that connects the world's knowledge workers
- 19:25to the best opportunities.
- 19:27Each offer you receive has salary and equity presented right up front.
- 19:31And you can view the offers to accept or reject them before you even talk to the company.
- 19:36Typically, candidates receive five or more offers in just the first week.
- 19:40And there are no obligations ever.
- 19:42Sounds pretty awesome, doesn't it?
- 19:44Well, did I mention there's a signing bonus?
- 19:47Everyone who accepts a job from Hired gets a $2,000 signing bonus.
- 19:51And as Talk Python listeners, it gets way sweeter.
- 19:56Use the link Hired.com slash Talk Python To Me and Hired will double the signing bonus to $4,000.
- 20:02Opportunities knocking.
- 20:04Visit Hired.com slash Talk Python To Me and answer the call.
- 20:18Well, actually, if you're using Genshi, which is the default template engine for Google years,
- 20:24you will have to write perfectly structured HTML files.
- 20:29So you need to close your tags in line and things like that.
- 20:34That's to actually tell to Genshi that you didn't forget to close the tag, but you did it on purpose.
- 20:41But that's for that specific reason, because a great engine needs to be really structured and well validated.
- 20:49Then if you want to output HTML5 and maybe avoid closing your head, avoid closing your body, or things like that,
- 21:03you can just tell Google years to output the result in HTML5 mode.
- 21:08And it will do that for you.
- 21:10That might be even considered a really powerful feature, because if you want to switch from HTML5 to XHTML or even HTML4,
- 21:20you just have to change the configuration options.
- 21:23And this template engine will output the code you ask him to do.
- 21:28That's really cool.
- 21:29You know, I personally don't mind at all writing, you know, properly structured XHTML,
- 21:35because I feel like I have, like you said, control I can check.
- 21:38Okay, this is exactly right.
- 21:40I guess it's probably a personal preference, but I like it.
- 21:44Yeah.
- 21:45So another one of the goals you guys had when you created TurboGear's 2 was, you said you want, unlike things like Django and Rails,
- 21:53you want to be able to start as a micro framework, but scale up to a full stack solution.
- 21:58What does that mean?
- 21:59Well, actually, when TurboGear's was created, it was totally a full stack framework.
- 22:04So it got started as full stack.
- 22:07But as the community started moving forward more API development and web services and things like that,
- 22:16it was clear that a full stack framework is far more complex than what you need to get started with a prototype on an API or similar things.
- 22:26And then when we rewrote TurboGear's in version 2.3 removing pylons,
- 22:33and we took the chance to rewrite everything on top of a core,
- 22:39which would make possible to have something which is a micro framework,
- 22:46so which provides everything you would expect, like a routing, like the configuration of your application,
- 22:54but doesn't provide additional features like the template engine or the caching layer or things like that,
- 23:02which you can turn on and turn off and replace with whatever library you want whenever you want.
- 23:09For example, if I start to a new TurboGear's project, I will get it with Genshi, which is the default template engine.
- 23:17Now if I want to use like Macro or Jinja or things like that, because I prefer to work with them,
- 23:25I can actually start with a project that uses them instead of Genshi, and everything will work anyway.
- 23:33Because when working as a micro framework, you actually do not have any template engine at the beginning.
- 23:40You register one, and registering it just means enabling an option, and you get started with that one.
- 23:49For if you want to turn on also database because you need SQL Archemy, you turn on another option, and SQL Archemy is enabled.
- 23:57If you want to use something which TurboGear doesn't support at the moment,
- 24:02you can just set up itself like you would with any other microframe or by flask or bottle or things like that.
- 24:10Yeah, that's cool.
- 24:12So if I want to, I could just create a single Python file, create a class, which is a controller,
- 24:18and have a single method on there and give it the expose decorator,
- 24:24and more or less just, say, serve that.
- 24:27And then I don't have the overhead of the database libraries, all the templating stuff.
- 24:34All those different things are kind of not there.
- 24:37So if I were writing like a really, really simple JSON-based service or something, maybe that would make sense.
- 24:43Yeah.
- 24:44Let me tell you an example.
- 24:47Yesterday, one of the guys in our team needed a little tool to preview the result of a bootstrap theme he was working on.
- 24:58And then I just created a quick and dirty file with TurboGear to render the theme, replacing some variables through the template engine and nothing else.
- 25:10So I started with the microframework mode.
- 25:12I started with what's called minimal mode in TurboGear.
- 25:17Then we decided that it would have been cool to be able to upload multiple versions of the template and switch between them
- 25:24and see the differences proposed to the other team members, which one was better and so on.
- 25:30And to do that, we needed the database where to register everything.
- 25:34We needed a crude where to create and update and modify the themes and things like that.
- 25:41So I just switched to the full-strap framework.
- 25:44I enabled the TurboGear's admin and I got the code for free.
- 25:49I got the database set up for me.
- 25:51And I have been able to create a full application in half an hour, starting from a single file and then moving to a full-strap application with login registration, multiple crowds, and so on.
- 26:07Yeah, that's really interesting.
- 26:08Because I think there's these two camps or two philosophies in Python web frameworks.
- 26:15You've got things like Django, which are super full-strap, super comprehensive.
- 26:22They even have admin backends and user management.
- 26:25And they're big things, right?
- 26:27And then on the other hand, you've got things like Flask and Bottle that are just very, very focused on, we will get the request to your method and then it's up to you.
- 26:37You know, to some degree, right?
- 26:39And so the ability to not rewrite that, go, well, it was working in Flask, but we need more.
- 26:44So, whoop, off we go to Django.
- 26:46But you just sort of grow it.
- 26:48That's a pretty cool idea.
- 26:49Yeah.
- 26:50That's one of our objectives, what we are trying to do.
- 26:54Yeah.
- 26:55Another one that you have is you said you want to make sure that the code that you write for the web framework is code that is as natural as writing just a function.
- 27:03Yeah.
- 27:04Well, that's one of the philosophies behind the object dispatch system and so on.
- 27:10We don't want people to have to mess with things like person parameters or the dispatch itself or things like that.
- 27:20You just want a web page that accepts some parameters and you can get them through a get URL encoded method or you can get them in the body of the post or whatever.
- 27:37It doesn't matter.
- 27:38You just want some parameters to your code and you want to return something when that parameters arrive.
- 27:45So, we really think that writing a web page is much like writing a Python method.
- 27:51You get something and you output something else.
- 27:54So, Python methods are perfect for doing that.
- 27:58And so, to produce actually just whatever parameter you get into your page, it gets converted to an argument of your methods with the same name.
- 28:08And whatever you return from your method is actually just a response of your web page.
- 28:15Yeah.
- 28:16That's interesting.
- 28:17So, suppose I've got a user controller and a method called show and it's supposed to show the details of the user and I want to pass like the user ID to go maybe to a database and pull it out.
- 28:32What is, could I have like user ID in the method for my show method?
- 28:37Yeah.
- 28:38You will just have a parameter which is an argument of your method which is named user ID, for example.
- 28:44If I pass in the URL a user ID parameter, that will be the value of your argument.
- 28:51Or, as Python supports position arguments, if you pass forward slash one, one will go into the user ID parameter as it is the first argument of the function.
- 29:04That's awesome.
- 29:05Yeah, I really like that because, you know, like I said, I'm a fan of Pyramid, but it's kind of challenging to get, you know, the route data and the post data and all those different things like gathered back up.
- 29:18So, you can start actually, you know, processing the request.
- 29:21So, that's really cool.
- 29:22Another one of your philosophies is you wanted a powerful and flexible ORM with real multi-database support.
- 29:29What's the story there?
- 29:30When we started, one of the main issues with SQL Object was actually that it was not as flexible as SQLAlchemy.
- 29:40And when we moved to SQLAlchemy, we saw that it was really simple to set up something like master-slave configurations on SQLAlchemy and the route and methods and queries depending on what we were doing through the SQLAlchemy session and things like that.
- 29:59So, when you are used Turbo Gears, you actually get out of the box something like the master-slave support.
- 30:06Whenever a method does only read, it will be rooted to the slaves by Turbo Gears itself.
- 30:13It is tried.
- 30:14If it tries to write something, it will be rooted to the master of your database configuration.
- 30:21And that's possible thanks to the SQLAlchemy unit of work because at the end of the request, when the unit of work is flushed, you know if it contains only reads or it will contain any change of the documents.
- 30:35And so, you can decide where you should perform those operations.
- 30:40Yeah, SQLAlchemy is pretty awesome.
- 30:42And that whole unit of work idea and auto-commit or auto-rollback of transactions on errors, there's a lot of really neat stuff.
- 30:49That's cool that you're leveraging that.
- 30:51Yeah, and that's also something we are trying to leverage also MongoDB.
- 30:57That's the reason why we choose Ming as the MongoDB library for Turbo Gears because that's pretty much the same concept.
- 31:05You get an identity map, so you don't have duplicates in your code.
- 31:10You get a unit of work, so you can flush all your changes at the end and have a single optimized set of actions instead of replicating the updates to your database.
- 31:22And you can decide to perform something when the changes are flushed and things like that.
- 31:29Yeah, that's really cool.
- 31:30And I think it's great that you support MongoDB and get a choice.
- 31:34So, sort of the whole relational database story is covered by SQLAlchemy, which is pretty comprehensive.
- 31:40And then if you want good NoSQL integration, nice document database, well, MongoDB is pretty straightforward choice, right?
- 31:47Yeah, actually, I've been using MongoDB for years now.
- 31:52And then, like, 70% of the web applications I'm starting are based on MongoDB because it's a really powerful and convenient technology.
- 32:02And so, I wanted to go to use Web as much support for MongoDB as it had for SQLAlchemy.
- 32:09And as we have a middleware, which is called Sprox, which permits to convert the queries in the two formats, it was not so difficult to provide support for MongoDB in most TurboGias extensions, like the TurboGias admin or the registration module or things like that.
- 32:31So, whenever you plug an extension into TurboGias, you can be pretty sure that it will probably work with MongoDB too.
- 32:40Yeah, that's excellent.
- 32:41Yeah, that's excellent.
- 32:41And I totally agree with you.
- 32:43Like, at least 75% of the time, if I'm doing a new web app and it needs a database, you know, I need a reason not to use MongoDB, not a reason to use it, you know?
- 32:52Yeah, it's the same for me.
- 32:54Yeah, it's awesome.
- 32:56So, another thing you talked about is sort of built-in support for horizontal data partitioning or what's known as sharding.
- 33:03So, that's actually something that's not strictly related to TurboGias itself, as we say, because it's another of those features which SQLAlchemy makes possible.
- 33:13But as TurboGias works on the concept of having one or multiple database sessions available, if you want to work on different nodes of your database and perform sharding, you can just set up different database sessions, one for each shard, and register your models on one session or the other.
- 33:38And whenever you perform a query on this or that model or whatever any extension, the admin or whatever you're using performs a query on that model, it will know that it has to perform that query on that database shard.
- 33:52Yeah, that's really cool.
- 33:54And that works with relational databases as well?
- 33:56Well, for MongoDB, it works really simple.
- 33:59And while for SQLAlchemy, you actually lose the ability to perform joins when doing that because you're actually storing the data scattered across multiple databases.
- 34:09Yeah.
- 34:10Okay.
- 34:11Yeah, you definitely have to give up a little bit on the relational side, which is kind of what the NoSQL databases are doing anyway to get better.
- 34:17So, it's all good.
- 34:18It's all good with me.
- 34:19So, one of the other things you talked about is support for multiple data exchange formats.
- 34:25Is that kind of like the hypermedia component of REST?
- 34:29Like, I could do a GET against a URL and have the accept type as image or the accept type as JSON and have it return different stuff based on that?
- 34:39Yeah.
- 34:40Actually, something like that because the routing of TurboGirth itself permits to register multiple expositions of your method.
- 34:51And so, your method is able to respond like three different things.
- 34:55You can return a webpage.
- 34:56You can return a PDF file or you can return whatever you want.
- 35:01And whenever the routing understands that there is an accept header or any other reason, for example, it also works by the extension.
- 35:11If I put .json at the end of my URL, the TurboGirth will try to route to something which is able to respond as JSON.
- 35:21So, if your method is able to respond to HTML and JSON, it will serve you the JSON version if the URL ends with JSON.
- 35:29Or if the URL has an accept header that says I only accept JSON.
- 35:34Yeah, that's a really cool feature.
- 35:36I love that.
- 35:38Maybe we could talk a little bit about the different, how TurboGirth compares against the different frameworks.
- 35:44Well, we already saw a lot of the things that TurboGirth does different from the other frameworks.
- 35:51But I think that the core part is the philosophy of making everything really, really simple.
- 35:58TurboGirth tries to be really simple for simple things while making complex things possible.
- 36:06So, you have routing receive just writing a method.
- 36:11You have a template engine which is a check server for you.
- 36:15You have a strong integration with the database, but you can even turn it off if you want.
- 36:21So, it's really just a different way of balancing things.
- 36:27I would not say that there is something in TurboGirth you cannot do in Django or something you cannot do in Flask.
- 36:33It's just a different way of balancing the features.
- 36:36Like, Django is much more on GitHub quickly and start with what you have to do.
- 36:43While Flask is more get maximum flexibility.
- 36:46TurboGirth tries to be a little bit in the middle, balancing between everything should be quick, but you can have an option to turn it off and do it your way.
- 36:58Yeah.
- 36:59Yeah, that's that start as a micro framework, but grow.
- 37:02And that's very cool.
- 37:03So, do you want to talk about the future of TurboGirth and where things are going?
- 37:08Yeah, that's an interesting topic because we recently tried to switch to a frequent release cycle.
- 37:15So, during the last year, we tried to release a new version every three months.
- 37:21So, it's a really interesting change from the idea of releasing when you have feature risks to releasing at that time.
- 37:31Whatever you have, you have.
- 37:32It doesn't matter.
- 37:34But that's a really important switch because it made possible to see faster feedbacks and faster correction of errors and things like that.
- 37:44And so, it even made more important the do not break backward compatibility philosophy because with frequent releases, you will have frequent issues if you avoid sticking at that philosophy.
- 38:01And so, right now, we recently referred, as I told you, from Pylons, which was using TurboGirth 2.2, to a totally separated core, which is written by the TurboGirth team itself.
- 38:16Because we wanted to support Python 3.
- 38:19And as we know, Pylons itself will never support Python 3, probably, because it now merged with the Pyramid project.
- 38:27Right, right.
- 38:28And by the way, thank you for making Python 3 such a key part of the effort.
- 38:34I think, you know, things are moving in that way.
- 38:38But everyone's got to do a little bit of work like you're talking about here to make it actually a common reality, right?
- 38:45This episode is brought to you by CodeShip.
- 39:02CodeShip has launched organizations, create teams, set permissions for specific team members, and improve collaboration in your continuous delivery workflow.
- 39:11Maintain centralized control over your organization's projects and teams with CodeShip's new organizations plan.
- 39:16And as Talk Python listeners, you can save 20% off any premium plan for the next three months.
- 39:22Just use the code TALKPYTHON, all caps, no spaces.
- 39:26Check them out at CodeShip.com and tell them thanks for supporting the show on Twitter where they're at, CodeShip.
- 39:37I think that right now you can start doing practically everything on Python 3 and use it day by day.
- 39:45But I see a lot of people still scared by the change, still unsure if they should do it or not.
- 39:53And so it's more like a people problem than a technology problem because the technology is there and the most common frameworks and libraries are available.
- 40:06But you're still unsure.
- 40:08You still have the question, and if?
- 40:10If I find something which is missing, what will I do?
- 40:15Yeah, I think there's definitely the painful history of it.
- 40:19But my philosophy these days is the same as with manga.
- 40:23Like, I need a reason not to use Python 3.
- 40:25So if I'm going to start something new, it'll also go down that route.
- 40:29That's cool, though.
- 40:30Okay.
- 40:31So then you also had some ideas about the future of Genji and the templating, right?
- 40:37Yeah, that's one.
- 40:38It's again related to Python 3 because it's really sad that the Genji project is not moving forward a lot recently.
- 40:47Actually, they have a few fixes and changes for compatibility with Python 3.4 and Python 3.5.
- 40:55But there is not going to be a release soon as far as I know.
- 40:59They are trying to get back on track, and I saw that they are talking about moving Genji to GitHub.
- 41:05But still, it's unsure if it will happen and when it will happen.
- 41:09So as we want to stick to a framework that has the same features and we want to stick to the template engine that works with the same way,
- 41:19we are actually experimenting with various different template engines that will make possible to migrate your project from Genji to another template engine without having to change much of your code.
- 41:33For example, we are experimenting with Kajiki, which has been created one of the past two years contributors, which is the Rick Copeland.
- 41:43And we are trying to provide a quick way to move away from Genji to Kajiki without having to change everything.
- 41:50We have a command in Gearbox, which is the toolset for TurboGear.
- 41:55So you have a command to upgrade your templates from Genji to Kajiki, and you don't have to change anything else.
- 42:03The command will move the templates from one to the other, much like the conversion tool moves your code from Python 2 to Python 3 and things like that.
- 42:16But still, we are still experimenting.
- 42:20So currently, both of them are available in TurboGear.
- 42:23So when you start a project, you can choose to use whatever you want, and Genshin is still the default.
- 42:29But it's just a possibility we have in case we will need to take another choice due to Python 3 support and Python evolution.
- 42:42Speaking of Python 3, one of the really cool features is the async and await sort of parallelism concurrency stuff.
- 42:54Is there any way to incorporate that into TurboGear's?
- 42:58Well, currently, TurboGear has been support for G-Event for a lot of time, but we do not have any support for a SyncIO.
- 43:09We are thinking about that.
- 43:11We are still in a research phase because we are not sure that it will be such an easy thing to achieve on everything of the framework.
- 43:23For example, you can already put in front of TurboGear's a WISG-E server, which is based on a SyncIO and that your application is set asynchronously.
- 43:39But that wouldn't provide any much benefit because your I.O. through the database or things like that will still block.
- 43:47So it doesn't make a lot of sense.
- 43:51And so it's much more a problem of the technologies available than of TurboGear's itself because until SQLAlchemy, for example, provides full support for a SyncIO, we cannot provide support for a SyncIO and things like that.
- 44:08Yeah, that makes sense because those are the places you really want to use a SyncIO anyway, right?
- 44:14Yeah.
- 44:14It's all the database calls and things like that.
- 44:16Yeah.
- 44:19Somewhat related to that is the whole HTTP2 thing that's coming, right?
- 44:26Where a single request can come in and it can actually process many files and so on.
- 44:33So like maybe the browser makes a request to the server and it gets the main page, but then it also gets like the CSS files and the JavaScript and, you know, a different style of processing.
- 44:46And I don't know if any of the WSGI servers support that yet.
- 44:52I don't know of any that do.
- 44:54What do you see about TurboGear's WSGI and HTTP2 coming down the road?
- 45:00Well, that's actually a really interesting question because it's such a big change because you're actually multiplexing multiple requests inside the same channel.
- 45:14That probably is not enough to rethink your HTTP server.
- 45:18You should also rethink your communication channel.
- 45:22You should rethink WSGI.
- 45:24You should rethink a lot of the way the current Python web application works.
- 45:32So it's not something that only matters to the web framework.
- 45:37It's probably something that matters far less to the web framework than to the WSGI protocol itself.
- 45:43I mean, WSGI, as we know, doesn't have a great support for things like asynchronous or interleaved requests and things like that.
- 45:54But we have been able to cope for the past years and still go on supporting things like WebSocket or protocol evolution and things like that.
- 46:05But here we are talking about a much bigger change.
- 46:09We are talking about, like, it doesn't work anymore.
- 46:12It's not like a common idea of, here is your request, give me your response.
- 46:16It's much like, here is a part of your request.
- 46:20And then you can get a part of another request, totally different request.
- 46:23And you should interleaved them.
- 46:26And you should be able to start processing one while you still are waiting for the other and so on.
- 46:34So it probably requires a much different programming model, which actually AsyncIO might help achieving.
- 46:40Yeah, I was just thinking as you were talking there that, you know, when you get to that level, AsyncIO might be the thing required to unlock that in Python.
- 46:49Because the threading story is not super easy to just, you know, kick that off as a bunch of threaded requests, right?
- 46:56You need some way to sort of interleave those reasonably, right?
- 46:59Yeah, exactly.
- 47:02And all these changes in the Python world and in the web development world are the reason why I'm also thinking about rewriting for the 2.4 version of TurboGios, the config system.
- 47:16Because so far, the TurboGios config system has been pretty hard, well-structured, much like the Django config system.
- 47:24You have a bunch of options, which you can set to turn on and turn off feature.
- 47:28Then you can register middleware, some things like that.
- 47:32But the configuration itself stops to something like options and things like that.
- 47:37While I would like to achieve something more similar to the way Pyramid works, where you can register even pieces of your configuration process and extend your configuration process and things like that.
- 47:50Which I thought I needed to evolve to evolve to different technologies and things like switch to a different programming part in the like,
- 47:59like, Helsinki or HTTP2.
- 48:01And it will make possible for people to go on using TurboGios even in the future.
- 48:08And even when they have to switch to a different way.
- 48:12And even when they have to switch to a different way to the way to the server.
- 48:14Like, you can enable by plugging an additional configuration step in your configuration and setup system.
- 48:21It's going to be an interesting time when it switches to HTTP2, isn't it?
- 48:26Yeah, it definitely will be.
- 48:31I think we are in an interesting moment for web development because it's still exploring where it has to go.
- 48:39We are no more at the time of websites.
- 48:42We are not yet at the time of whatever it will be in the future.
- 48:47We are still in the most interesting period, probably.
- 48:52Yeah, it's a great time to be a developer.
- 48:54I feel like, you know, there was in the early web, like everybody thought the web was a brochure, right?
- 49:00It was like a document and it was just fixed.
- 49:03And then now we know it can be so much more, but we haven't really gotten it, right?
- 49:08Yeah, exactly.
- 49:09Yeah, yeah.
- 49:10Very cool.
- 49:11So let's talk about some of the other things that you have going on, some other open source projects, maybe.
- 49:17So you already talked about Kajiki, how do you say Rick Copeland's template engine?
- 49:23I would probably say it's Kajiki, but I'm not sure.
- 49:28Yeah, yeah, yeah, okay.
- 49:28Kajiki, yeah, Kajiki.
- 49:30So just for people listening, that's K-A-J-I-K-I.
- 49:34And I'll put the link in the website.
- 49:37So we already talked about that one, but then you have some other ones.
- 49:40You have one called Depot.
- 49:41What's that?
- 49:43Well, Depot is a really interesting project because like a year ago or so, we had a project we worked on that needed to switch file storage during the deployment.
- 49:55Actually, we developed everything, storing files locally.
- 49:58And then the customer decided that it wanted to go on a path that didn't support saving files.
- 50:05So we had to switch to something different for storing files.
- 50:09We wanted to go to grid.fs on MongoDB.
- 50:12And so we had to revise the code.
- 50:14And we did that like writing everything related to saving files the day before the go live of the project, which is not a really good idea.
- 50:23So we learned from that error.
- 50:26And we wanted to create a framework that made possible to save, read, and sell files in web applications without caring at all about where they are saved.
- 50:37And so we started Depot.
- 50:39I started working on Depot as just an abstraction layer.
- 50:43And it evolved on something much more powerful and much more convenient.
- 50:48For example, right now, Depot supports filters on your files.
- 50:52So you can, for example, add a filter that creates multiple thumbnails on your images when you upload them.
- 50:59Or you can integrate with the unit of work of SQLAlchemy because Depot has strict integration with MongoDB and SQLAlchemy.
- 51:08And whenever your transaction rolls back, even your files go back at the previous state.
- 51:14So a previous state of the file is recovered.
- 51:16Or if you uploaded a new file, it's automatically deleted for you whenever the column is deleted or the transaction is all bad.
- 51:25That is actually a seriously cool feature.
- 51:28Yeah, absolutely.
- 51:30And Depot started as an extension for TurboGios.
- 51:34But pretty early, I decided that it would benefit Pratica Any web framework because it didn't have any requirements on the framework itself.
- 51:42And now it's a library that you can use on top of everything.
- 51:45I know a lot of people are using it with Flask.
- 51:48And it was like just one configure command at the beginning of your web application.
- 51:53And you are Depot ready to save your files.
- 51:56Yeah, okay.
- 51:57That looks really cool.
- 51:58And the fact that it integrates with GridFS and the real file system makes me think you could point it at things like Cloud Blob Storage and other places pretty easily, right?
- 52:09Yeah, we also have support for S3, for example.
- 52:13And right now we have support for those three.
- 52:16But if you want to provide support for another storage, you can just subclass the storage class, provide your own, and register it with Depot.
- 52:26So if people want to have additional backends, it's totally possible and really, really simple.
- 52:31Okay.
- 52:32Yeah, that's really awesome.
- 52:33Another one that you have is DukePy.
- 52:36DukePy.
- 52:37Yeah, I started working DukePy again for my own needs because I'm now a really Python lover.
- 52:49I want to use Python for everything.
- 52:51Okay.
- 52:52So whenever I have on my system to set up Node.js just to compile my CoffeeScript, and right now I'm using mostly ECMAScript.
- 53:02So to compile my ECMAScript to the current version and things like that, I was really frustrated by the fact that I needed to set up Node.js just for that.
- 53:13To have Google or whatever you want to use to compile your REST pipeline and convert your SAS to CSS and unify your JS or whatever.
- 53:27Because Node is one of the environments where these tools are mostly available because they are being written by JavaScript developers.
- 53:39So I started to look around for a solution that would make possible to run those tools on Python.
- 53:45So take the CoffeeScript compiler and things like that and run it on Python so that I could also integrate in my middleware and directly serve the CoffeeScript file from my web framework without needing to pre-compile them and things like that.
- 54:02And I saw that the tools available at Python for that are not really simple to use.
- 54:09They are really, really powerful because we have a layer for SpiderMonkey.
- 54:13We have a layer for V8 and things like that.
- 54:17But it's not really easy to set them up.
- 54:19You need to compile a lot of dependencies and things like that.
- 54:23And then I started working with DuckTapes, which is a really simple JavaScript interpreter written in plain C.
- 54:31And I started embedding it in a toolkit, which is actually DuckPy, which you can just pip install and have a full working JavaScript interpreter in Python.
- 54:45So you can run JavaScript from Python.
- 54:47And the main difference from the other technology is you just need to pip install it and it will work because it's just a single file that gets compiled without any external dependency.
- 55:00Now that's a cool project.
- 55:02Yeah.
- 55:04And it provides out of the box when you pip install it, it already provides the Bevel.js compiler, the CoffeeScript compiler, and a few other tools built into the project itself.
- 55:14So you just pip install it and you can compile your ECMAScript 6 to ECMAScript 5 and go on working without the need of an external tool.
- 55:23Yeah, nice.
- 55:24I'm a fan of less.
- 55:25Does it support less?
- 55:27Well, currently we do not have less itself inside DuckPy because I'm actually a SAS SCSS user.
- 55:34So I use LibSAS, which is available for Python.
- 55:38But it's really easy to add it because you just have an execute function where you can pass the JavaScript code that gets executed.
- 55:47So you can pass the last compiler code to DuckPy and provide him with the input that needs to be compiled.
- 55:56And you will get back the soon with the compiled code.
- 55:59That's at least how it works for the Bevel.js compiler and so on.
- 56:03Yeah.
- 56:03Okay.
- 56:03Very cool.
- 56:04So if for some reason I want to serve less files and I set them up right in the system directly off of like talkpython.fm and I want to minify my JavaScript without actually running that.
- 56:18You know, I just push the real JavaScript unminified versions up there and I want them swished together.
- 56:25Could I just sort of set up some kind of web handler that when I saw a request for a JavaScript file it would cache and minify that and return it back using DuckPy?
- 56:35Yes, exactly.
- 56:37I'm actually using a framework which is called Web Assets, which is available for any web framework.
- 56:43You can set it on top of whatever you want.
- 56:47And it provides a middleware and a caching layer and whatever that compiles the assets through a bunch of filters.
- 56:55And so you can register a filter which uses DuckPy to compile your LAS or to compile your JavaScript.
- 57:03And Web Assets will provide all the caching and intelligence to understand whenever it changes and needs to be recompiled.
- 57:10Oh, that's really awesome.
- 57:11Okay.
- 57:13I'll add a link to all those things in the share notes.
- 57:16Very cool.
- 57:17Alessandro, we're getting pretty close to the end of the show.
- 57:21Do you have maybe some final call to actions or want to tell people what they should do to get started with TurboGear?
- 57:28Well, actually, there is only one call to action that I really want to tell people that want to get started with TurboGear,
- 57:36which is just ask.
- 57:38Ask for whatever you want.
- 57:40Ask for features and things like that.
- 57:42Because I think that one of the more important parts of a framework is actually that people complain about it.
- 57:50Okay?
- 57:50Things can only improve if you complain.
- 57:53Otherwise, it's just my vision of how the framework should be.
- 57:57And feedbacks are really, really important.
- 58:00And that's the reason why we are starting to see agile methodologies and frequency cycles and things like that used every day in computer development.
- 58:13Because when you have something as complex as a software, which has minions on variables and things like that, you cannot take the right choice on your own.
- 58:24You always need to have feedbacks and users to tell you where are their problems and how things should evolve and improve.
- 58:33Yeah, that's a really cool philosophy.
- 58:34You know, start with something somewhat minimum viable and then like let it grow however it grows, right?
- 58:40Yeah.
- 58:41Everyone, let the TurboGear's team know what you need.
- 58:45That's awesome.
- 58:45All right.
- 58:46Two more questions before I let you go.
- 58:48If you're going to write some Python code, what editor do you open up?
- 58:51Well, as an editor, I use Beam.
- 58:54But as a development environment, I'm using PyCharm.
- 58:59Yeah.
- 58:59Okay.
- 59:00Very cool.
- 59:01Very cool.
- 59:01And of all the PyPI packages out there, what are some that you think are amazing that people aren't using?
- 59:08Maybe web assets?
- 59:10Yeah.
- 59:11Web assets, I can definitely suggest it.
- 59:14It's one of the tools that I use most frequently and it works perfectly.
- 59:19It's been around for a lot of times.
- 59:21So you can use it on production and go on safely.
- 59:25This has been a fun conversation.
- 59:27And it's been great to think about the future of the web and web frameworks.
- 59:31So thanks for being on the show.
- 59:33Thank you, Michael, for listening to me.
- 59:35Yeah, you bet.
- 59:36Talk to you later.
- 59:36Bye.
- 59:39This has been another episode of Talk Python To Me.
- 59:42Today's guest was Alessandro Molina.
- 59:44And this episode has been sponsored by Hired and CodeChip.
- 59:46Thank you guys for supporting the show.
- 59:48Hired wants to help you find your next big thing.
- 59:51Visit Hired.com slash Talk Python To Me to get five or more offers with salary and equity presented right up front and a special listener signing bonus of $4,000.
- 1:00:01CodeChip wants you to always keep shipping.
- 1:00:03Check them out at CodeChip.com and thank them on Twitter via at CodeChip.
- 1:00:07Don't forget the discount code for listeners.
- 1:00:09It's easy.
- 1:00:10Talk Python, all caps, no spaces.
- 1:00:12Did you know you can personally support the show too?
- 1:00:15Just visit Patreon.com slash mkennedy and join over 100 listeners who contribute between $1 to $2 per episode.
- 1:00:23You can find the links from the show at talkpython.fm/episodes slash show slash 35.
- 1:00:29Be sure to subscribe to the show.
- 1:00:31Open your favorite podcatcher and search for Python.
- 1:00:34We should be right at the top.
- 1:00:35You can also find the iTunes and direct RSS feeds in the footer of the website.
- 1:00:39Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.
- 1:00:44You can hear the entire song on talkpython.fm.
- 1:00:47This is your host, Michael Kennedy.
- 1:00:49Thank you so much for listening.
- 1:00:50Smix, take us out of here.
- 1:00:52Stay tuned.
- 1:00:54My voice, there's no norm that I can feel within.
- 1:00:56Haven't been sleeping.
- 1:00:58I've been using lots of rest.
- 1:00:59I'll pass the mic back to who rocked it best.
- 1:01:02I'll pass the mic back to who rocked it best.
- 1:01:06I'll pass the mic back to who rocked it best.
- 1:01:08I'll pass the mic back to who rocked it best.
- 1:01:11I'll pass the mic back to who rocked it best.
- 1:01:11I'll pass the mic back to who rocked it best.
- 1:01:14I'll pass the mic back to who rocked it best.