The singleton pattern refers to a class that you can only initiate once. If you try to create a second object of a singleton class, it will just return the already initiated object
Let's analyze the code a little step by step
_instances = {}
This is a dictionary where we save the objects we have already created. An important thing to understand here is that this is shared among the objects. When you create a new object you always get the same dictionary.
if class_ not in class_._instances:
class_._instances[class_] = super(Singleton, class_).__new__(class_, *args, **kwargs)
Now as I mentioned before, singleton creates an object once and it returns it again if you try to create a new object. This code here checks if we have already created the object by looking inside of the dictionary. If we haven't created it it will create a new object and it will save it to the _instances dictionary. If it already exists it will just skip this code.
return class_._instances[class_]
We then return the object that it is guaranteed to be there. Remember that we have already checked that we haven't created an instance of this class so we can create a new one. If it was already created, we just return it from the dictionary.