Hidden gems of Django Admin with Maxim Danilov
Published November 2, 2022
This video features Maxim Danilov at DjangoCon Europe 2025 in Dublin, Ireland.
Talk: One more time about µDjango. The next step in the evolution of asynchronous microservices technology by Maxim Danilov
https://pretalx.evolutio.pt/
Maxim Danilov presents “micro-Django,” a way to build Django services with the framework’s full functionality in a single Python file, without a separate settings module, and run them standalone, in Docker, or as parts of a modular monolith. He shows examples using views, the admin, serializers, testing, and asynchronous endpoints, while explaining the need for lazy initialization and the remaining limitations of Django’s async support. He argues that micro-Django is useful for extracting stable entry points from large Django monoliths without switching frameworks or refactoring the existing codebase, especially when teams benefit from keeping a unified Django stack.
Summarised automatically from the transcript.
Micro Django is a way to put a complete Django application in a single Python file, including its settings, views, URL dispatcher, and runnable server entry point. The resulting service can run standalone, as part of a monolith, and be tested.
Discussed at 1:32Set `DJANGO_SETTINGS_MODULE` to the single Python file, then run it with Uvicorn using the appropriate application path and flags. The same file can serve as the Django settings module and async application entry point.
Discussed at 2:18It is useful for extracting small, stable entry points from a large Django monolith, for modular monoliths, and for async-oriented Django services. It lets teams keep Django consistency while running individual services or endpoints independently.
Discussed at 8:26Async views work, but Django 5.2 still has synchronous class-based-view and database-related limitations. You may need to override methods such as `get_object` and explicitly await async operations; related-object serialization is still restricted.
Discussed at 13:00Put the settings elsewhere, configure `DJANGO_SETTINGS_MODULE` to point to them, and add their location to `PYTHONPATH`. The project directory can then contain just the Micro Django entry-point file.
Discussed at 18:19For a team already using Django, keeping the extracted endpoint in Django avoids adding another framework and reduces the complexity and learning burden for developers. The main benefit is a unified codebase and programming model.
Discussed at 26:22The extracted entry point normally uses existing, already-imported models and is not responsible for migrations or schema changes. Its job is to perform a small computation without modifying the models or database schema.
Discussed at 27:30Automatically transcribed, so expect mistakes in names and technical terms.
Maxim Danilov
Yeah, I'm happy to be here and I want to present my talk, MicroJenga. And before I start, I want to say a special thank for my family for sabbat thanks to my wife Elena thanks to my children Mark and Paia thanks to my animals Marcel and Kisa And special thanks for my children, Mark and Maya, because they create full illustration for all my presentation in last two years. Okay, thank you, Mark and Maya.
And short information about me. Who I am, my name is Maxim Danilov, and I am Python and Django developer many years and I love reactive front end frameworks and also last only in last year I provided around six thousand five hundred minutes like a mentor for newbie developers, Python developers for free. It's around 25 minutes in a day without a break Don't forget empty slots are available. You can ask mentor again. Okay But what is microjango?
The important idea. Important idea about microjango is we have project with single PI file. And we have full Django functionality and it's runnable standalone, it's runnable in monolith, and it's testable. How it possible? This is an example from mine PI. You can see there is we have import. We have declared we have declared view and we have declared oral dispatcher. That's all. How to run it We can use Ubicorn.
We need to set up properly the environment settings and At first, don't forget to have settings. There, Django settings module should be finded. And this Jenga settings module is the same file, mine PI It means I don't have any settings PI. And after that you can run it with Ubicorn with special with special flags and of course you can run it if it async with multiple workers and you get the async single file
Jenga endpoint. That's all. You can see how it works and it works normally And this is already normal st style or normal standard To write teeny small entry points which build it on Django. And if I start to compare, there is with famous different other Python. Web frameworks of course we can compare it for example micro Django put it in container In Docker
, the image of Docker takes around 50 megabyte and in code it's written five lines of code. For example, for FastAPI, example Hello World, it takes 75 megabytes in Docker container and it takes our also five lines of code. This is about the repository or storage, and this is about the code lines, quantity of code lines. But what about performance? In this case about code lines we have inputs We have also the
view declaration and we have also the Ural dispatcher declaration. And what is about performance? I compare Django and different other Frameworks like a lightestar or robin Python frameworks which written on Rust And on the other live session, I compare micro-jungo paradigm with FastAPI. You can find it in the internet and I can say it's comparable. But don't believe me, check yourself. And history about micro Django. This is important. The birth of this technology happens in 2000
2014. And important is this technology was completely clear described in 2014 with in the book Lightweight Django. And this style, coding style with Django framework, takes a name lightweight Django. After I met this technology in 2015, because I came to project which builded on this technology. Autors of this project was Armin Wolf and Fro Florian Ernser and they start to work with standard dzanger project
and after that they have they have simplified the structure of this project A little bit later I meet this technology in different benchmarks, for example in benchmark from Kirill Klonov there it was the idea lightweight Django plus Sitapi. And of course a little bit later this idea takes the second birth Vincent presented it in twenty nineteen after it was created the repository and name transformed in Django MicroFramework. But idea was the same refreshing of light data Django
ideas. And the Last important step which happens with this technology in 2023 Paolo Melchiora presented a sync form of lightweight Django and Paolo also mm offer the new name for this technology Micro Django. I like this name and that's why I use this way this name. Altruff, the normal is lightweight Django, already eleven years. You can meet also other names in the internet. It can be Teeny Django and a lightweight Django project. Or you can see the nano Django, probably you have hear it. It's all
about the same Okay. MicroJenga in real life. I use Micro Django already two and a half years, also in grow big project sorry I live in Austria and I use sometimes dn German words I hope you understand me and the where we can use this technology. This example on the right side, you can imagine this is one huge messy Monolith from Django. Each can this contains around three hundred forty thousand lines of code. And it's really
heavy to start to test and it was a problem. It this is example This is an example from medical observation data lake. And it was a problem we should make these projects more stable. And with lightweight Django sorry with micro Django we have we start to extract some small entry points in separate containers and run it to achieve stability exactly for these entry points This is medical observation. We should, for example, store information from heart frequency sta it should be stable, it should
be achievable, and that's why We want somehow to extract entry points and make a guarantee this entry point what works every time. And this is segregated entry points as QRS -based project. Also, in modular monolith, you can use micro-Django technology. Please refer in internet the architecture pattern project pattern modular monolith. I like this idea. It's it was bunch of articles in twenty nineteen probably. And also
you can use it in async oriented Django projects. But you can remember I say we have full Django functionality. How it works It's really easy. Pretty easy. We this is a simple one PI file to run admin site from project. And you can see I declare VSGI handler, but it's wrapped in lambda because I want to made it lazy. And at the second I define URL patterns and again
I made it lazy. Simple lazy object. This is the hand helper Which created in Django and help us to work with objects which will be initiated later not on start of project. And execute from command line as a standard command, it means you can simply run as usual Python mine PI run server. It works. Try it yourself. All examples you can find on the end of my talk. And the next example. Standard model data series serialization sync. You can see I like to work with
generic class-based views. I define the view based on the detailed view modul again wrapped in LaZerobject because we don't have models on start of server. They are registered later And in response simply I use to render in response I use standard Django serializer Django serializer framework. It's amazing powerful library which nobody uses, especially in projects which I have seen. And I declare URL
patterns and it works somehow. You can see the Django serializer framework placed in Django core serializers. Okay And how it works? If you run it on server, I can roll back rollback. I run it on server and we get the serialized object from model users. Only one file, not more. Also, I can offer you async example. The sync example it works and we have a problem. Django 5. 2, it's still not ready
to be a sync. Because I mean not Django but class-based views not ready to be a sync. For every async operation I should overwrite any function in class Piew. For example, standard detail view calls getObject. But getObject call mate hit in database sync hit. In this case I should I instead getObject create the new function r get object and after that I should await the result from a get object and if we I check our results, we can see it also works. I run it with
with Uicorn And if we see we have also our obstacles in Django. If you use related fields If you want to serialize related fields, it's not possible, still possible with a sync It's this is not a problem. You can simply serialize pline objects and usually this is normal solution if you work with reactive frameworks. But If you try to work right now to solve right now some solution on in a sync mode, probably right now in Django five
point two, it's not all possible but possible. Okay testing. With testing it works completely normally for example right now I provide The async test for view, which I presented on slides before, and important is to is for async testing. Don't forget Always you meet somewhere this transformer from sync to async or something back, and this is our legacy. We cannot still na till now we cannot avoid it to transform from sync to a sync easily or seamless.
But it works And right now some words about settings because settings PI probably it's a file which you meet in every project. Who has projects without any settings PI? I have. But in reality, settings PI is our core file, it's much more important than any other. And if we speak about settings, we have in reality 50 shadows of settings. Because on debug, in debug production, in debug we work with like a debug settings Probably you
you have somehow local settings there. You have construction. If debug blah came some settings. Who has who has this construction? Yeah, everybody. And after that, probably we have we can have the test stage. And for test stage, probably we have special test settings. And also, if we start to run in production, probably there we have production settings. Who has this difference in settings? Of course. And probably you have also the different test settings. Test settings to work with Amazon, AVS test settings to work with clouds in the same way and so on.
Or with different databases. And don't forget, Django offers us to have settings in completely other place of file system. It's not important to have settings in the same folder or in folder settings, settings, or project name settings, whatever. How it works at first we should at first at first Django offers us to works with different arts how settings can be declared We can use Django settings model like a
like a variable in environment. Also, we can by run server we can provide a settings flag there run server should find the settings and so on. And external settings for single service. For example, how it works at first, you should check properly base dear in settings PI. After that you should set up in environment Django settings module path to settings and the final step you should set the new environment variable or new redefine new and redefine environment variable
python path and you can add path to settings on your system after that you can run standard your developer web server, it works. But settings placed somewhere probably it's also placed somewhere in internet on the other machine. It works. It means settings pry you don't have you can don't have not in project folder and in this case Project folder with Micro Django paradigm contains only one PI file. OK. Micro Jenga: it's amazing because it can work as modular monolith.
If you work with MicroJunger Paradigm, you can create the folder. There you place the first service projekt which can be run at standalone. After that you place the second service folder, which you can run standalone. And after that you have one small micro Django file. Which simply goes through f full folder automatically or right now it's written strict But you can find in the repository I created the auto discovery for every mine PI and in this case the feneral mypi microservice
file simply run any other service in one bunch like a monolith but this is modular monolith It's easy, it's funny, and don't forget to make your functions or attributes lazy. It should be calculated later and not on the import of the file. Okay, how it works with Docker? In Docker it's all fun and easy You can see also in my project I don't have any requirements text or settings PI because all requirements or settings I have in Dockerfile. Dockerfile installs for me all requirements. And it's also
one possibility to reduce loading for developer who works in team and we remove the possibility to use different libraries because Dockerfile usually is provided from central repository, for example. Also, this command it works. Every example which I provide in my talk is works and placed in repository. Link I gave on the last slide, you can check it all and check Max you say true or Max you a liar And also what happens with micro-jungo in 2025?
Because Paolo presented Micro Django in 2023, and what happens in these two years? In this case, I'm really happy to have in Django five point two a meta decorator right now support me to decorate methods in class-based views and these methods can be a sync. Why it's important? Because I don't use middleware settings in settings. I wrap my small teeny services in dec I decorate my small teeny services which based on class with meta decorator But a Django
also provides us a second decorator which calls middleware to decorator. It means I transform any middleware, for example, out of middleware in from middleware a transform decorator and after that with this new function in Django I can decorate only my single view with this middleware. This is important. We can discuss it later. It's a really game changer for async programming with Django. I like it, thank you. And also in only in previous version of ja previous version of Django it was not possible, but we have also
cache decorator which works with async views or with async entry points it's also appears only last year probably it's around And we have also many different async possibilities. It means I can write I can solve more tasks or business goals with async paradigm and improve quantity requests per second. Okay, and if we speak if we summarize this all what I want to say Important is micro Django is only technology to work with Jenga. It means till now I don't install any other additional library.
Also, to get Swagger user interface, I don't install any additional library because I know how it can be solved in a microjanga paradigm. And okay Ubicorn like external web server will be installed. Okay. And yeah, summary, key takeaways about micro-junga technology It's this pattern is already ready to work. Simply take it and use it. And you cannot forget it if you start to use it. This is a problem. And it's comparable with other technologies. In my previous talk I already show how djangforms can validate the
incoming data in the same speed like works paidantik Which written on Rust. I speak about Pydantic version 2. And also Micro Janga, for example, in my personal situation, Micro Django help us to extract the Django and endpoints from Messi Manolith and run it standalone Without any refactoring, without technology switching, this is important for team who support this code base And please don't forget right now in 2025 we are not still possible to solve all tasks with
async programming in Django But right now with last version of Django, it's really a huge part of tasks can be solved in a sync paradigm And you can try it yourself at home. Simply open your love your famous project switch written on Django Find only one small entry point in your project. Extract it in a single file. Write it in micro-Django style. Check imports. Don't forget to check imports. Run and enjoy. It's easy. Thank you.
Speaker 2
So one question from the remote audience. What are the ideal use cases for micro Django and why would you take it instead of flask, for example?
Maxim Danilov
What
Speaker 2
ideal use cases for micro Django and why would you take it instead of flask?
Maxim Danilov
In this case, important pu important idea is if I work with five teams and I have Around four members in every team, and they all work in one paradigm Django in this case to switch for one separate entry point to use Flask there or FASTAPI or Django Ninja or I don't know Lightestar. In this case we increase complexity of project and the problem for newbie developers who came in team It's gross because not everybody knows a whole bunch of technology. In this case,
Unification of code base it's made this code base easy. That's why we use this technology instead of probably any other framework. I hope I answer But we can discuss it.
Speaker 2
How was your experience extracting endpoints in relation to database migrations?
Maxim Danilov
In this case you can see I always use I always use already existed and imported models. In this case my micro-jungo entry point don't have any responsibility to work with migrations Responsibility is only to perform one small computation without relations to changing the models or database schema. I'll truth the you can find the articles how your answer exactly researched Not from me, from other developer.
Speaker 3
How do you feel about the idea mentioned by Mr. Gibson in his talk about modularizing Django itself? How would that affect micro Django as a project? Do you think that then Docker image can be even more smaller and maybe lessons learned from Micro Django can be used as a reference for Django Core if we go that road.
Maxim Danilov
I already think about separating Django project on different modules I also created the additional library which means dependency instructor extractor. It means if my entry point uses some dependencies from Django. I can use this library to extract only single files from Django and run it in Docker container and it works without install Django. It's interesting, but problem from Django itself: they use really often import module. And in this case, your dependency
not writed deklarativ importul imports something frĂĄn string. Somtimes du cannot imagina what should be importer. You should debug place you should be on this line and in this moment you can see which library will be imported right now. And sometimes it's completely not obvious. For example, this problem it's famous, you can see jung jjung can tripod mean sites import lazy the default site but this is a problem because It's imported from import string.
It's not imported normally. I don't know why I know why. But I'm not agree with this idea in codebase And Django itself try to be written modular, but the these imports string imports or lazy imports can break full work. That's all But yeah, the is cool. Thank you.
April 23 - 27, 2025
Dublin, Ireland
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