basic metaclass perhaps the simplest metaclass you can code is simply subclass of type with __new__ method that creates the class object by running the default version in type metaclass __new__ like this is run by the __call__ method inherited from typeit typically performs whatever customization is required and calls the type superclass' __new__ method to create and return the new class objectclass meta(type)def __new__(metaclassnamesupersclassdict)run by inherited type __call__ return type __new__(metaclassnamesupersclassdictthis metaclass doesn' really do anything (we might as well let the default type class create the class)but it demonstrates the way metaclass taps into the metaclass hook to customize--because the metaclass is called at the end of class statementand because the type object' __call__ dispatches to the __new__ and __init__ methodscode we provide in these methods can manage all the classes created from the metaclass here' our example in action againwith prints added to the metaclass and the file at large to trace (againsome filenames are implied by later command-lines in this class metaone(type)def __new__(metaclassnamesupersclassdict)print('in metaone new:'metaclassnamesupersclassdictsep='\ 'return type __new__(metaclassnamesupersclassdictclass eggspass print('making class'class spam(eggsmetaclass=metaone)data def meth(selfarg)return self data arg inherits from eggsinstance of metaone class data attribute class method attribute print('making instance' spam(print('data:' datax meth( )herespam inherits from eggs and is an instance of metaonebut is an instance of and inherits from spam when this code is run with python xnotice how the metaclass is invoked at the end of the class statementbefore we ever make an instance--metaclasses are for processing classesand classes are for processing normal instancesc:\codepy - metaclass py making class in metaone newcoding metaclasses