Functions are fundamental to python, and are amongst the first features of python that most users learn. We call a function with arguments, and it returns a value. However, there is more to this callable interface than meets the eye, and there are lots of useful and powerful (and cool!) things we can do with the callable interface. You may have come across many of these already: (anonymous) lambda functions, the __call__ magic method, the decorator pattern, the __doc__ property, and modules like functools and inspect which provide detailed about functions and allow us to alter functions at runtime. Lots of libraries, particularly web frameworks like Flask, Django, and FastAPI, and testing toolkits like pytest, use this callable interface to implement their API, and as developers, understanding these advanced features of python’s callable interface is particularly useful when writing generic, automation focused code. This talk gives a deep-dive into python functions, and the associated callable interface. We’ll start with quick tour of the basics, before covering python’s more advanced callable features. Finally, using an example – automatically generating FastAPI endpoints for dataclasses and SQLAlchemy models – we’ll see how and why we might want to use them.
About Dom Weldon
“Dom Weldon is a Principal Software Engineer at Decision Lab, a London-based mathematical modelling consultancy with expertise in machine learning, simulation, optimization and visualization. Dom’s team specialize in taking models from data scientists and turning them into production ready tools. Recent clients include the Royal Navy, Siemens, and the UK Space Agency.
Dom came to Decision Lab from his PhD studies in Computational Geography at King’s College London. His initial degree was in Natural Sciences at the University of Cambridge, and holds a master’s in the historical and cultural geography of the Cold War United States. Outside of work, Dom is interested in languages and travelling, and holds a voluntary statutory appointment on a board monitoring the welfare and dignity of prisoners in a challenging North London jail.”