Kajiki, the fast and validated template engine you were looking for

Video in TIB AV-Portal: Kajiki, the fast and validated template engine you were looking for

Formal Metadata

Kajiki, the fast and validated template engine you were looking for
Title of Series
CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
Release Date

Content Metadata

Subject Area
Kajiki, the fast and validated template engine you were looking for [EuroPython 2017 - Talk - 2017-07-10 - PyCharm Room] [Rimini, Italy] Being dissatisfied with some of the constraints and complex usage of Genshi, the TurboGears2 team started working on an alternative that could solve Genshi speed issues, complex inheritance system and be backward compatible with genshi templates. This is a talk about what lead to the creation of the Kajiki template engine and what's particular about it. The talk will cover: - Comparison on the major template engines available in python to showcase what's special in Kajiki (validated, xml based) what was special in Genshi (also lazy evaluated) - What's a validated template engine and why it's good to have one. - How Kajiki works, showcase kajiki syntax, it's performances and how to use it in any python project. - Why Kajiki is fast, code generation applied and how to write a code generation template engine like Kajiki and Jinja2 (showcase a simple 50 lines of code template engine that uses code generation)
Context awareness Run time (program lifecycle phase) Code Length Multiplication sign Mereology Food energy Software maintenance Uniform resource locator Mathematics Forest Core dump Software framework Closed set Sound effect Markup language 10 (number) Type theory Category of being Arithmetic mean Process (computing) Software framework Text editor Freeware Resultant Software developer Markup language Data storage device Streaming media Rule of inference Event horizon Theory Template (C++) Revision control Integer Data structure Text editor Data type Default (computer science) Standard deviation Validity (statistics) Projective plane Core dump Cartesian coordinate system Template (C++) Frame problem Compiler Personal digital assistant Function (mathematics) Form (programming) Extension (kinesiology)
Revision control Multiplication sign Projective plane Freeware
Point (geometry) Context awareness Inheritance (object-oriented programming) Code Multiplication sign Direction (geometry) Plotter Streaming media Mereology Thermische Zustandsgleichung Computer programming Template (C++) Formal language Intermediate language Conjugacy class Positional notation Core dump Volumenvisualisierung Compilation album Physical system Inheritance (object-oriented programming) Validity (statistics) Kolmogorov complexity Software developer Expression Complex (psychology) Content (media) Fitness function Code Variable (mathematics) Template (C++) Demoscene Loop (music) Process (computing) Network topology Interpreter (computing) Iteration Text editor Resultant
Web page Functional (mathematics) Direction (geometry) View (database) Plotter Multiplication sign Translation (relic) Mereology Template (C++) Formal language Product (business) Programmschleife Data structure Internationalization and localization Local ring Physical system Social class Poisson-Klammer Cellular automaton Web page Content (media) Machine code Template (C++) Type theory Loop (music) Process (computing) Website Escape character Resultant
Web page Context awareness Multiplication sign Water vapor Mereology 2 (number) Template (C++) Mathematics Artistic rendering Endliche Modelltheorie Local ring International Date Line God Pairwise comparison Rational number Mapping Web page Binary code Content (media) Electronic mailing list Code Benchmark Sphere Template (C++) Virtual machine Arithmetic mean Personal digital assistant Website Convex hull Cycle (graph theory) Landau theory Resultant Reading (process) Library (computing) Vacuum
Point (geometry) Web page Computer chess Run time (program lifecycle phase) Structural load Code Multiplication sign Translation (relic) Control flow Mereology Disk read-and-write head Data transmission Theory Template (C++) Revision control Pi Array data structure Escape character Computer configuration Hypermedia Volumenvisualisierung Local ring Traffic reporting Injektivität Information Validity (statistics) Poisson-Klammer Web page Projective plane Content (media) Depth of field Database Line (geometry) Variable (mathematics) Template (C++) Process (computing) Error message Personal digital assistant Logic String (computer science) output Escape character Resultant Spacetime Traffic reporting Booting
Revision control Default (computer science) Data management Exterior algebra Multiplication sign Software developer Plotter Configuration space Database Template (C++) Physical system
so the name of the complete engine is actually catch so I for any 1 of you was in that light told this morning and I spoke about the topic the fragment actually this morning I'm 1 of the core developed outsourced to a body of which is a what framework that has been all the forest longest jungle and it was pretty beta like uh 4 or 5 years ago and then John is now that the ruler laughter what 1 but there are still a lot of people especially in Europe and in the uh in the eye and other countries that are using to we'll see if the and in the context of operating upgrading to a body yes vital for you 1 of the problems we face was that we were using gain xi which is a very powerful and flexible template gene but there's 2 major side effects is really complex to use for some cases and it's really slow so we started to look around for other projects and uh you and are actually tens of template engines and that if you tried anywhere frame modified jungle flask purely this on each 1 of them as its own February attempting energy and what we were looking for was something that was really today she sort provided some core features that we are going to see and that we ended up in a situation where there was not much interesting around close of these by our needs so 1st of all let's event blob cobra the template engines that we know and that existing fighting which are the most the most common 1 that probably Mark Cohen jean job and jungle templating and to is that only so there's a template engine is is actually more parts of jungle itself but I will say that the learning they properties of those template engines are usually divided in 2 kinds 1 we achieve we choose to use this syntax is marked up based or refute these free text for example if you ever used ginger you can actually out prodigally everything inside the genes lady but they're really have to be valid mark-up in anyway as far as the thin plate is able to understand the structure of your quote it's fine you can even use that for j so for example or whatever you want and then there are the that's about Captain plates and then the way they are actually around it and itself which might be combined stream and they combined them great danger in our the most common kind of template and you know what that is because our found really fast use only a few of the things in the right way it can be really fast in fact the fact that the compiler the template engines compiled means that he gets comparative to pure Python code so would you don't bring doesn't exist anymore gets translated to Python code and that might encode get executed while in the other case again she which was 1 of the few example of a stream that can length integer is actually uh perform the runtime so what he didn't can change itself for example because the template as easily structure and just a stream of types of parts of the thin plate in each part can actually change the 1 that are going to come after me more that they can do and powerful manipulation was run time of the template itself which is something that looks really cool but was actually pointless in made a lot more complex to use the template engine and in practice people never ever use the theory of war that apart from the guys that are actually created gage and I'm most owing to remember in which project mostly that I can't remember right now was a he Sutra making tool so they created for their own needs we're really love the fact that she was valid perfectly valid HTML which means that you can open it with any editor that understands HTML doesn't need to add any specific support for uh geisha completes themselves they are perfectly valid HTML while fact like cool in the gene giants on ad and then 1 more layer on top of the HTML so you need specific support for them and the fact that the change in gene j she saying parts was pure HTML means that it was really seen out to the alkyl you got so that the template itself wars in fact there the result of the the execution maybe some piece were removed of things like that but it was still really seen to the uh to the template itself and will obligations so much that in version 2 . 2 of to a body of became the standard template engine and all that pluggable application which are like he's you can bring into your justification uh where based on gage as it was this standard default template but 1
day there the guys that's where Mendelian thing again she decided that he was no there were no longer interested in 1 thing which anymore so or is it actually some be both that the in but the project is nearly that no what they not being seen as not seen a really useful like years and has been ported to on free but works only on some version of white and free if I'm correct it only walks up to a height of 3 . 4 on 3 . 5 and so on it doesn't work anymore and that
this was actually how are you feeling at that time this news came because we just make geisha along fault engine for everything and then the next day they just remove the they say is going to die so we then I want to step
in a mounting tension because due to their design due to the fact that it was a stream bending it was incredibly complex it was so 1 of the most complex code that I ever seen imagine you are trying to create an interpreter for a dynamic language which was so as real thing to the language itself the ability to modify the language itself but not in the way that Python buzzing which is you can modify the bytecode but in a way that don't actually modify this was called the self so you cannot transpired that's was sold to some things easier you always need to work on the high-level complex language and converted to a stream of and things like that was really powerful but very few people understand the inheritance system of cation because it was a really complex I'm not going to show you much about gay because we are going to see Yao cadging keywords which is nearly the same this women this thing and we were lucky enough that 1 of the 2 but just core contributors was working at so splodge at the time this is large was looking to a new template engine that will replace ginger and be as fast or even faster than jean job but we better validation for what they were doing and things like that so they started experimenting with the idea that they're making Tajik in this is that the scene thoughts or conjugate from the short example you can actually see what I was trying to tell you which ease the decoding cellphones pure HTML we have some other that use for example you can see that by content you can see that by 4 and things like that and the pi content means of at least the content of the start with the value of the expression that is contained in the by content Y and the pi for of course means repeat these dot the stack as many times as the iteration of the loop and you can of course is as about to variables we there 1 of the most widespread notation for valuables replacement in so it was easy to see that a good part of these kind of template engines is that you can actually throw the template that anything that was we've HTML for example I so people uh having their designers work on the and play find themselves with some kind of all what you see is what you get in the doors and they could just change it in any way they like and then the designer when he was at the with the result will provide that the template fight to the development and was still a profit divided uh gain showcard keep and played as far as the editor of the then remove the parts that we didn't know or things like that which they usually don't do if they see a by content that just leave it there because they don't know what to do with they directives that are provided by Tajik you are the most common 1 you can of course you files each for best 3 point not going to spend too much time on this because I suppose that most of you already work with some kind of template Benjamin very nearly all year be the same way but the interesting part is that Tajik he's prep parts and converted to pure Python code this is a really interesting feature of than 1 many template engines provide an which allows us to do very cool dividing and a very simple inspection of what is going to happen uh while while we are writing a longtime player in the code itself
is actually generated by air but I use the program because these generated by the generator or in the sense that there is a generator that goes through you all syntax tree you all templated structure and for each pack that you've wrote it actually against that IPython expression so all you just can't see that your template is conducted 1 by 1 to Python code so a URI if you know when you start working we can you will know which called will end up for what you wrote and you win all facets would be we sigh that fit into elaborate things like that and then after the compiled plots equals that represent everything to where intermediate representation which is seen simpler tended and play the In this context essentially resembles how most of the compilers what most of the compilers get useful code get an intermediate representation that is easier for them to manage and then they talk about something else and this is actually what
conjugate throughout out so that the same exact and plate that we saw before it gets converted to these codes so you can see that it's 6 classes and provides a single middle views on the which is the main which is actually the body of your template and for each entry if it is something that doesn't need to be processed in any way it's the plain text that you wrote so for example I have you HTML plot held the title and so on and they are just sent back as the young Y and then comes the really interesting part inside the title I provided the custom content we chose was the title will then what can you could us just replace the text read the instruction that would set the tightening their results into the out so we see that we have the title than they content of the title body of all which is the other direction you can can see 1 more function being called around because kind provides automatic escaping of the entities so you don't have to bother himself to like replace the text that was escape there uh and angular brackets like that the the user cannot provide any content that will break the HTML because country with xk Paul the markables that you're going to show and then you have the title like the clause title after the valuable and then there is 1 more interesting part if you work leveraging job or other template engines the internationalization the translation of the text is something that you usually need to take care of you by yourself you have to do like to underscore a something in front of this things that you want to translate or you have to collect them in some way or things like that Wang Tajik you be intimate sensation in built into the system as it works on the structure of the language like HTML you can recognize which part of the thin use the structure so the attack and which parties content so they bought the text of the time and we can say OK I don't care about the structure of the title of the ad in the body that those are not something that the user just about they are just something that represents the structure of my page but then the user cares about the text that is contained inside these are some fruits and the text that is contained inside the cell emitted by you for you by tragedy so if you have a translation available for that phrase here we ultimately translate that for you so you don't have to remember to drop all your texting gettext also things like that and then provides the for loop because we added it by for type 2 2 was the
only member which was the product will list item so we have in the site and the loops so kojiki complies he were for
real that brings the list item and its contents and here you can see that the the user gain there I like to be a valuable through it and then there is a new 1 this is actually an old notion of God you can because your recent rations this 1 won't be translated because just empty text so it was just be skipped and then you have the uh the ending part of you attempt OK so this is the result when the template that we had in those these these result which is I the same page read the text that we provided in the valuable and they uh repeated entries we adding that through its the fact is that this approach is able to make a catch here really really fast for example by doing a comparison to I will render the simple example like in uh 1 million times rendering these example 1 million times to 22 seconds the model why doing the same exact example encouraging people to quality of of the time so it's twice as fast as model which is actually 1 of the fastest and use that we have a rock so they're actually really interesting feature and it's actually Purup item what you get is purified and the result of college accused Europe items so you can anything that works would fight like libraries like inspection elected by arguing whatever you want for example in this case it does something a really maps which had he suggests you shouldn't do yourself which is compiling the complete ranging we've cited so in this case the combats they're called the kojiki generated to pure C called that that gets compiled offset the Aransas binary code so it's even faster I don't remember if I need any benchmark of these experiments I was just to show you that anything you can do you weep you can when we that Kajetan plate because you just the same exact thing of lot there are a few things that need to be converted because for example there is no no Tajik expose context while compiling sites but when the end it works they was that yet there is a benchmark you can see that without much changes if you ever water recycling you can actually improve performance is lot if you pay attention to a few things but without any single change just by upping might called into cycle the i got there speed up from 12 seconds 9 seconds so just by applying cyclamen nothing else ensure that if any 1 of the best firemen optimizing the roulette at least the out of the which will be like 4 or 5 times faster than model which was still the fastest 1 of the fastest
1 and the fact that the sphere and vital means that it's easy to the back any tool you know that the work sleep idle works
gadgetry and for example 1 of its employees the like the bag of or the backlash the bargaining to a body of we each whenever you have a feeler India tragedy called can pinpoint you had the exact place where the template failed and you can see the exact instruction that failed you can inspect the variables because there are just plain Python body nothing magic happening so the only deciphered the catching inspect the called and replaces all the information all the data that doing uses for dividing we've other values for example instead of pointing to the line of the pie to encode the points to the line of the thin plate so whenever you see the fatal or that he fail but line 25 where you template you really don't carry the fate of the line 400 of their Python code that was generated as a result of you
template it provides profit by dancing by checking this is something that many them pretending that are Estonian doffing that or process that the runtime do not provide whenever you start because can place when you combine not when you're running so not when you are showing your page but just when you are compiling USOS code URIs intense get checked both has the HTML that ended the bipolaron soul in this case for example I got there initially we might Python code being invalid and it tells me the exact line because instead of biting by for being I wrote 4 on any complaint that theories a that deadline the reads on instead of he change so I get fighting until the gets validated an it some of the future that I already the explained to you in which our media reporting we whenever the Tajik thin-plate phrase you can inspect it and see what fail you get automatic escaping so you don't have to remember to remove any character from the input might break your HTML or my tools job things injection you where the blaze he does logic uh transmission for you and the ultimate again unifies the result the result of that page if you want to use is an option I've gone too far enabled but there are people who care and the real unified HTML for you and the thing that I love most from tragedy is actually the fact that validates my HTML to I For example I still remember that more than 10 years ago I was working we've Ruby and they're really be project we were working on all arrays had the page that was broken any 2 cars like to allow us to find we each partial templated he was used from a complement there's is the like that 20 that of the stones from the page itself had that thought that wasn't proper and you will be there realizing we only know in got to find the issue because what some users complained that the page was broken and the whining Tajik he checks your HTML and the chess that it's perfectly valid like in this example I opened it for me the least item but then I close it there's a spot like them the 1st contact in Tajik essays you the something that doesn't make sense you open the the Spiderman your closing a spot disease clearly from so you can see that it's going to bring to you from many hours is going to do a lot of things for you and it's actually faster than most of the template engine you can find around and here is an example of the automatic escaping that I was telling you like you fight random account templated we've had as a fruit body in this case the ball as the younger artists brackets so in short break our HTML because I get the maple which makes no sense at all can detect the Aeneid we'll bring as a result of the escape version of younger or brackets so it will bring you less than entity and the greater than entities instead of you know a break so means that you don't have to care too much about you use those striking their comments Monday shows jobless little things like that because when you rearrange the comment that they provided even if you store their money issues according to your doctor database tragedy will Wilek's for you and you want to break your page and a translation if I tried something like these I like fruit and then conjugal what guy that that that that I like part can be translated the simple in text that this interesting for humans and not interesting for the HTML part so so it's something that we can mostly it ultimately robs the text for you and we get goal if you didn't provide any translation it would just out the the full text you wrote if you provide a written solution you we'll priority translated any does minification for example in this case you can see that I wrote it and plate we choose random to the set the star items and if I Street the text which is animal desorption Kon-Tiki gadgety without intervention of the HTML we choose 3 all all for all the empty spaces which is still validation about so it will maintain like uh content of Pereira streets or things like that but the wisdom if invading was that against the and of course like many other template engines if you're not working we've HTML but you working with something else you can use it on plain text so in this case is the tragic using passport plain text like we did the example of using a template engine with J some of things like that what a that I was shot in the head like I did this ball plus time like 3 years ago so I don't remember will be enjoyed it who was a good fall back and if you
have questions feel free to ask and like
judging here let me know what you think OK and fj
it the but yet not directly related catching people what is happening with TurboGears I mean this is still under active development or because it can have folded into plot a until whatever the In alternate and then there was another 1 that began would be in and they were going to you know which was closely the was giving is still under active development or what's going on with it yeah it's the ongoing the development he became the default template engine into a body of conventional Telecom to interpret the use of self have and we just really is like 3 days ago about shrunk to about 3 . 11 defined correct and the reason is being there really was a major revival during the version to lottery that maybe like 4 times faster and it's not depending on violence anymore but it's field compatible and in the upcoming version which will be rational to vote for you has a major overriding their liking system for configuration and things like that so it's still under active development and it's trying to maintain fully backward-compatible while moving on things like that and how many developers are actively working cut currently I'm currently the is manager for 2 and there are a lot of the 3 people that continuously work on the on the databases and there are like in 7 8 people that contribute from time to time the thank you that it putting her