Django on the Med with Paolo Melchiorre
Published October 20, 2025
This video features Carlton Gibson at DjangoCon Europe 2026 in Athens, Greece.
Keynote: Static Islands, Dynamic Sea by Carlton Gibson
Python's dynamic nature isn't a bug—it's a feature. Django leveraged this from the start, building elegant APIs that would be impossible in a rigidly typed system. Duck typing, runtime introspection, and flexible interfaces gave us the expressiveness we grew up with. But sometimes we want more. Type safety at API boundaries. Auto-completion that actually works. Data classes instead of ORM objects. The confidence that comes with catching errors before runtime. The answer isn't to abandon Python's dynamic core—it's to build static islands where they help. Incremental typing lets us wrap specific layers (like the ORM) in type-safe interfaces while leaving Django's liquid core untouched. This talk explores when, why, and how to add these type-safe layers, and demonstrates Mantle, utilities for typing around Django's liquid core. We'll keep the Python you love, with those little extras when you need them.
More information: https://2026.djangocon.eu/speakers/JHNLPQ/
Follow DjangoCon Europe on social media:
*X - https://x.com/DjangoConEurope/
*LinkedIn - https://www.linkedin.com/company/djangocon-europe/
*Mastodon - https://fosstodon.org/@djangoconeurope
#djangocon #djangocon #djangoconeurope2026 #django
Automatically transcribed, so expect mistakes in names and technical terms.
Speaker 1: Good morning So welcome to Athens, welcome to Greece. In a typical Greek manner, we should have uh you know delayed a bit of the beginning. No I'm joking It wasn't on purpose. We had the we still have actually some problems with uh virtual tickets. So uh that's why we try to fix it before we start. But Uh anyway, it's work in progress. So thanks again for being here. Thanks again for traveling and being in Athens. Thanks to all the speakers, the volunteers, and all of you uh for uh making this conference happen. Of course, our sponsors So I do not have many things to say uh other than uh you know I hope that you have an amazing time. Um If you need anything, find the people with uh the nice pink t-shirts.
Speaker 1: I know that you're jealous that you do not have a pink t-shirt, but you know that's for volunteers. I will have to give some perks to the people that do uh all the hard work behind the scenes. I think this is it. I'll hand it over now to Marius so that he can get the schedule started for this room. And yeah, welcome, have fun, enjoy, and thank you for being here.
Speaker 2: Hello everyone, my name is Mary Freshak and I will be a host of the morning session. Warm welcome at DjangoCon Europe, the first in Greece. I couldn't imagine person that would be better for to to kick off Jangokon Europe than our first keynota It's Carlton Gibson. He's a co-host of the Django chat. He's the former Django Fellow, the current member of the Django Steering Council. and he wears many more hats in the Django community. So please give a warm welcome to Carton Gibson for the first our first keynote
Speaker 3: Thank you, Marish. for the nice introduction. Hello. I'm I wasn't gonna have any words on this slide, but to be in Athens is just a phenomenal thing. Um on the way here, we walked past Aristotle's Lyceum. Yesterday I went round the Parthenon and wow it really is amazing when you're up there. And I came down and I saw on the map, I saw Socrates' prison. Now I'm a philosophy graduate and to go and s see walk past the Lyceum and to see the place where Socrates was held before his his death, this is Just phenomenally touched by such anyway. Well I'm very happy to be um in um Athens. PEP 484, the Python enhancement proposal that introduced type
Speaker 3: hints into Python contained this explicit non-goal, in bold no less. Python will remain a dynamically typed language, and the authors have no desire to ever make type hints mandatory even by convention. That was repeated verbatim, again in bold, by PEP526 and PEP563, and was carried over to the canonical typing guide at typing. python. org. So type ins, well what are they? Just in case you haven't seen it, type ints are code annotations that let you specify the types of your variables, function parameters, and return types. Here's an example. This is a hello world Django view. It's a Python callable that takes a request and returns a response. That's the web problem, right? On the deathline
Speaker 3: there we have our type hints. The request parameter is marked as taking an HTTP request, and the little arrow bit at the end says that the view will return an HTTP response. The type hints act as documentation for the function and we can run a type checker such as MyPy or Pyrefly or Zuban or numerous others to ensure that we have honoured the contract as specified. I want to focus on those last few words there, the not even by convention bit, because sometimes it can feel that promise wasn't kept. In case you don't know me, my name is Carlton. Marish gave me a nice introduction. I mainly work on and with the Django web framework. It's nice to be at home at DjangoCon Europe. I'm a former Django Fellow, I'm on the Django Steering Council for the current 6.
Speaker 3: 8x cycle, and I maintain well one or two packages in the Django ecosystem. And together with my friend Will Vincent, I co-host the Django podcast. Do give that a listen if you haven't. And just in case you don't know though, I'm here to tell you that Django doesn't have type hints. It's untyped. Django predates typing in Python by over a decade and well we never added them. But if you're a maintainer either on Django or in a third-party package for Django There is significant pressure to add typing. It's one form or other of, well, why don't you just add them? And it's ongoing. That not even by convention bit, well that just doesn't feel true At the same time, we have a bit of a cultural backlash in Django against typing.
Speaker 3: We have at the very least a large minority of users that would take to the barricades rather than us having a doctor rather than have us adopt typing. So the position is hard. There's no there's no just about it. I could talk about scepticism around the run the type safety features really on offer. You fail to return an HTTP response from view and Django will tell you. You pass a bad field name to a query set method and you'll get a field error. You pass a bad value to the ORM, the database will tell you, and so on. Django has 20 years of bulletproofing against all the ways that you can use it wrong. The type checker adds what exactly, they might say. I could talk about skepticism around the documentation value of type hints.
Speaker 3: Django is built on a small number of core patterns that once and once you know them, they don't benefit from the syntactic news of noise of type hints. They might say. I could talk about skepticism around the added complexity of type hints. We always cite the easy examples, like the view example I gave just at the beginning. But you pretty quickly jump off a kind of complexity cliff when you look at more than just the obvious cases. The whole point of Python was that it was meant to be fit your brain But if you asked me how to type in, say, Django's method decorator, well, I'm gonna pause. I could work it out probably, sure. I could work it out. But that's work. It's not fit my brain Django, as a mature project, isn't already kind of notoriously difficult to contribute to. And the concern is that we make the on-ramp for new contributors much harder still.
Speaker 3: And for what exactly is the lurking question. Now we could talk about all these things all day. I don't think we're going to come into any re resolution about those because we've been talking about them for years already. I think the back and forth goes around the fundament fundamental issue that Django is dynamic by design. Here's a quote from Django's design philosophies. Django's Django app should use as little code as possible. They should lack boilerplate. Django should take full advantage of Python's dynamic capabilities such as introspection. Django is dynamic to the core. It's how it was built. Trying to weld static typing on top of that is going directly the other way. That's the tension. It seems to me that we can play around the edge it edges, but any effort to retrofit typing into Django is doomed.
Speaker 3: The MyPi docs say this. Python is a highly dynamic language and has extensive metaprogramming capabilities. Many popular libraries use these to create APIs that may be more flexible and or natural for humans but are hard to express using static types. Extending the PEP 484 type system to accommodate all existing dynamic patterns is impractical and often just impossible. Now again here we can talk about examples till we're blue in the face. But I want to give just one example that's bugged me ever since type hints were introduced. It's not even the most complex. I'm a view jockey. I like HTTP. I'm I like I'm about turning requests into responses. I'm a web developer. I have a package called Neapolitan
Speaker 3: that does quick crud views for Django. And here's a simple crud view. You import the crud view and your y your bookmark model there, you declare your subclass and you add that to your URL your URLs file. And you've got endpoints to create, edit, delete bookmarks, and so on. The key point is that with that one line there, that model equals bookmark Crudview knows everything it needs to know to generate the query set, to generate the form, to generate the context for the template, all of it. And what's more As soon as you know how PradView works, you, the developer, know that too. But what's really frustrating is that static type checkers can't use this information. What's called type inference totally fails in this case There are tools that can do this. PyCharm
Speaker 3: has done this for years. It uses a kind of hybrid analysis. You turn on the Django support in PyCharm and it immediately knows its way around your Django project because it knows the Django pattern. I think one of the big steps forward here is the language server protocol, the so-called LSPs, which took away the hard part of integrating your tooling with editors. Once upon a time you not only had to do the hard work of the analysis, but you also had to solve per editor how to you how to integrate it. With LSP in place there are now I think Three language server projects just in the Django community, adding dynamic introspection for templates, models, settings, and so on. So The the analysis here is not an insurmountable problem. But if we want to do this purely statically, we have to make CRUDView generic over the model class, whatever that means.
Speaker 3: We have to write something like this. Now here the extra bookmark in the square brackets there is t t is to tell the type checker which model class should be used for the various query set form template methods on the superclass. Now, you already know I'm cross about this, right? The extra bookmark is uh it's ugh. Okay, the syntax is a ba bit weird, I think. But well maybe if I could move the bookmark up up there to the top and get rid of the model line. Well that would be okay. But I can't. One of them is for the type checker and the other is for the runtime. If I don't set the explicit model there the the the explicit model value there, it won't be there when I need it.
Speaker 3: Well, okay, so we've got some extra noise. Well maybe we get at least we get type saf safety, right? Well not really. Say not me. Obviously I wouldn't do this. But let's say my L I L LLM writes the wrong thing there for the model. Say it does this and it puts comment in. puts comment in instead of bookmark. The type checker's gonna catch that, right? Well no, it's not. If I actually want the type checker to catch that, I have to write an extra bookmark I have to put in the extra one there to say that the modeled attribute is of the type bookmark. Now, okay, the type checker will now complain if you put the wrong model in, but it's basically right bookmarks so many times that you couldn't possibly get it wrong Which is exactly a joke we used to make about Java. Now I can make this type safe, right?
Speaker 3: Instead if we don't do the model thing, if we declare an abstract get model method on the superclass, well then I could implement that in the subclass and we would get proper type safety here. The return type would be validated against the generic parameter on the on the superclass. Wow, okay. This is the kind of thing you'd do in Rust. You'd implement the has model trait for bookmark Crowdview. But if we were doing this in Rust, We'd have a thing called actual type safety enforced by the compiler. And we'd have none of the performance penalties that Python has to play because it is a dynamic language and it has to validate references before it uses them. As it is, we get none of that, and it's a long way from where we started. I come back to that MyPy quote. Python is a highly dynamic language and has extensive metaprogramming capabilities.
Speaker 3: Many popular libraries use these to create APIs that may be more flexible and or natural for humans but are hard to express using static types. Well exactly My take here is that Django's dynamic nature isn't something that we should try to avoid. It gives us powerful, graceful, expressive APIs, and we can live with that, no problem. I think the same applies to Python more generally. If we try to forgo Python's dynamic nature, we're leaving on power on the tape power on the table. Power that we need. Like really, what else has Python got if you throw all that away? That is our dynamic C. It's the living foundation that we begin with. The question then is well okay if we accept that for us here, if we accept Django as it is, how do we build on top of that when we want more rigor?
Speaker 3: Well that's part two, static islands. Now, you might have the impression that I'm anti-static typing. I'm not. Where it fits naturally, I think static typing is great. I'm perfectly happy to have all the benefits My point was just that we shouldn't eschew dynamic code and we shouldn't try to shoehorn it into a static mould where it's never going to fit. To wit, I want to show you how I deal with this in my projects. Instead of fighting Django, I go with the grain. I build on top of it. The bottom line is that modern Python code starts as type safe by default. And if we can draw a nice boundary between our application code and then the underlying Django, we can easily flow our type safety out from there
Speaker 3: So I want to introduce you to my project Django Mantle. Mantle allows you to move your business logic to type safe Python classes that are decoupled from the Django RM. It provides automatic query generation with declarative overrides of efficient ORM queries including limited field fetches using only and defer and pre-fetching related objects avoiding N plus one query problems. That's a big mouthful, isn't it? It uses a model and performant approach to serialization and validation, and it provides a progressive API with a minimal surface area by default and depth when needed. It's your type-safe layer around Django's liquid core. So let me show it to you. We start with a standard Django model for a bookmark. It's got a URL, a title, a note field, whether it's a favorite or not, and a foreign key to our user model for the parent user
Speaker 3: As a domain-specific language, a DSL for describing our database, the Django ORM is superb. There'll be purists out there who'll say, oh, we should never use an ORM, but Django's history speaks for itself. Millions of applications written at every scale say otherwise. Django's design philosophies recommend models follow what's called the active record pattern. The model encapsulates access to a single row in the database. And we add our domain logic on top of that in custom methods and properties. Model managers act as a table data gateway for table level logic, and together with custom query sets and lookups, they enable a rich and expressive domain-specific API for probably the vast majority of applications. When folks say they love why they love Django, it's this aspect of the ORM that they're talking about.
Speaker 3: Our problem is that our model is it kind of starts to grow A single method or property on the model, well that's wonderful. A couple of them, that's still great. Even a few, no problem. But as our application grows, we reach a point where it starts to get too much. We've just got an awful lot going on in our model A simple bookmark it grows a s a dunder string implementation so that it's output nicely. Then you add some helpers, related bookmarks, get summary, etc. Methods for common queries, properties for template convenience, a list display, a detail display, a preview. And so on. I'm not going to show those methods, right? But I want you to imagine it. You've all seen it in your own projects, in your own models. Beyond everything else, it's probably this tendency for models to grow arbitrarily long. from overlapping logic, from competing concerns, that gives complaints from folks who aren't fans of the Django
Speaker 3: RM the most teeth. Complexity management is the eternal challenge, right? And that's regardless of your framework. But this kind of growth model growth, these fat models that get too big, that's how and where complexity shows its face in Django most commonly. You're all familiar with this, right? While we've got the model on screen and we're thinking about problems, I just want to raise two related points about the RM that draw criticism. Firstly, The default unrestricted nature of field fetches when querying. Say I get a bit a query for a bookmark. The ORM will fetch the data for every field of the bookmark model, regardless of whether I use it or not. The generated SQL will look something like this. The dot dot dot there is for the inner join the ORM lab are filtered by the related username. There's no problem with that The point is that for a list
Speaker 3: view say I only want the ID to generate the URL, the title, whether it's a favorite or not for the preview. The other fields in this case are just dead weight. You could imagine that the note field there is quite heavyweight. But that it's fetched from the database, sent over the wire, loaded into memory, and then put possibly done that numerous times if you're iterating over a list. Well that's just and then it's just thrown away. Well that's overhead we could do without The ORM lets you control this behavior using only and defer, but those methods are not always used and they can be fragile and difficult to use correctly even when they are. The other problem is about lazy related foot um lookups. If I have my bookmark there, I can easily I can straightforwardly access the related user just by the attribute access. This causes the ORM to fetch the related user data
Speaker 3: Right again we fetched all these fields when I might say only be interested in say the username. It's the same problem again. But as convenient as it is to just access the user with the la the lazy lookup That you can trigger an SQL query from a mere attribute access makes it hard to control when you're hitting the database, which is the most performance-sensitive part of pretty much any web application. Right? So in the list view, we'll often iterate over our bookmarks with the equivalent of something like this, right? Be it in a template generating HTML or a form generating model choices or wherever. This kind of structure means we make one query for our bookmarks. followed by one extra query per bookmark for the related user. This is the so-called N plus one query problem. And avoiding it is Django Optimization 101.
Speaker 3: But the ORM's the ORM's lazy related fetches make it an easy problem to fall into. Now again the ORM gives us tools to deal with this and select and prefetch related. And from Django 6. 1, query sets will be able to specify a fetch mode to automatically fetch all peers when a related field is accessed But these tools are still opt-in. They require careful use and can be fiddly to keep updated as our models evolve. Now I'm largely assuming that this is kind of familiar ground to you We've got a model that's growing more logic than we feel comfortable. Well that's the main problem. And then we've got these default performance-sensitive behaviours of the ORM that can be awkward to deal with and can and do trip us up as we go What we want
Speaker 3: is a separate class with no more than the exact data it needs for the task it has to deal with. So this is just an attaz class. Plain Python, fully typed, no Django in sight. Your type checker already understands it without any plugins or stubs. This is our static island. Again, I'm not going to show them, but this is where we add the our domain logic. Instead of putting it on the model, we could put it in our Atlas class And in this case, just the modic related to the list view, not all of it. Our Atters class defines the shape of our target data. Now we need to bridge from the ORM to that shape, and that's what Mantle's query layer does It looks like this. We instantiate a query object with a Django query set and the atta shape that we want our data mapped to, and then we can what we fetch is a fully typed list of data that's fully populated as soon as we fetch it.
Speaker 3: Same again if we want to fetch just one instance. I can get use get instead of all there. In each case, the generated ORM query selects only and exactly the fields that are required by the bookmark data class and no more. So there are no unrelated fetches of all the fields regardless of whether they're used or not. The same applies to nested data. Here we want to add the username for our related user. So we define a nested user data shape and we add that to our bookmark data. Then when we query for the data, the user dot username is populated as we need. And the generated ORM query automatically prefetches the related data. So there's the minimum number of lookups. Even if we're iterating over a list of objects, there are no lazy related objects, object fetches, and so no M plus one
Speaker 3: query problems. Let me show you one more example. Under the hood, Mantle uses a library called Django Readers for interacting with the ORM. Even if you think Mantle's mad, I recommend checking out Django Readers. It's really worth your time. It's just lovely. In order to do its work, Readers uses what's what it calls a spec, which is a list of two tuples where you where you give it what you need to prepare the query set, include a field say, and how you fetch the value from the return data, like get the attribute In the simplest case where you just want to include a field and select its value, you can use the field name instead of the two tuple. What Mantle does is generate a reader spec from your Atter's class Prepare the query set, get the data from which read from which from readers is an untyped dictionary, and then map it back to Atter's instances using catters.
Speaker 3: The example here shows customizing the reader's spec generation. It mantles progressive API. In simple cases you don't need it, but it opens up if you do. Say we don't want nested query data, but instead want to bring the username up onto our bookmark data. Username there, string We can provide an override to the spec generation that says annotate the query set with the username value and then select that to include in our return data. Then if we fetch our data again, you can see that the username is available directly as a top-level attribute. Now there's lots you can do with overrides. The mantle docs have a whole section on customizing query gen query generation, but annotation like this is kind of 90% use case. Let me just show you about rights
Speaker 3: with validation. If we have incoming data, along the principle of pass don't validate, we structure that into atters classes using catters. Now that tells us that our data has the right shape, the right fields, the right data types, and so on. But we might need an extra layer of domain validation on top of that. Rules that go beyond what's purely internal to the data. In Django, it's common to have unique or unique together constraints for some field or other. So here we define a bookmark validator that ensures that the URL field for our bookmark is complete. Now the the unique field validator would have worked by itself there, but compose validators let you get lets you track chain validations. So I wanted to show you that. With the validator in place, we can use our bookmark data that's coming in as
Speaker 3: an Atis class and to create new Django bookmark instances checking the URL. uniqueness constraint beforehand. In your view code you catch an error there and report that back to the user. Same with updates. We realize that we should have made the mantle docs a favorite. We want to be able to find those quickly. So we take our existing instance and update it accordingly. It works exactly how you think it should. Finally then, I just want to show you that if you That if you're using Django Rest framework, there's an integration there available with um vi via mantle DRF. Mantle DRF provides versions of Django's generic views, mix-ins and viewsets, replacing DRF serializers with the Mantle Shape Flow that we've talked about. So let's hit let's show you an example.
Speaker 3: Here we define a bookmark detail, which is a retrieve API view which we've imported from Mantle DRF generics instead of from REST framework generics. We define our shape class, the bookmark shape there, and we're done. You'll see that we have the extend schema decorator from J DRF Spectacular there because we have open API schema generation via DRF Spectacular. The screenshot there is just rend the rendered swagger docs from um our bookmarks API. Mantle DRF means that you can begin working with mantling your existing DRF application now. So a quick aside, well, is is Mantle Django's supposedly missing REST story then? Well, it's my take on a good chunk of it Mantle gives us a modern performant ORM aware serialization story.
Speaker 3: And that's the hardest part. The view layer, rate limiting, permissions, auth, well, DRS versions are perfectly serviceable there. They may be a little old, but they're not unfit for purpose by any means. If we want to evolve them now with a new serialization story in play, well we can. And I think historically, in contrast, without an ORM-aware serialization story to tell, it's been hard to see a clear way forward. Anyway, that's my hope. So static or dynamic? Well it's a trick question. The answer is obviously both. The question is not which to be used, but how do we combine them. We keep the ORM, we keep Django's dynamic power, and we build our domain layer on top with simple typed Python classes. Mantle's query layer bridges from the ORM to your data shapes in an efficient and scalable way.
Speaker 3: It's a deliberate but small separation. We keep everything from Django, we just build on top of that. Static islands on a dynamic sea. I'm having great fun with Mantle. I d ask you to do go check it out and let me know what you think. I'm here for the rest of the conference and the first day of the sprints. And if you wanted to give Mantle a run while you were here, we could talk about it And that would be great. I'm keen to see what you run into. Thank you.
Speaker 2: Thank you, Carton. I'm not sure how about you, but I have plenty of questions. And we have plenty of time for questions. So are there any questions from the audience?
Speaker 4: Uh can you please contrast uh this uh framework or like mantle thing with Pydentic?
Speaker 3: Okay, Pydentic, good. Uh yeah Can I get out the room alive? Um how did we get here? We got here because we had a map a big bookmark model and it was growing logic and growing more logic and growing more logic and growing more logic and what we've done is we've coupled two very significant domains. Our application logic, which is complex And the mapping to the ORM, which is complex, or to the database, which is complex too. That coupling is for many people Django's original synth. Like the the architecture purists. Why don't they like Django? They don't like it because of that. So we want to tease those apart. Now with Pydantic, it wants to be your domain object, it also wants to be your serialization, it also wants to be your validation layer.
Speaker 3: So from the perspective of where we've come from, Pydantic is just Doing the same thing Django did. We don't want to, we don't want to separate our concerns only to couple them back together. Now Pyden for just as the ORM is a fantastic solution for you know, it gets you an awful long way. Well so so does Pydantic as well. But at this point in the the evolution of our app, as our app grows, we want pure Python classes with serialization and validation as separate concerns rather than uncoupled. Does that does that address your question? Okay. Uh
Speaker 5: does this unlock anything interesting in terms of forms?
Speaker 3: Forms.
Speaker 5: Uh Django forms, yeah.
Speaker 3: Yeah, okay. So um Hi Balder. Yes, not currently, because I haven't built it yet, but the the idea would be to um just as we have model forms, have a mantle form. And what do Django forms do? Django forms have two roles. One is data validation, the second is HTML rendering. So a mantle form would work where when you get clean data, you get an At as instance. out instead of an untyped dictionary um for instance um and then the the form generation would we would generate a standard Django form in order to take the rendering side because we don't want to duplicate that that's there's There's so much going on there that's wonderful. But then on the when you take the data in, you you get your your your post data, say, you run it via
Speaker 3: CATAS into an Atters class, which gives you that that kind of structural validation and then the the additional validation you might add for you know uh you want an int but it has to be greater than 18. Well that's that's not structural you that's not a pass don't validate approach that's a a validation step on top of it But that doesn't quite exist, but definitely on the right mark.
Speaker 2: Yeah, another question from the top.
Speaker 6: Uh which type checker do you recommend to use with Mantel or it works great with all?
Speaker 3: Personally I use MyPy. I don't I've got no problem with the other type checkers, but maipy is the is is the sort of community one.
Speaker 6: But it's a bit slow.
Speaker 3: Speed's overrated.
Speaker 2: And other questions from the audience?
Speaker 7: Uh do you have any recommendations on how to do that? depart those into Django Mantle if we already have an existing Django project which might already suffer from the problems that you highlighted.
Speaker 3: Yeah so it's Mantle exists because I have my own projects and they they have their own problems. And it's I would suggest pip install mantle and then begin with a single view. A single read-only view, you know, if you're using DRF, a single retrieve endpoint. Define the shape you want, use the get used to the query thrive, see how it works. Just start small. And say you've got one big monster model and you're like, do you know what? I really like to remove these methods, which are all about how this is displayed in the template. Well, create your Atis class. Move that logic to the Atis class and pass that Atis class to your template. And then you can delete those methods from your model and all of a sudden your model is cleaner.
Speaker 3: And its fundamental role of map of controlling the mapping down to the database table becomes clearer because you've removed that noise from around you. it. So it's designed to be introduced incrementally. It's low risk. It's not like you know you have to throw everything out and adopt mantle as your new thing. No, you can mantle on one view. Oh I like this, two views, etc.
Speaker 8: Yeah. Um I've heard so many talks about the tensions that you've talked about, the tension between keeping things decoupled and then wanting to couple them back together or between um Python as a language that can fit your brain because it's so small and simple and a model description that's completely clean and contains nothing that the human doesn't want to see and then the tension between that and wanting to add all that machine readable information that will be useful And are we trying to be too many? Yeah, are we trying to be both this and that when it's impossible in Is this where the tensions are coming from, or does every programming language and culture have the same thing?
Speaker 3: Ugh, good question. Um we're in the home of philosophy, so uh It's the for me these questions are what programming is is really about. It's the the the the challenge of maintaining your application. Start small, all bang it in one file. You know, we've all written a hundred line Python script and it doesn't need to be any more sophisticated. than the horrible thing it is. But as your your application grows, you need more rigor, you you you the the number of things that are happening on your application become so much that you have to to separate them because other you you know you over overwhelm the capacity of the human mind to reason about the a cer
Speaker 3: a fixed number of things at a time Yes, it's the it's the problem of programming. So every programming language has it there is no golden solution here um you there's a a happy path a via media um that you can tr you can walk between not enough engineering and and over engineering. And either one of those you make your job harder than it needs to be at the scale of your application it is. Now that's not a fit, you know, who knows what the shape of that path takes for your your given application. But the challenge that we face as professional programmers and why I don't think I'm worried about my job for the, you know. our new machine overlords
Speaker 3: is that it's a question of taste and how you walk that path. Does that answer your question, Daniel? It it talks towards it, but I don't think it really Let's start from uh okay.
Speaker 8: Thank you. Um I really, really like the idea of mental Uh my only concern is that in my experience the a lot of bugs pop up when you're crossing uh the border between two uh systems. So if I define my data class and it sort of mer uh changes uh or mutates away from the model definition Would mental be able to detect that and give me like a type error or not?
Speaker 3: So what's so nice about um so it's two there's two aspects that um Uh the generated Django reader spec or you can manually provide it if you want to. That that handles the s actu the data that you end up pulling from the model. And if there's so if there's some model error there, it you'll get an error from the ORM because some field that you tried to ask didn't exist, that kind of thing. What's really nice about the structure, so Django Readers gives you an untyped dictionary. And if you get some kind of drift there, You you're only going to spot it at the end as you use that. What's really nice about forcing it into the typed structure of the of the Atis class, the data class that you're using, is that the structuring process will tell you when you you w if that data changed and you get the error straight away.
Speaker 3: Yes, there's problems with map The the mapping is always difficult, always, you know, you're gonna have to adjust it. What's nice though is that you can define like a tight shape just for the one particular role. And then you define another one for a different role and another one for a different role. So you end up instead of having sort of one to one and this one thing doing everything, you have one to n where each N is only doing a smaller task so it becomes easier to reason about it comes easier to test it becomes you know um more coherent I think is the fancy word we like to use
Speaker 8: Hello, thank you for your uh for your speech.
Speaker 3: Where are you?
Speaker 8: I'm here.
Speaker 3: Okay, hi yeah.
Speaker 8: I I just uh uh hijacked the mic, apparently. Uh so in order to To solve Python's issue and not look like Java in the process. How does Mantle manage to fix the performance issues that you describe that pure vanilla Django M DRF on that matter has? Because At least I failed to to get the part where you don't need the fetch related or
Speaker 3: Okay, so the um The underlying library there is um called Django Readers. And it's f I've said it in the talk, I'll say it again, it's a wonderful library um by uh Jamie Matthews, who's um the uh CTO at um dab apps they were the um uh they were the agency which DRF originally came out for out of is a very experienced developer um and Django Readers is very robust. It fixes the problems with the um R the two problems with the RM. One was unrestricted fields fetches and the other was um uh lazy related object fetches. It fixes them in two ways. One by forcing you to specify the exact fields you want. So that's they come from the Atis class, they come from the fields you want, and Mantle generates the reader's spectrum those.
Speaker 3: So you so you you fix one problem by um it you by basically saying I want this field, field A, field B, field C, and no other fields every single time you're querying. The second one is that readers will automatically generate the prefetch related calls that you need so that even if you've got a deeply nested one, you know, you've got a project with some steps with each with some you know sub steps and each of those has got some sub you fetch all of that and you're still only getting at most one query per model um down the tree um which is about as efficient as it's reasonable to be Um
Speaker 8: I guess your database administrator will be happy because
Speaker 6: you can basically reduce the number of unique queries you have uh given that you have no um yeah queries over all the views but uh constrained to your shapes. Um how many shapes for uh a single model do you usually have? to cover like list and detail views because the fields are not um
Speaker 8: mappable one to one in most cases.
Speaker 3: Yeah no so I I would define a a a different shape per use. Um and the art the the the the point about them being lightweight at as classes is that there's there's very little to it. It's just it's It just defining defining the the um the data you need and then you bolt on the one or two extra helpers that you need. But define as a matter of policy, define a different shape per use case. But the historically DRF, right? Reusing serializers are they're heavy and hard to write, so we reuse them and then the serializers start becoming difficult to maintain. It's the same you sh we should have always been creating different serializers. Well we create different shapes to keep our logic clean and our logic separated. So n is as many n's as you need.
Speaker 3: Two, three, four, five, six, no problem. Hi up here. Sorry, I can't see you anyway Doesn't matter. Hello.
Speaker 1: Yeah, yeah, I see you. I got a question about the stability in your opinion, because I looked on the PyPy uh at the Django. mental and it doesn't say anything about stability. Would you recommend it for production?
Speaker 3: I I've been using it in production for several years and yes. Um Yeah, I mean, you know, um it uses a form of Calver because um I don't like to lie in my version numbers um and pretend that if I'm making some promise I'm not The core query flow from um the Atter class into the reader spec, um it to the database. Uh um back into the um at a class fives catters all of that's working and stable and that's the core of it. The new features will be added, um but what would I say?
Speaker 2: You don't need to convince me, I need to convince other people.
Speaker 3: Yeah, no, sure. Um I can't make any promises beyond guarantees. I don't intend to make breaking changes arbitrarily if that's But beyond that I can't, you know, what else can I say? It's it's uh a newer project, sure, so it's by its nature less um stable than say an existing project like DRF. DRF is feature complete and stable, but because of that it's decaying, right? There's a trade-off between the older very stable thing and the the newer, well potentially more or less stable thing.
Speaker 3: Nothing that a requirements. txt file pen can't fix, I would suggest.
Speaker 4: Thank you.
Speaker 2: Okay, I think we have time for two more questions.
Speaker 7: Thank you. And the um desynchronization that could happen. also exist with mantle between the model definition and the data class definition. Do you see a path where we don't need to repeat the type as much in
Speaker 3: Repetition by itself, good question. Repetition by itself is not a problem. Don't when we talk about dry, right? Dry, you mustn't re people take that to be a a religion almost. And don't duplicate logic where the same thing is happening. Well you don't I've got it in two places and every time I have to edit one I have to edit the set the second. The thing with separate concerns is that they're separate. And dry applies within a concern, not across concerns. Because as soon as you start drying between concerns, you then couple them, which means that you they become difficult to edit and they become difficult to allow
Speaker 3: to evolve as your application grows. So absolutely repeat yourself if you've got concern A, which is logically separate from concern. concern be. It's about cohesion. Don't couple those two different things by fear of repetition. I think it's a perfectly natural part of programming. It's a perfectly natural part of writing maintainable software is to keep Keep our features atomic. This feature array has everything it needs there in front of you that you can work on. Feature B also has everything it needs and yes we oh look we use the favorite field in both of those so shouldn't we have its parent shape that which we then subclut No don't do that that's a mistake
Speaker 3: Yeah.
Speaker 2: The last question
Speaker 8: Hi. Um I want to ask whether this can be used with the Django Ninja framework and if so, whether it's recommended.
Speaker 3: I don't think Django Ninja recommends Mantle. Because so Ninja 's view. Right, so okay. Good question. There are various tasks that need to be solved by an API framework. Serialization is one of them. Ninja's solution there is to use Pydantic. Okay, um the map the mantle built on Atters and CATAS flow is a separate approach to that and I explained kind of why I I favor that one of the earlier questions Then there's the views that wrap it. And what does a view do? Well it takes the the request and it turns it into a response. Well the first thing it's gonna do is serialize or deserialize the um structure the re
Speaker 3: the incoming um request body say Could you take out, I don't know if you could, but in theory, could you take out um Pydantic and plug in Mantlin to Django Ninja's views? Uh yeah, why not? Why not? Would you do that? I don't know. Would you just rewrite some views? We had um Adrian Holivati on Django chat and we were talking about um rest framework and why why Django doesn't have its own built-in API story. And Adrian was like, well there's no there there. There's nothing to it. Like beyond the serialization story, which is kind of difficult. The view bit is well Serialize the incoming data, deserialize the incoming data, do whatever processing you need to do, and then serialize the response with the right content type. There's your web framework, there's your API framework.
Speaker 3: Could you, I don't know about the actual surgery on Dan Django Ninja, I don't use it. So but yeah, in theory, why not? Wait,
April 15 - 17, 2026
Athens, Greece
Note: We understand that names change, people change, and bodies change. We respect each individual's journey and privacy. If you have any concerns about a video or need us to remove content, please don't hesitate to contact us. We will handle your request with care and promptly address any issues.
Published October 26, 2026
Published October 26, 2026
Published October 26, 2026
Published October 26, 2026
Published October 26, 2026
Published October 26, 2026