Automatically registering plugin systems
One very useful way to use metaclasses is to have classes automatically register themselves as plugins/handlers.
Instead of manually adding a register call after creating the class or by adding a decorator, you can make it completely automatic for the user. That means that the user of your library or plugin system cannot accidentally forget to add the register call.
Note the distinction between registering and importing. While this first example shows automatic registering, automatic importing is covered in later sections.
Examples of these can be seen in many projects such as web frameworks. The Django web framework, for example, uses metaclasses for its database models (effectively tables) to automatically generate the table and column names based on the class and attribute names.
The actual code base of projects like these is too extensive to usefully explain here though. Hence, we’ll show a simpler example...