Metaclasses
A metaclass is the class of a class. Just as a class defines how its instances behave, a metaclass defines how a class behaves.
Metaclass = the blueprint for blueprints. If a class is a cookie cutter and instances are cookies, the metaclass is the factory that manufactures cookie cutters. Meta = one level up from the thing itself.
type is the default metaclass of all classes. class Foo(metaclass=MyMeta) uses a custom metaclass. __new__ and __init__ on the metaclass run when the class is defined (not when instances are created). Metaclasses are how ORMs (Django models), ABCs, and some frameworks (e.g., attrs, pydantic) work under the hood.
__prepare__ on the metaclass returns the namespace dict used during class body execution (used to support ordered attributes, etc.). __new__(mcs, name, bases, namespace) creates the class object. Most metaclass use cases are now better served by __init_subclass__ (Python 3.6+) or class decorators — they're simpler and less surprising. Metaclass conflicts occur when multiple bases have different metaclasses that aren't in a subclass relationship. The conflict must be resolved by creating a metaclass that inherits from all conflicting ones.
Every class in Python is an instance of a metaclass — by default, type. A custom metaclass lets you intercept class creation: modify class attributes, register subclasses, enforce interfaces, or auto-generate methods. I'd use __init_subclass__ first (simpler, cleaner) and reach for a full metaclass only when I need to control the class namespace itself via __prepare__. ORMs like Django use metaclasses to turn class attributes (Field instances) into database column definitions.
Metaclasses run at class definition time, not instantiation time. A bug in your metaclass can make a class impossible to define — the error fires at import time, which is confusing to debug.