 Okay, so hello, I'm alexandre bourgeois director of development at saouafali nukes This is gonna be pretty quick and so just get your brain straight and look at the screen Okay, it's gonna be a demo. I have a lot of stuff. I never timed it So I'm just gonna rush and look out how long I have okay. I'm a bit tired. So I might do a lot of typos So we'll start see I have that I never did that before slide. Okay. I have a couple questions I want to know who you are. I wouldn't tell me who has some PHP background. Raise your hand Okay, who has some Python background does Python. Okay. Okay who who heard about or read about pylons before oh Wow, so you use that who who use that? Okay Who worked with Django previously? Okay, so a bunch of Django guys who knows virtual and easy install Pip the replacement for oh Okay, and who does the web development with Java or did Yeah, of course, of course did okay. Okay. Thanks, and everyone knows what an MVC framework is Okay, raise your hands. Just I have a good. Okay. So I want to explain that Okay, good I'm just gonna quick start with a little comparison between Django and pylons just to set things I'm not gonna bash on Django. Just have a little difference Okay, so Django is the all-star see it's one single thing It has a norm to deal with databases URL dispatcher has its own forms manage Which was are pretty good and request object authentication system and templating language It does it pretty well it even plays guitar or almost and whoop now I'm screaming the thing and It has a lot of marketing and a hypes in so and pylons is more like the milky way You have the best of the breed components from elsewhere See see what take pick up the best templating out there engine out there and it's wired into pylons So pylons by itself is about thousand a thousand lines of codes and Mako Now you choose your I'm gonna have a little demo here so if you want a good or I'm go and get the best of the breed and plug it in wire it in and So poof see you have like for example Mako Jinja again She ensues your authentication system. There's many out there, but you can wire them very easily and The strength of Python will see it's because it's WSGA by GI based Okay, what's for web stand server gateway interface. We're gonna see that in a moment Okay, just how I didn't screw things up Very good Okay, so over here. We're gonna see we're gonna see pylons. What's WSGI and what we can do about it controllers templates mode So the MVC MVC here. Okay, this is the view and we're gonna see a lot of demos and some fun stuff We can do with with pylons being a WSGI framework Yeah, that's horrible just to follow Okay Now we're just gonna set up the environment We assume you have virtual and even pick you're not gonna do that with me But we have that already installed you can install pip with easy install. It's pretty nice thing. We're gonna do that together Okay very good Just so you pip a little bit here if you pip help you have a bunch of new Functionalities which are pretty cool like bundle you can have a bundle which is many packages all bundled into one file You can deploy that on the machine pretty cool and freeze your feature like build out system You can freeze all the requirements and all the versions in a file and then you can install from that You can have like a subversion and git and Repositories listed in there with specific version So when you check out or install a new environment with pip while you can or a new installation You can unfreeze those version right into your environment So you can follow and notice here the uninstall which was lacking to the easy install world, huh? No easy uninstall so that's pretty cool, too Okay, now we're gonna create a virtual environment okay virtual and we're gonna specify we don't want no site packages So we don't mind of the Debian distributed packages, okay? We want an isolated environment and we're gonna call that pylons and it's gonna be created here and let's look into it it's pretty quick just drops a couple of files and See you have a little sub architect sub here hierarchy here Which have sim links mostly and sim links to the standard library and a bunch of file like pip and python and you're gonna activate that with Activates notice here the pylons and now you're in the environment if you run python from there well and import OS for example You're using the one in the environment, okay, so you can isolate all your packages right there, okay? So we're gonna use that and And Poof very good I'm gonna just show you what WSGI is now I should see that There you go. Thank you Okay, so what's WSGI WSGI is? Java servlet, okay? Specification it's a pep 333 so it's standard in python. It's the way you deploy web application It's the standard way to deploy web application some of you might have been there when I present that as a flashbook So it's a bit I need to stuff it in so it's complete mode. Okay, so for example, you have Apache here and That worked Apache and with mod WSGI which is loads the interpreter here. Oh Shoot That's bad. Okay, that had to happen Okay, this way here Okay, so it's gonna load the interpreter and then run your program which contains WSGI We're gonna see what the WSGI application is it's gonna run that and loop until some client outside Go and get something goes through Apache hits your program knock knock and it's gonna call the application here So it's gonna call the actual python object and it's gonna populate a special environment Which looks like CGI variables or what you get in under dollar underscore server act happen when in PHP So if you call when you're gonna call the application like that with two variables It's a very simple spec and wait for the response and deal with it and send it back to the user. Oh, yeah They're very happy user Okay, the application looks like Three modes of first application mode. You can you just have you just need that It's a callable and it returns something that iterates So in a terrible that's gonna be a generator and at some point it has to cost start response If it's going to return something it well, it should do something. That was just a hello world That's the environment variable. That's passed on and contains the request on the server part Well, you have this and you're gonna create the environment call the python app deal with the response and now middleware that's nice stuff because Just like serve like can be stacked together and give Functionalities you can do that with WSGI for example We're gonna have an example so this acts as a server to that application this one acts as a server to this one While this one acts as a an application to the server very good. We don't okay So let's look here I have a request coming from the web and so we all want to get something it goes through ever middleware Which is the stack here? That's a stack. Good. It's gonna go through Come on Session middleware and the session is gonna fetch from the from the drive based on cookies and add some session data To the environment variable it's gonna be passed on to my application We're just gonna do something or crash and if it crashes It's gonna go back to the session middleware with an error. That's my error Okay, and go to the error and error middleware is made to handle errors. It's going to Produce a nice a beautiful page and send it back to the user Unbroken and you can even have further requests and go back and forth between the error middleware so you can debug interactively We're gonna see that that's awesome. Well, that's in the pylons framework That's the end here now Okay, we're gonna install. I think I should go back manually. Okay. Sorry for that. That's horrible Okay, okay. Now I'm going to install pylons Okay, only doing that here Will install it's going to download the packages from the web, of course, you know whoop. I don't care I have squid 3 and I have all the package installed Oh Where did I do that pip install? Oh, yeah, sorry, okay So it's going to install so I just gonna shoot the command once more it's going to install down all the dependencies and all this stuff And put that in my environment in my local So it has installed all the dependencies with pip install that allowed me to just download and not install right away, okay? So Now the next thing pylons uses so as I said pylons is a thousand lines It's really glue and just a way of thinking and bundling things together So pylons does not do deployment per se. It uses pacer, which is an awesome deployment to a Swiss knife it's another Swiss knife and so you have to and So for example pacer is going to deal with creating a new application is scaffolding in the rail in the rails world And it's going to serve the application pacer has a production ready a web server and like Django Which you had to you have to host somewhere else because of the run server doesn't isn't Solid enough to serve on a okay and set up up to just set up the database and create the temporary directories for example Okay, so that's what pacer does so we're going to look at create here and create can list Templates and we see we have two templates pylons and pylons minimal So we can have two kind of projects and you can build those you can say I have all those files built and it loads that plug-in Loads that system and I want to be able to start off with that Package next time so you can do a pacer template and load it like that. So I'm going to create whoop create See I slept very well Pylons and we're going to just get out of here You don't have to be under the environment to deal with that. It's just activated So pylons, we're going to call it MTL pi. Okay. Okay. Now we're being asked A templating language see we can use Mako Genchi or Jinja to let's have a look at those things This should have been automatic Okay, so here's Mako an example. It's more line-based very powerful very fast It's you can insert. Oh, that's very Pythonic. It uses Python syntax Those lines will be rendered as HTML and you can render any type of files csv or will have you okay? So sample Mako and Jinja to this is more like a port of the Django templating system Which is I think more powerful on the guy who did that wanted to add some functionalities So a lot of Django people want to use that in Django because it's better. So use that syntax You can wrap it around pretty neat and Genchi, which I find pretty cool to see you use those Fake HTML tags and it it's gonna deal with the line It's not you don't have to specify and for it's just gonna loop in the structure there So it's not going to display if there's nothing in the links. That's nice Okay Can't follow that Select Mako Okay, so we're gonna select Mako because it's nice and I'm used to it and I love it and now SQL can be here is An orm so object relational mapper. It deals with database interfacing with Python It's a very awesome package And you would like to learn it right away because you can use that in pylons But in all your other database needs you don't depend on pylons unlike the Django orm Well, you're you're tied to Django. You can't use it externally something like that or with a lot of us I'm gonna put true here and in mtl. Sorry Is that the next thing an mtl? We'll have our pack or We're gonna see that right after I just want to start with a demo of SQL alchemy. All right It's in fact an extension called SQL soup That helps you introspec databases already existing databases and you can just Okay, and you can discover from the inside and use it object-oriented interface to your data So to do that we're going to create a quickly a From scratch a database. Oh wait a second we need to install SQL alchemy there we go downloaded from the web and install all all right And we're going to create that database so super db.sqlite create table users with ID integer primary key auto increment and First name varkar something like that. You used to that varkar to 5 5 last name varkar to 5 5 Oh, see I knew there was something you know the syntax for a Auto increment. Oh There's the underscore here. Oh Okay, that probably be okay. Let's take it out Cuz I I didn't test it with the auto increment anyway, okay, so insert into user. We're gonna add some values So ID one Alexan Something like that, huh, and then I want to change that for alt one was my brother Oh, yeah, I have to put that too and then somebody else. I don't know Bob Dylan okay, there we go. So we could select from the database, you know, SQL SQL light tiny database It's a library from users here. We go and There okay, we have that file Super db sqlite Wacky's my username Okay, now let's go with SQL soup. I have a python here. We're gonna import from SQL alchemy From extension SQL soup import SQL soup and we're gonna create a connection to soup So SQL alchemy is also a database instruction layer. So it deals with any database in the background oracle and you name it Okay, so here we just specify super db sqlite and s discovers automatically that there's a table of users And you can query them and It's gonna return objects where you can access the elements inside and SQL alchemy has that neat pythonic syntax to query it So if you do for example users dot id equals equals one You don't have to specify id underscore underscore and all sorts of creepy stuff It returns a binary expression because the python allows you to do that I don't know why some people didn't do that and if you print it out or cast it to a string It's gonna be returned like that and you can pass it as a parameter users See whoa, what's that query? No Filter sorry Filter and that gives you a query a full query and you can run it with All or put in a loop so it's an iterator. So you got the element here. Okay, that's pretty neat. Isn't it? Okay, thank you Now we're running pretty fast, aren't we we'll have a lot of time for questions Are you following? Okay, good pace So now let's go and look at the files No, is it all right? I'll try to slow down. I have a little difficulty with that So let's just look at the files in our project here So you have an egg ready set up the py you can pack you can you can Deploy it on pi pi and French is pee pee. Okay, so and it's ready to go You be disted upload and it's ready to go. You have those So let's say the model here. I didn't explain the model here You have anything you want here was going to be SQL alchemy stuff But you can have anything you want to go to data flat files a couch DB kit for example and grab your data from anywhere It's a generic term model. So you store that in in it now the controllers We will have your controller data here the business logic stuff So you can name it you have several several of them and each controller is a wsgi application. Okay, and we'll see that's cool Now in templates, you'll have all your templates Which are basically what you want Mako templates or Genchi templates or flat files if you want and in Lib Well, it's just a convention here So Lib contains all your things you're going to use for in every controller base For example contains things you're going to use in a controller's helpers You're going to use in the templates most of the time so load stuff you're going to use with h dot For example trim or cut to words and put your trailing dots stuff like that and app global This is where PHP gets blown off. You have an actual application running and it keeps its state You have a Python program running and it requests coming in and app global is shared between all threads all requests coming in Shares app global and you can have some cues in there So you can share data between those threads for example having a somewhere a jabber connection and it's Spits out data to the different threads and you have the user connecting. So that's pretty cool You can't do that with PHP unless you you spit that on the disk serialize, but then I'm in cash D and stuff like that Okay, config you'll have all the config configuration. Mostly those things not going to change a lot rootings routing Sorry, you're going to route for example this URL to that controller slash foo goes to foo.py and You have a pretty powerful engine called routes and actually it's an external project just tie it in here because it's the best Yeah, okay Environment is just one function that's going to set up like load the database connect and start up your things middle where we're going to see the moment and Test stuff public is going to get served and yes with pylons You can actually serve your media files with pylons You don't have to use some other means because it's not safe or something like that Not looking at any place anywhere. Okay, so we have the database and we're going to see that any file Which is just the configuration files any files. Is that clear? Sorry, I'm giving a lot of Course these times. So is that clear you have you understood have questions if you want to stop me at any time you can just scream Okay, I'm speaking loud. So you just scream and say what's that or okay? Don't be shy. Now. Let's go and look the middleware MTL pi config middleware no CD come on The middleware file is I don't know if you notice a little bit earlier that my app See you have your WSGI stack here That's the actual application the one we're building and it's stacked with the routes middleware Which does that URL? Directioning and the session middleware where it's going to load from disk data according to the cookies and the cash Middleware if you don't want that anymore, you just stack it out and of course a little bit like other MVC frameworks And you have that awesome error handler Which does like I said you can debug interactively if you put that on production of course You're not going to put the error handler and that allowed a people to import OS and OS dot system but it's very useful for debugging registry manager and You can serve here if you want static URLs in public and you just return that application That's your WSGI application the stack is built and each application has been configured according to certain configs I see here You don't have the same screen. Yeah, here configurations, okay, so that's good now. Let's go and create Let's we're gonna run the server. Okay, so we've seen paster here paster Oh, yeah, one cool thing of paster you can you can have some plug-ins So here pylons have some plug-ins you can have the shell and controller So it's pretty easy to extend and it's generic You don't need to use pylons you can deploy other types of applications in fact any type of WSGI application Okay, so we're gonna create a controller to do that We're just gonna create controller foo is gonna create two files a test file I do tests with external tools, but you can do that in in there. I had to press a button I don't think it's useful Just a second. All right, wait for button Okay, so I have that controller here Created and I'm gonna call up paster serve. I'm gonna pass it reload Oh, let me just show you development on any so that's the configuration for our application So you have a couple of defaults you want to debug that's going to be a that's going to turn out as enabling or disabling the error handler SMTP server you'll receive you'll receive by email. There's an error on your application with full debugging info and logs and stuff so the server here Listen on that port use that as a loader and we're gonna listen to port 5000 now for our application Well full stack. Yes or no in static files here The beaker is the caching middleware and the session middleware, which is pretty good And if you deploy a new system, it's going to create a random secret so it can encrypt the Elements you have config here and most notably SQL alchemy here URL so you can choose your database In fact, we're going to use that cute database. I created earlier Yes, I use emacs Okay, so it's super DB dot sqlite. What was it? And you have those vloggers. Okay, very good now. We're ready to run the server aren't we and We notice a reload statement here. That means it's going to detect a fast change reload the server But we have that can be annoying sometime when you have a big big problem So we have a demo of sensing very sweet that can Allow you allow you to blah blah, okay? Now this is getting. Oh, there it is Very good. It works. So you have that's the welcome page Those files in fact are just in public a bunch of files in public You just trash them away and you have your your Your environment setup. Okay now we're going to go in our Controller foo and look what's there so you have a bunch of imports most notably. Oh, okay. Those are comments We don't care. I'm going to read them out if you want so you have that controller based on base controller That's a WSGI controller. So that thing foo controller at the end There's you have that identity or foo controller is an actual WSGI application It's going to be called as so because pylons is Interleaved with WSGI and it's going to route according to what the routes took out from the URL for example slash Index or by default. This is the default Method It's going to call the right method here So if we see So the the controller is named foo. Let's go in the routing section So you have a pretty simple match The controller name if you have the controller name here and here this the action Well, it's going to be routed to the good controller and action So these are two important keywords controller and action that actually point to the right place Shouldn't lose too much time here Okay, so let's go and see foo Index for example. Okay, here we have hello world Which is awesome and if you modify Well, we'll notice here that's get that gets reloaded restarting and it's going to be changed. Wow So are you very happy now? Okay, now let's go to routing and add for example map connect You can't read the green. I Can't I'm sorry Not at this at this time Sorry, you have the emacs command right away Color Okay, so I'm going to use I'm going to use geodit. Can you see that? Is it better? Sorry, yeah, good. Yeah, but I don't think it's going to be as fat Because the font of the terminal is fat and it's going to be small just like a chance to draw away. We couldn't read Okay, is that all right, so we're gonna have here Blah blah goes to foo index goes to browser. Okay, so we can and open that's going to be slower though config routing if we go here Different HTTP versions Verbs. Yeah, of course. Yeah, Russ deals with that. He's going to point to different thing You have a full rest controller. Just drop it in is going to point to different. Yeah, of course. That's supported Yeah, so you see you can go to drop foo and index so slash mp11 is going to point to that foo controller and action index It's gonna get restarted and if we go here mp11 is going to point. Wow. That's brilliant I probably made an error and it crashed the server. So There you go mp11. Okay. That's very not useful. I'm gonna Put that out for the next time Okay, now we're going to use a little bit of Mako so of the templating engine, okay? Okay Thank you. So this we're going to trash out that return here and we have the comment that we can just put in Return to render. I'm used to emacs. So foo index dot Mako. You can use HTML if you want That's just the exception that we give man. I think I'm gonna go back I'm a bit speedier in here Let's see HTML so you don't have the same coloring. Okay So templates foo index dot Mako. I'm going to create that No, no, I don't want that. I want to create that simple file. Can you read that? So I'm going to show you all Python 11 titles. So you have something like that Body what we're gonna have some So I'm super title and some paragraph Super stuff here. Okay Now you can see the render thing Well, it's gonna get rendered That right Server all great. So see that now we crashed. I probably entered some weird things or broke So you have that top-level look. I don't know that extent that that error But I can go in here So that's the web error in in action it crash and now I'm on a solid thread and thread is continuing and I can deal with the server with the The exception objects still in memory and I can go out in any level for say first see the code here this level or that at this point of the stack and Go and import pylons or from pylons Import config and look what's inside config keys and we have all this see we can really introspect the request Whoa from pylons import requests request and the fire and of course that's not pretty useful because you have already that in extra data Okay, and you can view the source code of each of the files right away here Okay, wow Now let's fix that error So an mp11 so what was the error? Render foo index Maco can't locate. Oh, it just can't locate foo index. What's the file? Oh, yeah, that's horrible I didn't save the file Nick directory. Thank you. Okay. There we go Okay, so we have that file there perfect So let's add a bit of mako stuff for example if we were gone we want to loop We want to loop through a list. Okay, so import random and we have a list here of random stuff How we would do that ran int? zero to two hundred I don't know for X in range Ten okay, and we're gonna store that in C. Notice that template context here that pylon does that integration To see there so my list oops Equals L and in index will be able to reuse those ran it non-define. Oh, yeah So that's random. It's not better. Okay So let's go in the template now and for example UL Li and here for L in my list Use that yeah, there are numbers, huh? So we're all right with this and That and for Okay, so these are random numbers. Okay, so that's the basic stuff. You know that huh? We don't want to see that So I wasted a lot of time doing that I'm really sorry. I'm gonna try to strip that up a little bit Okay, so now maybe something a little bit more interesting. So we want to have our application to actually serve video files And we had on-demand File server you do that with Apache serving the files But you have to HD access files to secure or other means we can do that all in pylons because there's that awesome file app WSGI application which deals with with a byte range is all the cranky stuff Apache does normally while you have that WSGI application which does What you can't see now this had to happen We're just gonna pause I I Have to get the right time. What's that? Oh, thank you. Thank you. No, you didn't do anything Yeah, yeah, of course Okay, I Want to go back to Emax? Okay, now if you want to do some video blah. Yeah, that was this one here They controller showing it off controller foof. Sorry Okay, let's create that so in food. We have index. We're gonna save that as Video dot Mako and we're gonna put some Video embedding stuff, but we're gonna grab SWF object and stuff like that. Okay script and type text Java script here SRC equals object.js. Don't worry. I don't I won't type SWF object And then here we'll have that div id video which is gonna be empty and a little script here Which is going to embed so the latest version of SWF object is embed SWF takes Media player VRL Okay, we're gonna grab that from the web Now we want that in a video tag so it's gonna be six We have that Adobe version some Expressing soft stuff and then the flash bar that's going to be in video file. Let's for example elephant Or mp4 I have here Okay, and that proof that should be pretty good Video So that's our video dot Mako file. Let's go in the controller diff video self and return render food video Mako We should we should be able to see that at food video Of course, we don't have the files already. So we're gonna go here and Whoo, there you go download The the media player and download the SWF object shoot. I should have put that in an NPL public. We want to serve that. Okay Public public and unzip Local directory here media player. So we're all set. We have that SWE object blah blah Now what about the video file? We have nothing to play here. It does not exist So we're gonna create the controller to do that the controller part to do that Okay, we're gonna put that in a video file for example self and we're gonna get the file name from here And we're gonna use the awesome Is it from paste or file app? From import file app and return file app temp Don't do that at home. Okay, and This is a wsgi application Okay, and file app is gonna be returned and that's enough for pilots to just deal with it and call it and anything that this does It's gonna be returned as the final request of the user. So to do that It's just it's not just an application pilots can add the environment and start response if it sees you have that in there And after you created the application the configured application. Well, you call it Wow So you can use any like for example track or an instance of track the bug ticket system You do the same thing in just instance of track and you have it running there at that amount point for the mountain point part Let's look at config routing We're gonna add our little map connect video file and file name So anything that goes there is gonna go to controller foo in action video file. Sorry for the pep 8 compliance. Okay, and That's good. Sorry Too many ends. Oh In connect. Yeah, that's true So normally normally if elephant dot thing exists Wow, it's there. Okay. I have sin like in the background. So If everything goes right, no, wait a second before we load that No, let's load it So I crashed at some point has not all connect. There you go And doing a play is gonna load that I don't know if you know the open source told the open source movie or Elephant dreams. Okay, so you can play it out. Now what we want to do of course is not just serve a file You can do that with Apache but You could add some security here at that point for example if You have environment variable Remote HTTP and you split it with the dots and you map that Oh, you have the environment here. Sorry Okay, and you have the you split any map with so inter values and then you sum it up And let's say you only allow people which their IP sum is 128 Okay Else you just abort it with permission denied so you can configure your application and use it according to your own fanciness This way if you go here and call the video file, I'm not gonna try it with the Now you're allowed because I'm 127 0 0 1 but what about 129? Okay, that's an inconvenience of a remote HTTP. Oh, what's that remote HTTP? remote host What is it? remote address Sorry So there you go. Okay, so that's pretty much. You know what was what happening? Okay. Now. Let's go and integrate SQL alchemy Okay, because it's fun Let's go in the model here So you have some sample we're gonna uncomment that you have three modes of operation SQL alchemy You can use reflected table. We're gonna see that reflected tables Which are gonna discover the the tables in the database and give you an object or just like SQL soup But you can map it to a local object and all the attributes in that SQL suit we've seen like dot first name and stuff we haven't seen that but Are gonna map to that object and you can add some functionalities like another method to deal with for example users change name or I don't know in validate password or You could use a long definition like this Okay, so you explicitly say I want that table and that column and that stuff you can create very complex reference and it has all Class inheritance hierarchy stuff and it's very powerful Or you could use the declarative like layer like you have in jungle You just say I have that class this attributes equals a column integer and stuff like that and they would all three work We're gonna try the reflected table because we have a beautiful database to use Okay, so let's say we have class user and To use the reflected table. We have to use this one here. So users table Because we need oh here it is Users table equals none. It has to be a Reflected user That's gonna be reflected and when we initialize the model so in the environment. Well, we're gonna go introspect auto load truth and you have to comment that here and Reflect so here you're gonna map the user object to the users table That's a bit too complicated. Isn't it? That should be users of course and a table here will be users So you want to go inside that way this way you could use a an already existing database and create a new application over it And you don't have to manage the schemes other schema schema Fat that thing, you know, have to you let the other application in here provided you don't modify to to cranky Lee Well, you can use it with this application by introspection Okay, so if we want to test that we can hear use paste or shell which doesn't work because Let's just sim link that Pylons environment I always do that here so I can activate poof Paste or shell Which loads the environment so I have my model here and my user and Model user query all is gonna fish in the database Okay, I forgot a line, but that should work and we could create a new user You of course you could from MTL pi model import user if you fan of a direct Access so my user youth first name super Bob and last name a hero Bob and My ID would be seven and then we could add that to the session. Just save it to that database Okay, you have the debugging info. See you can see the actual queries, which is kind of nice Okay, so I won't go through all that crud stuff. Okay, because you probably don't care I want to show you some neat stuff we can do with that. I'm gonna skip that part. Okay a quick overview of You guys want a three minutes break? Okay, maybe I take one next time Templates we're gonna go to the controller here Do I have it open? Okay, so my foo controller? We're gonna show some for example a tom feed So RSS and this is gonna show. I don't know some So feed generator Import a Tom one feed We could create in the Tom feed here, which takes a title super title and a link To that site. We're gonna URL for which is generated from routes Yeah, can use browse odd use without your URL both sides generation of both side of course and link a description super description and and We need a language and then to the feed we're gonna add an item which was a title Some post I know I've seen and a link. Let's go to google.ca, which is an awesome site description simple post And we we're gonna Set the content type to application at Tom XML and return There we go. So we'd have a beautiful Where did the response come from? It's loaded automatically here. So it's a pylons. So that's what pylons Gives you on top of WSGI which the Java specification gives right away. It gives the request and response here WS guys is a bit more lightweight and gives the application the burden of dealing with that But pylon uses web OB, which is the best of the breed a response of well one of the best response objects Request and response. So let's go and see that in the website We don't have a control. All right. We're through RSS Of course, I'm probably did a bunch of typos So I see the feed here and just to be Okay, wait that should launch. Oh, there you go. No, so I'm gonna add that to life. We which is a feed reader Through RSS and you have it here with a new item and a new blah blah, okay? So that's what web helpers is there for you It has a bunch of HTML generation tools So you can trim files cut words and add some dot dot dot change dates and say, okay Since two days since one hour since the last minute and stuff like that also HTML it was ported by from rails Initially, but now it's been expanded. It's a bit more complete and stuff That's web helpers It comes with pylons, but there again, you can use that with other projects. You're not tied to pylons, but okay Okay, that's what it that one's a good one Now what if you have a PHP application and you want to stack it up on your You have an application here You have foo RSS and you deal with that slash the root of the server and you want for example slash Bob or PHP app to host a PHP application Well, we're going to create for that. Oops a controller and the controller only needs so you have to copy paste from the the WPHP website from WPHP Import blah blah and we're going to follow the convention here By pylons to use PHP app controller That's what it's going to seek and I call a WPHP thing We're going to host Well, that's not that's a PHP app and we're going to serve here path templates first element and So we're going to serve from our templates directory. Okay, and we can add PHP options for example magic quotes magic quote gpc off And now you have the power WSGI this is a controller and it's a WSGI application like any other the foo file See foo controller is a WSGI app and the same as the PHP application so you can go in your routes Go in a config routes and add a special map or a simple map if you will pH PHP app and here you add What's the name path info that's going to be passed on as the path info to the controller PHP app here You notice you don't need action because the controller does it all You need an action only for pylons to know which function to execute but here PHP app does it all well that worked Maybe not because I think we didn't install a pip install. Oh, yeah, pip install. I have that in build somewhere PHP There you go Okay Now let's try that before we can do that. We have to create the templates. Don't we so PHP app Let's go in there and do some PHP man so let's try index dot PHP and Sorry, it's been a long time And try to serve that where did we try to serve that? PHP app and index dot PHP is that gonna work no module name PHP app Wait a second In PHP app from blah blah import PHP app. Where do you say that? I didn't say that file. Oh, that's horrible Config not defined of course so from pylons import config. Oh man So you can have all those files hosted under that and you have that WSGI rewrite thing that understands the HT access mod rewrite thing So you can have actually beautiful URLs from inside Python dealing with a PHP application underneath So that's a little bit. I don't know if you say it's insist. It's a bit insist you insist you wish or anyway Okay, but it works. I mean you can have any spawns a PHP a CGI process in the background I think that's yen biking to that or band background. I don't remember any paster tools. You know, yeah Okay, okay, so that's good now What's the most important here? Okay, what do you want? I have I have three things so the reload problem Who can circumvent the reload problem using a WSGI? I'm gonna do that. Okay So see if you have a big application This has to be reloaded if I go here and I modify for example this one I add a PHP app blah and I save it. There's a moment see where that Where that reloads and there's some drops time So if you have that in production if you want to update the code Well, you'll need to restart the service. You have five five seconds depending on the bigger the bigness of the application Well, it's gonna take five ten seconds to reload. So you have that downtime but you can use the awesome or simple or in config middleware You know config middleware a simple thing called me mental and And it's it so you could import me mental Of course, we're gonna need to install that to there you go It's a package on the pipe I and you replace that here with something that looks like Assassin and you give it the actual object you want you'll want to load See this is and we're gonna give it the package We want to be dropped and reloaded at each new request for example, my mtlpy and We won't need to load the pylons app anymore here Okay, cuz it's gonna do it and at each new request is gonna reload everything. That's in mtlpy That's mtlpy in green. Okay, let's try that Because it it seems a bit mysterious For example foo index not implemented index So if I go and modify that foo file Okay, here. I have a bunch of enters and modify that for mako 2 See it's getting reloaded. That's annoying. So let's stop that and having placed our memento thing prevent the reloading and Modify that again. See it's not reloaded Of course, it hasn't been loaded, but so F5 here It's not reloaded And if we change that for randint zero one Normally the code here changed it should be reloaded in order to to be updated on a server Well, it's it got updated right away and the awesome part here is you can activate and deactivate the memento thing So you can just activate it for a bunch of seconds while the code reloads And you still all you get your your clickstream and then you deactivate it on production servers for example So this is neat and that's a double sji application. It stacks in the middle and does a certain good job Okay, was that fun? You probably don't have that that problem often, huh? Okay So that's good in pylons. We have Wow Okay, I Have a next MLRPC server service or controller. Okay, you just change XMRPC I can demo that and I have also the beaker caching caching algorithm with a new Slick a clever CSS package. We can just demo like that. I have six minutes for question You want a question or want me to demo that? Yeah, go ahead Questions are better. Okay, so pylons is the underlying Stack of two burgers true burgers adds some some it selects things for you So you have that or me have that type of thing to choose So they chose things for you and they add some more maybe a Yannick would be a better off to answer that they add more Icandes selected application and more functionalities on top of that But once you learn pylons, well, you know two burgers more right away So it's a bunch of libraries that they added on top of that Yes. Yes here tie up the application instance So the controller here is created on each request it creates a new controller and calls it So you just create a new instance of the file app each time and you can use conditional to run it or not So you have one paster process Which listens for incoming HTTP requests and spawns a thread for each request and in that thread Well, you create a new instance of a food controller and in the code you create a new dynamically, of course That's Python create a new instance of a file app each time well Probably there's some I wouldn't say there's absolutely no Overhead of course if you use a patchy which is optimized But you can't use that when you can you want to have some Checking or error permission checking and stuff like that But you can do it because it has the power to do of course is gonna it might take some Processing time on the machine that runs the other HTML page. Maybe you want it quicker, but So file app is pretty efficient. Yeah, and it's fully fled Yep. Yep. I haven't talked about that, but I'm gonna just show off Where's that oh that's on a bureau The Apache demo Oh So that's an example Deployment script that you put that in Apache. That's one of the methods I prefer Okay, because you can run the the process on your own username You're not tied to WWW data and your environment for production is the same as development because you use paster for development and paster on production and you use the Port mod proxy to just forward every request on the local port so your process is listening on 504 and on the other side. Well, you have that development.ini file That listens on local interface and you can put a script in the inif in it dear Okay, if you use that as an in it dot d script is gonna lower your application of course, just add that to your File.ini and you can use it with that file start and it loads the application apps as that user Spons as a demon and it's gonna serve That might not be very clear But it's pretty neat So you just run your application just like you would with Apache and then in the modular It's not separated. Yeah, in fact, it's separate separate Python process. You can run different versions and stuff in different environments. Yes Yep, yep, yep, it's using production on several servers. Yeah, it's a good thing See it's because it's a project of its own and it's worked on by itself not as a Means to okay. We need that because we have something else to do. Huh not looking at anyone or any project here So that's it any question Yep, yeah, you had a question. Yep though so the session we haven't seen that beaker is a has the cache and the Session middleware we've seen it stores that in a temporary directory. Okay, you can use memcache Do you can do all sorts of a serializing thing, but it doesn't store that in there? Well with memcache. Yes Well, you have several ways to store the session data Okay, by default. It's in a directory Does that answer the question? Sorry. I'm I'm a Quebec or French. I don't speak English very fluently so Yes back there. Yeah Well, you'd put a queue in there so you can do threading as you say one Request one thing cool you can do is for example when you start the process it's that might not be an answer to your question, but You can spawn a process you launch a paster and you start a thread on the side and in that thread You can wait and do some things like for example each hour You don't need to configure a cron job or stuff like that in that case You have one thread more than any requests are gonna have and in that special thread you could also use that apps global and Communicate through each thread using that G. So you'd probably do something like in from pylons import Lib sorry I'm tired import app globals as G before it was G or you can just app globals something like that Now I'm not in an environment or another Directory and you'd use that up global as a dictionary as or I don't remember if it's a dictionary or just the attributes are mapped And they're safe and shared between all the applications. Okay and thread thread safe manner. So Well in that case you probably you're gonna need some other things that I can't talk to you about or I don't want to Yeah, to do a load balancing use a couch DB and use that as your means to Well, I'm not gonna suggest on your required infrastructure for your personal project But I guess you have to find a solution if you want to spawn on several servers. Maybe yeah, I have a central Data exchange. So yeah Yeah, yeah, you could do that Yeah, yeah, we could do that of course you have a low balancer in front put that on AWS Amazon EC2 and have a low balancer hit different parts of those over. Yeah, now that's application architecture. It doesn't have pretty Stuff to do with pylons, but yeah pylons would serve you that like any other sweet Python application Are there any questions because I'm pretty much out of time. Yeah Yeah, so oh I didn't talk about that. So you have to do that you have several Shoot man, you have several Packages that do that you have form alchemy, for example, which does all the form rendering and it's bound to SQL alchemy So you can use that is alchemy the good word. No, sorry. Okay, so you can use that in pylons or in other frameworks But for my key has a an admin interface So it's going to generate an admin interface Maybe not as sweet as the Django one because it's been work and they use that in production stuff But format can be does has something like that. Also two more gears have that cake sprox. Yeah, it's a bit ugly Yeah, yeah, of course. So so the turbogears is built on pylons. I had that question while you were out Yeah, so what turbogears? What does to bring your add to pylons? Yeah, yeah, it's another thing. Yeah, you can use that in pylons and if it Yeah, of course Exactly Yeah, so with pylons you have Flexibility and you can you mostly can if you have a problem if you have a project that use couch TV For example, well, you probably better off using pylons and then adding the other stuff that was probably in turbogears But and to break isn't that matter will be a bit more like Django, which has Django apps You notice here the WSGI Applications are not like the commenting system with a bunch of tables And they're really application years. So under that backs another slash you have like a track instance or you have a video-on-demand service or you have those type of Applications all right. So turbogears allows you to do that So you can have a look if you want into turbogears, but learn that first of course because WSGI is Java's server And who would deploy Java application today without a servlet, you know, you want pipe and create your new deployment methods Okay Well, if that's what you need, of course Yeah, don't just don't just drop and oh, there's a lot of hop on Django and go back go there And if it's not your nevel you're gonna get struggling In fact a lot of people that start off because of the hype and they have to rewrite mostly everything at the end because Oh, it wasn't the fit for that wasn't fit for that It's not powerful enough for for what I need because today We don't only have applications that are like my weblog and my address book and simple database stuff You have an actual application that do some processing and do some particular things and I don't know scan some stuff and be linked to other Internal systems and so you have to think about that Anyway, okay Anything else? Yeah Yeah Well, the Amazon EC2 is very cheap today load of server. That's it's awesome. You can do everything Yeah, yeah, of course of course now you have a several a Python deployment option that our favorite Namely Google App Engine Well, that's gonna run on App Engine. Okay, you either have a couple of recipes just copy paste and and Spit it out on Google of courses. It might not be very speedy when you have a low but their web faction does a Python deployment point and click I think I never use that It does. Oh a woman's voice. Okay Any other question? So I should have a last slide that says thank you, but I don't have that And we've skipped a bunch of things so thank you and I hope you appreciate it And I'm ready for comments if you want to spit on me or stuff like that. Hey, I can talk it I won't be over there at the beard It was a pleasure