Using Python decorators to process and authorize requests

When building any system that interacts with users you always need to check that they are who they are claiming to be and whether they are allowed to do what they are trying to do. In other words, you need to authenticate and authorize users. Chatbots are no exception. Strictly speaking, with chatbots you do not need to authenticate users yourself – the platform does it for you. However, on each request you still have to load the user model and authorize it....

2021-12-06 · 5 min

defaultdict: a hidden gem of Python standard library

Often you need to store data (counters, sums, lists, etc.) about some entities. A regular Python dictionary will suffice with one caveat: before adding information regarding a particular entity you need to check if the corresponding key exists in the dictionary, otherwise you will get a KeyError. Do not know about you, but I have written similar code many times: dct = {} if key not in dct: dct['key'] = 0 dct['key'] += 1 A better way While it is perfectly workable, it does not add to readability....

2021-10-25 · 2 min