{"id":4644,"date":"2024-09-26T05:02:15","date_gmt":"2024-09-26T05:02:15","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=4644"},"modified":"2026-02-05T06:53:12","modified_gmt":"2026-02-05T06:53:12","slug":"what-are-metaclasses-in-python","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/","title":{"rendered":"What Are Metaclasses in Python"},"content":{"rendered":"\n<p>Python is a powerful object oriented programming language used by millions of software developers and organizations. It not only supports classes and objects like other programming languages but also something called as metaclasses. Many programmers often want to know more about metaclasses and get confused about them. In this article, we will learn what are metaclasses in Python, and how to work with them. We will also learn how they are different from traditional classes. They are mainly used in metaprogramming, a practice that allows you to write code to modify the existing code in your application.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#Classes_as_Objects\" >Classes as Objects<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#What_Are_Metaclasses\" >What Are Metaclasses<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#Creating_Custom_Metaclasses\" >Creating Custom Metaclasses<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#Benefits_of_Metaclasses\" >Benefits of Metaclasses<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#When_to_Use_Metaclasses\" >When to Use Metaclasses<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#Common_Examples\" >Common Examples<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#1_Create_Class_Dynamically\" >1. Create Class Dynamically<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#2_Class_Validation\" >2. Class Validation<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Classes_as_Objects\"><\/span>Classes as Objects<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Before we try to understand metaclasses in python, it is important to learn about regular classes and objects. A class is like a template for an object. It defines the data, attributes and functions that are available to the object. But it has no actual existence. It is only when an object instance is created out of this class, that memory is allocated for the object and not the class. Python provides many pre-built classes as well as allows you to create user-defined classes. Here is an example to create a simple list object from pre-built list class.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; sample = list(\"hello\")<\/pre>\n\n\n\n<p>You can verify the list using following command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; print(sample)<br>['h', 'e', 'l', 'l', 'o']<\/pre>\n\n\n\n<p>You can also check its data type using type() function. In python 3+, you will see the output as class, instead of type.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; type(sample)<br>&lt;class 'list'&gt;<\/pre>\n\n\n\n<p>You can also check the attributes &amp; functions available for this class using the dir() function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; print(dir(sample))<br>['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']<\/pre>\n\n\n\n<p>Among them, you can use __<strong>class__<\/strong> attribute to get the information about the object&#8217;s class.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; print(sample.__class__)<br>&lt;class 'list'&gt;<\/pre>\n\n\n\n<p>This is where it gets interesting. If you call __<strong>class<\/strong>__ on the output of above command, you will see that &#8216;list&#8217; class itself is an instance of &#8216;type&#8217; class.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; print(sample.__class__.__class__)<br>&lt;class 'type'&gt;<\/pre>\n\n\n\n<p>Let us see what happens when we repeat the above steps with a string. We define a string as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; sample = 'hello'<\/pre>\n\n\n\n<p>Let us look at its type.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; print(type(sample))<br>&lt;class 'str'&gt;<\/pre>\n\n\n\n<p>We see that it is string. Let us check its metaclass.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; print(sample.__class__.__class__)<br>&lt;class 'type'&gt;<\/pre>\n\n\n\n<p>You will see that its metaclass is also &#8216;type&#8217;. If you repeat the above steps for other data types, you will get the same result. We see that &#8216;type&#8217; is the metaclass of all data types in Python.<\/p>\n\n\n\n<p>In other words, everything in Python is an object.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Are_Metaclasses\"><\/span>What Are Metaclasses<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Metaclass is a class whose instance is a class itself, not an object instance. It allows you to modify the way a class behaves and consequently how its objects also work. Metaclass is like a parent class of a regular class whose attributes and methods are automatically inherited and can be overridden by the metaclass. In simple words, a metaclass is a class that creates other classes. The created classes can create object instances.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_Custom_Metaclasses\"><\/span>Creating Custom Metaclasses<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let us create a very simple metaclass and regular class to understand how to create metaclasses and use them.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class sample_metaclass(type):<br>   pass<br>   <br>class sample_regular_class(metaclass=sample_metaclass):<br>   pass<br>   <br>sample_object=sample_regular_class()<\/pre>\n\n\n\n<p>In the above code, we created a simple metaclass of type &#8216;type&#8217;. We have created a regular class sample_regular_class which inherits from this metaclass, via metaclass argument.<\/p>\n\n\n\n<p>Lastly, we create an object instance using this metaclass.<\/p>\n\n\n\n<p>Let us look at the class of object.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; print(sample_object.__class__)<br>&lt;class '__main__.sample_regular_class'&gt;<\/pre>\n\n\n\n<p>Here is the class of sample_regular_class.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; print(sample_regular_class.__class__)<br>&lt;class '__main__.sample_metaclass'&gt;<\/pre>\n\n\n\n<p>Here is the metaclass of sample_regular_class.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;class 'type'&gt;<\/pre>\n\n\n\n<p>It is important to note, that even if you do not specify a metaclass for a class, it is still derived from type metaclass.<\/p>\n\n\n\n<p>There are 2 other methods to create metaclasses in Python &#8211; using __<strong>new__<\/strong> and __<strong>init__<\/strong>.<\/p>\n\n\n\n<p>Here is how to create metaclasses using <strong>__new__<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class sample(type):<br>    def __new__(cls, name, bases, dict):<br>        pass<\/pre>\n\n\n\n<p>__<strong>new<\/strong>__ is used to control metaclass creation by defining dict or bases classes tuples. It returns a class of type cls. It is useful to customize instance creation.<\/p>\n\n\n\n<p>Here is how to create metaclasses in Python using <strong>__init__<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class sample(type):<br>    def __init__(self, name, bases, dict):<br>        pass<\/pre>\n\n\n\n<p>__<strong>init__<\/strong> is usually called after instance creation before initialization.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Benefits_of_Metaclasses\"><\/span>Benefits of Metaclasses<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Metaclass allows you to reduce code repetition by wrapping common data, attributes and functions for a bunch of classes into a metaclass and making those classes inherit from this metaclass.<\/li>\n\n\n\n<li>Singleton design &#8211; In this case, you can use metaclass to ensure that the same class is not defined more than once. It is used in data connectors to prevent multiple connections to same data source.<\/li>\n\n\n\n<li>Metaclasses are great for building the basic infrastructure that programmers can leverage to quickly develop applications. Instead of writing everything from scratch, you can write a set of metaclasses with common data, attributes and functions that feed into your classes.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"When_to_Use_Metaclasses\"><\/span>When to Use Metaclasses<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Although metaclasses are rarely used, they are required in important situations.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>API Development &#8211; Metaclasses are commonly used for API development.<\/li>\n\n\n\n<li>They are generally used to dynamically create classes, as shown below.<\/li>\n\n\n\n<li>They are used to modify a hierarchy of classes and subclasses<\/li>\n\n\n\n<li>They are also used to validate class attributes. For example, if you want to restrict attribute values of data types for a class and its sub classes, you can do it in the metaclass itself.<\/li>\n\n\n\n<li>If you want to automatically change a class when it is created, you can do so by making it inherit from a metaclass.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Common_Examples\"><\/span>Common Examples<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let us look at some common example to use metaclasses.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Create_Class_Dynamically\"><\/span>1. Create Class Dynamically<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>One of the simplest use cases is to dynamically create Python classes. Generally, type() function is directly called on a data. But you can also pass 2 optional arguments to it. Here is the complete syntax of type().<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">type(name, bases, dict)<\/pre>\n\n\n\n<p>In the above function, name is the name of the class, bases is a tuple of classes from which the class inherits and dict is the namespace directory containing definitions for class.<\/p>\n\n\n\n<p>When we call type() function with all 3 arguments, it will dynamically create a class instance of type metaclass. <\/p>\n\n\n\n<p>Here is how to dynamically create class named sample using metaclasses. Here the bases argument is empty indicating that it does not inherit from any other class. The dict argument is also empty indicating that this class does not have any attributes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; sample = type('sample', (), {})<br><br>&gt;&gt;&gt; x = sample()<br>&gt;&gt;&gt; x<br>&lt;__main__.sample object at ...&gt;<\/pre>\n\n\n\n<p>To make the above code easy to understand, here is how to create the exact same above class the regular way using Class keyword.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; class sample:<br>...     pass<br>...<br>&gt;&gt;&gt; x = sample()<br>&gt;&gt;&gt; x<br>&lt;__main__.sample object at ...&gt;<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Class_Validation\"><\/span>2. Class Validation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Another simple example is to easily check if a class inherits from multiple classes. For this we first create a sample_meta metaclass. Each metaclass has to generally inherit type metaclass and override __<strong>new<\/strong>__() and __<strong>init__<\/strong>() functions. __<strong>new<\/strong>__() function is called before __<strong>init__<\/strong>() and can be used to control how the object is created. We will override this method in the metaclass to check if it inherits from multiple classes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class sample_meta(type):<br>    # override __new__ method<br>    def __new__(cls, clsname, bases, clsdict):<br>        # if number of base classes &gt; 1 then raise error<br>        if len(bases)&gt;1:<br>            raise TypeError(\"Inherited multiple base classes\")         <br>        # else call __init__ of type class<br>        return super().__new__(cls, clsname, bases, clsdict)<\/pre>\n\n\n\n<p>Next, we create a regular class using the above metaclass.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class base(metaclass=sample_meta):<br>    pass<\/pre>\n\n\n\n<p>Then we create 2 classes that inherit from this base class &#8211; One, Two. Both One and Two inherit only one class whereas Three inherits 2 classes &#8211; One and Two. Therefore, it will raise an error.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># no error<br>class One(Base):<br>    pass<br> <br># no error <br>class Two(Base):<br>    pass<br> <br># raises error<br>class Three(One, Two):<br>    pass<\/pre>\n\n\n\n<p>You can also do this using <a href=\"https:\/\/peps.python.org\/pep-0318\/\" target=\"_blank\" rel=\"noreferrer noopener\">decorators<\/a> but in that case you will need to create separate decorators for each subclass, which is very tedious, especially in big complex applications.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt what are metaclasses and how to use them. Metaclasses are classes that allow you to create and modify classes that inherit from it. This is an advanced concept that is not really required for most Python programmers. It is sometimes used to build the basic infrastructure used to speed up software development of complex applications. Nevertheless, if you ever need to work with Metaclasses in python, we hope this article will help you quickly get up and running.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/what-does-yield-keyword-do-in-python\/\">What Does Yield Keyword Do In Python<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-access-correct-this-inside-callback\/\">How to Access Correct This Inside Callback<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-return-response-from-asynchronous-call\/\">How to Return Response from Asynchronous Call<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often Python programmers wonder what are metaclasses in Python. In this article, we will learn how to use metaclasses in your Python program.<\/p>\n","protected":false},"author":1,"featured_media":4662,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301],"tags":[308],"class_list":["post-4644","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-metaclass"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What Are Metaclasses in Python - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Often Python programmers wonder what are metaclasses in Python. In this article, we will learn how to use metaclasses in your Python program.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What Are Metaclasses in Python - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Often Python programmers wonder what are metaclasses in Python. In this article, we will learn how to use metaclasses in your Python program.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-26T05:02:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-05T06:53:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/09\/metaclasses-in-python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"336\" \/>\n\t<meta property=\"og:image:height\" content=\"224\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/what-are-metaclasses-in-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/what-are-metaclasses-in-python\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"What Are Metaclasses in Python\",\"datePublished\":\"2024-09-26T05:02:15+00:00\",\"dateModified\":\"2026-02-05T06:53:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/what-are-metaclasses-in-python\\\/\"},\"wordCount\":1269,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/what-are-metaclasses-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/metaclasses-in-python.jpg?fit=336%2C224&ssl=1\",\"keywords\":[\"metaclass\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/what-are-metaclasses-in-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/what-are-metaclasses-in-python\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/what-are-metaclasses-in-python\\\/\",\"name\":\"What Are Metaclasses in Python - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/what-are-metaclasses-in-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/what-are-metaclasses-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/metaclasses-in-python.jpg?fit=336%2C224&ssl=1\",\"datePublished\":\"2024-09-26T05:02:15+00:00\",\"dateModified\":\"2026-02-05T06:53:12+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Often Python programmers wonder what are metaclasses in Python. In this article, we will learn how to use metaclasses in your Python program.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/what-are-metaclasses-in-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/what-are-metaclasses-in-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/what-are-metaclasses-in-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/metaclasses-in-python.jpg?fit=336%2C224&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/metaclasses-in-python.jpg?fit=336%2C224&ssl=1\",\"width\":336,\"height\":224,\"caption\":\"metaclasses in python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/what-are-metaclasses-in-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What Are Metaclasses in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What Are Metaclasses in Python - Ubiq BI","description":"Often Python programmers wonder what are metaclasses in Python. In this article, we will learn how to use metaclasses in your Python program.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/","og_locale":"en_US","og_type":"article","og_title":"What Are Metaclasses in Python - Ubiq BI","og_description":"Often Python programmers wonder what are metaclasses in Python. In this article, we will learn how to use metaclasses in your Python program.","og_url":"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2024-09-26T05:02:15+00:00","article_modified_time":"2026-02-05T06:53:12+00:00","og_image":[{"width":336,"height":224,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/09\/metaclasses-in-python.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"What Are Metaclasses in Python","datePublished":"2024-09-26T05:02:15+00:00","dateModified":"2026-02-05T06:53:12+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/"},"wordCount":1269,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/09\/metaclasses-in-python.jpg?fit=336%2C224&ssl=1","keywords":["metaclass"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/","url":"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/","name":"What Are Metaclasses in Python - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/09\/metaclasses-in-python.jpg?fit=336%2C224&ssl=1","datePublished":"2024-09-26T05:02:15+00:00","dateModified":"2026-02-05T06:53:12+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Often Python programmers wonder what are metaclasses in Python. In this article, we will learn how to use metaclasses in your Python program.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/09\/metaclasses-in-python.jpg?fit=336%2C224&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/09\/metaclasses-in-python.jpg?fit=336%2C224&ssl=1","width":336,"height":224,"caption":"metaclasses in python"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"What Are Metaclasses in Python"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/09\/metaclasses-in-python.jpg?fit=336%2C224&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1cU","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/4644","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=4644"}],"version-history":[{"count":24,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/4644\/revisions"}],"predecessor-version":[{"id":10514,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/4644\/revisions\/10514"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/4662"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=4644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=4644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=4644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}