although metaclasses make it possible to drastically alter the behavior and semantics of user-defined classesyou should probably resist the urge to use metaclasses in way that makes classes work wildly different from what is described in the standard python documentation users will be confused if the classes they must write don' adhere to any of the normal coding rules expected for classes class decorators in the previous sectionit was shown how the process of creating class can be customized by defining metaclass howeversometimes all you want to do is perform some kind of extra processing after class is definedsuch as adding class to registry or database an alternative approach for such problems is to use class decorator class decorator is function that takes class as input and returns class as output for exampleregistry def register(cls)registry[cls _clsid_ _cls return cls in this examplethe register function looks inside class for _clsid_ attribute if foundit' used to add the class to dictionary mapping class identifiers to class objects to use this functionyou can use it as decorator right before the class definition for example@register class foo(object) _clsid_ " - def bar(self)pass herethe use of the decorator syntax is mainly one of convenience an alternative way to accomplish the same thing would have been thisclass foo(object) _clsid_ " - def bar(self)pass register(fooregister the class although it' possible to think of endless diabolical things one might do to class in class decorator functionit' probably best to avoid excessive magic such as putting wrapper around the class or rewriting the class contents lib fl ff