What are metaclasses? What are they used for?
A class, in Python, is an object, and just like any other object, it is an instance of "something". This "something" is what is termed as a Metaclass. This metaclass is a special type of class that creates other class's objects. Hence, metaclass is responsible for making new classes. This allows the programmer to customize the way classes are generated.
To create a metaclass, overriding of new() and init() methods is usually done. new() can be overridden to change the way objects are created, while init() can be overridden to change the way of initializing the object. Metaclass can be created by a number of ways. One of the ways is to use type() function. type() function, when called with 3 parameters, creates a metaclass. The parameters are :-

Class Name
Tuple having base classes inherited by class
A dictionary having all class methods and class variables

Another way of creating a metaclass comprises of 'metaclass' keyword. Define the metaclass as a simple class. In the parameters of inherited class, pass metaclass=metaclass_name
Metaclass can be specifically used in the following situations :-

when a particular effect has to be applied to all the subclasses
Automatic change of class (on creation) is required
By API developers
What are metaclasses in Python?