ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.3 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://www.python-engineer.com/posts/metaclasses-python/ |
| Last Crawled | 2026-04-15 19:42:21 (8 days ago) |
| First Indexed | 2022-11-26 22:52:01 (3 years ago) |
| HTTP Status Code | 200 |
| Content | |
| Meta Title | What are metaclasses in Python - Python Engineer |
| Meta Description | A beginners guide to metaclasses in Python. |
| Meta Canonical | null |
| Boilerpipe Text | A beginners guide to metaclasses in Python.
Python
Basics
Metaclass is an advanced Python concept and is not used in day-to-day programming tasks. They allow a user to precisely define a class state, change its attributes and control method behavior.
In this article, we will understand how metaclasses can be created and used in Python.
1. Type and OOP
¶
Everything is an object in Python, including classes. Hence, if classes are an object, they must be created by another class also called as Metaclass.
So, a metaclass is just another class that creates class objects. Usually,
type
is the built-in metaclass Python uses for every class. But we can also create our own metaclasses with custom behavior.
2. Understanding the
type()
function
¶
To fully understand Metaclasses, one needs to thoroughly understand
type()
.
In Python,
type()
is used to identify the data type of a variable. If we have the following code
var
=
12
print
(
type
(
var
))
Console output would be:
<class 'int'>
Indicating
var
is an instance of the class
int
.
In the case of a user-defined class, we get the following output.
class
Foo
:
def
bar
():
pass
foo_obj
=
Foo
()
print
(
"Type of Foo's instance is:"
,
type
(
foo_obj
))
print
(
"Type of Foo is:"
,
type
(
Foo
))
Type of Foo's instance is: <class '__main__.Foo'>
Type of Foo is: <class 'type'>
Here, we can see
foo_obj
is correctly identified as an instance of class
Foo
, but the type of class
Foo
indicates that it is an instance of class
type
, establishing the point that classes are indeed created by other classes.
Creating classes dynamically using
type()
¶
This is one more concept we should know before diving into metaclasses.
This usage of
type()
is fairly unknown. The
type()
function can take three arguments and can be used to create classes dynamically:
type
(
name
:
str
,
bases
:
tuple
,
attributes
:
dict
)
name
indicates the name of a class
bases
is a tuple of classes to be inherited
attributes
is a dictionary including all variables and methods to be declared inside the new class
Example:
Dummy
=
type
(
"Dummy"
,
(),
{
"var1"
:
"lorem ipsum sit domat"
})
dummy
=
Dummy
()
print
(
dummy
.
var1
)
Output:
lorem ipsum sit domat
The main purpose of a metaclass is to change the class automatically when it's created.
To use class as a metaclass we pass
metaclass=ClassName
as a class parameter. The metaclass itself is implemented like a normal class with any behavior we want. Usually the
__new__
function is implemented.
The name of the metaclass should ideally make the intent of the class clear:
Example:
class
PrintAttributeMeta
:
def
__new__
(
cls
,
class_name
,
bases
,
attributes
):
print
(
"Attributes received in PrintAttributeMeta:"
,
attributes
)
return
type
(
class_name
,
bases
,
attributes
)
class
Dummy
(
metaclass
=
PrintAttributeMeta
):
class_var1
=
"lorem"
class_var2
=
45
Output:
Attributes received in PrintAttributeMeta: {'__module__': '__main__', '__qualname__': 'Dummy', 'class_var1': 'lorem', 'class_var2': 45}
This meta class simply prints all attributes, and then creates and returns a new class by using the
type()
function.
Note that there’s output without creating an instance of the class because the
__new__()
method is called when the class is created.
Using Metaclasses, the user can perform multitude of validations and modification such as changing variable names, raising error on receiving an invalid data type, checking inheritance levels, etc.
For this example, we will write a Metaclass that raises a
ValueError
when a negative value is received in
attributes
.
class
PositiveNumbersMeta
:
def
__new__
(
cls
,
class_name
,
bases
,
attributes
):
for
attr
,
value
in
attributes
.
items
():
if
isinstance
(
value
,
(
int
,
float
))
and
value
<
0
:
raise
ValueError
(
f
"Negative values are not allowed in
{
class_name
}
"
)
return
type
(
class_name
,
bases
,
attributes
)
class
MyClass
(
metaclass
=
PositiveNumbersMeta
):
class_var1
=
23
class_var2
=
-
1
Output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 5, in __new__
ValueError: Negative values are not allowed in MyClass
We could also change attributes:
class
PositiveNumbersMeta
:
def
__new__
(
cls
,
class_name
,
bases
,
attributes
):
for
attr
,
value
in
attributes
.
items
():
if
isinstance
(
value
,
(
int
,
float
))
and
value
<
0
:
attributes
[
attr
]
=
-
value
return
type
(
class_name
,
bases
,
attributes
)
class
MyClass
(
metaclass
=
PositiveNumbersMeta
):
class_var1
=
23
class_var2
=
-
1
a
=
MyClass
()
print
(
a
.
class_var2
)
# 1
5. Use proper OOP principles
¶
In the previous example we are calling
type
directly and aren't overriding or calling the parent's
__new__
. Let's do that instead:
class
PositiveNumbersMeta
(
type
):
def
__new__
(
cls
,
class_name
,
bases
,
attributes
):
for
attr
,
value
in
attributes
.
items
():
if
isinstance
(
value
,
(
int
,
float
))
and
value
<
0
:
attributes
[
attr
]
=
-
value
return
super
.
__new__
(
class_name
,
bases
,
attributes
)
Now our metaclass inherits from
type
, and by calling the
super.__new__()
we are using the OOP syntax and call the
__new__()
function of the base class.
There are several reasons to do so:
The intention is clear. When you read PositiveNumbersMeta, you know what's going to follow
You can use OOP. Metaclass can inherit from metaclass, override parent methods, etc. Metaclasses can even use other metaclasses.
You can structure your code better. You never use metaclasses for something as trivial as the above example. It's usually for something complicated. Having the ability to make several methods and group them in one class is very useful to make the code easier to read.
You can hook on
__new__
,
__init__
and
__call__
. Which will allow you to do different stuff, Even if usually you can do it all in
__new__
, some people are just more comfortable using
__init__
.
Resource: Here's a great
StackOverflow answer
that explains it well.
Note that Metaclasses are usually only used in more complex scenarios, and in 99% of cases you don't have to worry about it. One common use case is when creating an API. A typical example of this is the
Django ORM
.
FREE VS Code / PyCharm Extensions I Use
✅ Write cleaner code with Sourcery, instant refactoring suggestions:
Link*
Python Problem-Solving Bootcamp
🚀 Solve 42 programming puzzles over the course of 21 days:
Link*
* These are affiliate link. By clicking on it you will not have any additional costs. Instead, you will support my project. Thank you! 🙏 |
| Markdown | [Skip to content](https://www.python-engineer.com/posts/metaclasses-python/#1-type-and-oop)
[](https://www.python-engineer.com/ "Python Engineer")
Python Engineer
What are metaclasses in Python
Initializing search
- [Home](https://www.python-engineer.com/)
- [Posts](https://www.python-engineer.com/posts/)
- [About](https://www.python-engineer.com/about/)
- [Newsletter](https://www.python-engineer.com/newsletter/)
[](https://www.python-engineer.com/ "Python Engineer") Python Engineer
- [Home](https://www.python-engineer.com/)
- [Posts](https://www.python-engineer.com/posts/)
Posts
- Tutorials
Tutorials
- [How to split a List into equally sized chunks in Python](https://www.python-engineer.com/posts/split_list_in_chunks/)
- [How to delete a key from a dictionary in Python](https://www.python-engineer.com/posts/delete-key-dictionary/)
- [How to convert a Google Colab to Markdown](https://www.python-engineer.com/posts/convert-colab-markdown/)
- [LangChain Tutorial in Python - Crash Course](https://www.python-engineer.com/posts/langchain-crash-course/)
- [How to write your own context manager in Python](https://www.python-engineer.com/posts/contextlib-contextmanager/)
- [How to easily remove the background of images in Python](https://www.python-engineer.com/posts/remove_background/)
- [How to work with the Notion API in Python](https://www.python-engineer.com/posts/notion-api-python/)
- [How to measure the elapsed time in Python](https://www.python-engineer.com/posts/measure-elapsed-time/)
- [How to copy a List in Python without side effects](https://www.python-engineer.com/posts/how-to-copy-list/)
- [How to check if a List is empty in Python](https://www.python-engineer.com/posts/check-if-list-is-empty/)
- [How to sort a dictionary by values in Python](https://www.python-engineer.com/posts/sort-dictionary-values/)
- [How to schedule Python scripts with GitHub Actions](https://www.python-engineer.com/posts/run-python-github-actions/)
- [How to create a constant in Python](https://www.python-engineer.com/posts/constants-in-python/)
- [Best hosting platforms for Python applications and Python scripts](https://www.python-engineer.com/posts/hosting-platforms-for-python/)
- [6 Tips To Write Better For Loops in Python](https://www.python-engineer.com/posts/better-for-loops-python/)
- [How to reverse a String in Python](https://www.python-engineer.com/posts/reverse-string-python/)
- [How to debug Python apps inside a Docker Container with VS Code](https://www.python-engineer.com/posts/debug-python-docker/)
- [10 Python One Liner You Must Know](https://www.python-engineer.com/posts/10-python-oneliner/)
- [How to apply image thresholding in Python with NumPy](https://www.python-engineer.com/posts/image-thresholding/)
- [15 Best AI Newsletters](https://www.python-engineer.com/posts/15-best-ai-newsletters/)
- [Learn about Pandas groupby operations - From Zero to Hero](https://www.python-engineer.com/posts/pandas-groupby-operations/)
- [Socket Programming in Python](https://www.python-engineer.com/posts/python-sockets/)
- [The base64 Module in Python](https://www.python-engineer.com/posts/base64-module/)
- [How to limit float values to N decimal places in Python](https://www.python-engineer.com/posts/limit-float-python/)
- [Exploring the statistics module in Python](https://www.python-engineer.com/posts/statistics-python/)
- [File Organizing with Python](https://www.python-engineer.com/posts/file-organization/)
- [How to rename files in Python](https://www.python-engineer.com/posts/rename-files/)
- [Deque in Python using Collections Module](https://www.python-engineer.com/posts/deque-python/)
- [Calendar Module in Python](https://www.python-engineer.com/posts/calendar-python/)
- [Enum in Python](https://www.python-engineer.com/posts/enums-python/)
- [How to use pprint in Python?](https://www.python-engineer.com/posts/pprint-python/)
- [Working with Stacks in Python](https://www.python-engineer.com/posts/python-stacks/)
- [What is functools in Python?](https://www.python-engineer.com/posts/functools-overview/)
- [Tip - Use the round() function with negative arguments](https://www.python-engineer.com/posts/round-function/)
- [Tip - The print function can take additional arguments](https://www.python-engineer.com/posts/print-function/)
- [Tip - Find the longest String in a List in Python using the max() function](https://www.python-engineer.com/posts/find-longest-string/)
- [Tip - How to loop over multiple Lists in Python with the zip function](https://www.python-engineer.com/posts/zip-for-loop/)
- [Precision Handling in Python \| floor, ceil, round, trunc, format](https://www.python-engineer.com/posts/precision-handling/)
- [Difference between byte objects and string in Python](https://www.python-engineer.com/posts/byte-vs-string-objects/)
- [How to use ThreadPoolExecutor in Python](https://www.python-engineer.com/posts/threadpoolexecutor/)
- [How to work with ZIP files in Python](https://www.python-engineer.com/posts/python-zip/)
- [Difference between the equality operator and is operator in Python](https://www.python-engineer.com/posts/equality-vs-is-operator/)
- [Type Conversion in Python](https://www.python-engineer.com/posts/type-conversion/)
- [How to work with tarball/tar files in Python](https://www.python-engineer.com/posts/tarfile-python/)
- [Difference between iterator and iterable in Python](https://www.python-engineer.com/posts/iterable-vs-iterator/)
- [Difference between set() and frozenset() in Python](https://www.python-engineer.com/posts/set-vs-frozentset/)
- [How to use dotenv package to load environment variables in Python](https://www.python-engineer.com/posts/dotenv-python/)
- [How to count the occurrence of an element in a List in Python](https://www.python-engineer.com/posts/count-element-list/)
- [How to format Strings in Python](https://www.python-engineer.com/posts/string-formatting/)
- [How to use Poetry to manage dependencies in Python](https://www.python-engineer.com/posts/python-poetry-tutorial/)
- [Difference between sort() and sorted() in Python](https://www.python-engineer.com/posts/sort-vs-sorted/)
- [What does the yield keyword do in Python](https://www.python-engineer.com/posts/yield-in-python/)
- [Data classes in Python with dataclass decorator](https://www.python-engineer.com/posts/dataclass-python/)
- [How to access and set environment variables in Python](https://www.python-engineer.com/posts/environment-variables-python/)
- [Complete Guide to the datetime Module in Python](https://www.python-engineer.com/posts/datetime-module/)
- [How to build CLIs using Quo](https://www.python-engineer.com/posts/cli-with-quo/)
- [What are virtual environments in Python and how to work with them](https://www.python-engineer.com/posts/virtual-environments-python/)
- [What is super() in Python](https://www.python-engineer.com/posts/super-in-python/)
- [Complex Numbers in Python](https://www.python-engineer.com/posts/complex-numbers-python/)
- [What is the meaning of single and double leading underscore in Python](https://www.python-engineer.com/posts/double-single-leading-underscore/)
- [Working with Videos in OpenCV using Python](https://www.python-engineer.com/posts/opencv-videos/)
- [In-place file editing with fileinput module](https://www.python-engineer.com/posts/inplace-file-editing/)
- [How to convert a string to float/integer and vice versa in Python](https://www.python-engineer.com/posts/string-to-float/)
- [Working with Images in OpenCV using Python](https://www.python-engineer.com/posts/opencv-images/)
- What are metaclasses in Python
[What are metaclasses in Python](https://www.python-engineer.com/posts/metaclasses-python/)
On this page
- [1\. Type and OOP](https://www.python-engineer.com/posts/metaclasses-python/#1-type-and-oop)
- [2\. Understanding the type() function](https://www.python-engineer.com/posts/metaclasses-python/#2-understanding-the-type-function)
- [Creating classes dynamically using type()](https://www.python-engineer.com/posts/metaclasses-python/#creating-classes-dynamically-using-type)
- [3\. Creating Metaclass](https://www.python-engineer.com/posts/metaclasses-python/#3-creating-metaclass)
- [4\. Modifying a class state using Metaclass](https://www.python-engineer.com/posts/metaclasses-python/#4-modifying-a-class-state-using-metaclass)
- [5\. Use proper OOP principles](https://www.python-engineer.com/posts/metaclasses-python/#5-use-proper-oop-principles)
- [6\. When to use metaclasses?](https://www.python-engineer.com/posts/metaclasses-python/#6-when-to-use-metaclasses)
- [How to randomly select an item from a list?](https://www.python-engineer.com/posts/randomly-select-item/)
- [Getting Started with OpenCV in Python](https://www.python-engineer.com/posts/opencv-python-intro/)
- [What are global, local, and nonlocal scopes in Python](https://www.python-engineer.com/posts/global-local-nonlocal-python/)
- [What is self in Python classes](https://www.python-engineer.com/posts/self-python/)
- [Create a Task Tracker App for the Terminal with Python (Rich, Typer, Sqlite3)](https://www.python-engineer.com/posts/task-tracker-cli/)
- [Introduction to Graph Machine Learning](https://www.python-engineer.com/posts/graph-ml-intro/)
- [How to check if an object is iterable in Python](https://www.python-engineer.com/posts/object-is-iterable/)
- [How to slice sequences in Python](https://www.python-engineer.com/posts/sequence-slicing/)
- [How to read and write files in Python](https://www.python-engineer.com/posts/read-write-file/)
- [How to remove duplicate elements from a List in Python](https://www.python-engineer.com/posts/remove-duplicates-list/)
- [How To Analyze Apple Health Data With Python](https://www.python-engineer.com/posts/apple-health-data-python/)
- [How to flatten a list of lists in Python](https://www.python-engineer.com/posts/flatten-list-of-lists/)
- [What is assert in Python](https://www.python-engineer.com/posts/assert/)
- [What are \*args and \*\*kwargs in Python](https://www.python-engineer.com/posts/args-kwargs/)
- [How to delete files and folders in Python](https://www.python-engineer.com/posts/delete-files-python/)
- [31 essential String methods in Python you should know](https://www.python-engineer.com/posts/string-methods-python/)
- [What is \_\_init\_\_.py file in Python](https://www.python-engineer.com/posts/init-py-file/)
- [How to copy files in Python](https://www.python-engineer.com/posts/copy-files-python/)
- [Quick Python Refactoring Tips (Part 2)](https://www.python-engineer.com/posts/python-refactoring-tips-part2/)
- [How to ask the user for input until they give a valid response in Python](https://www.python-engineer.com/posts/ask-user-for-input/)
- [Master Pattern Matching In Python 3.10 \| All Options \|](https://www.python-engineer.com/posts/pattern-matching-python/)
- [Create a Note Taking App in Python with Speech Recognition and the Notion API](https://www.python-engineer.com/posts/note-taking-python/)
- [Python Automation Projects With Machine Learning](https://www.python-engineer.com/posts/machine-learning-automation/)
- [New Features In Python 3.10 You Should Know](https://www.python-engineer.com/posts/new-features-in-python-3-10/)
- [5 Python Pitfalls that can save you HOURS of debugging\!](https://www.python-engineer.com/posts/5-python-pitfalls/)
- [What is the difference between append and extend for Python Lists?](https://www.python-engineer.com/posts/append-vs-extend/)
- [10 Python Basics You Should Know\!](https://www.python-engineer.com/posts/10-python-basics/)
- [How to concatenate two Lists in Python](https://www.python-engineer.com/posts/concatenate-two-lists/)
- [Difference between \_\_str\_\_ and \_\_repr\_\_ in Python](https://www.python-engineer.com/posts/difference-between-str-and-repr/)
- [Difference between @classmethod, @staticmethod, and instance methods in Python.](https://www.python-engineer.com/posts/difference-classmethod-and-staticmethod/)
- [How to pad zeros to a String in Python](https://www.python-engineer.com/posts/pad-zeros-string/)
- [How to create a nested directory in Python](https://www.python-engineer.com/posts/create-nested-directory/)
- [How to merge two Dictionaries in Python](https://www.python-engineer.com/posts/merge-two-dictionaries/)
- [How to execute a Program or System Command from Python](https://www.python-engineer.com/posts/python-execute-system-command/)
- [How to check if a String contains a Substring in Python](https://www.python-engineer.com/posts/check-if-string-contains-substring/)
- [How to find the index of an item in a List in Python](https://www.python-engineer.com/posts/find-index-of-item-in-list/)
- [How to access the index in a for loop in Python](https://www.python-engineer.com/posts/access-index-in-for-loop/)
- [How to check if a file or directory exists in Python](https://www.python-engineer.com/posts/check-if-file-exists/)
- [How to remove elements in a Python List while looping](https://www.python-engineer.com/posts/remove-elements-in-list-while-iterating/)
- [What does if \_\_name\_\_ == "\_\_main\_\_" do?](https://www.python-engineer.com/posts/python-if-name-main/)
- [The Best FREE Machine Learning Crash Courses](https://www.python-engineer.com/posts/free-ml-crash-courses/)
- [How to write while loops in Python](https://www.python-engineer.com/posts/python-while-loops/)
- [How to write for loops in Python](https://www.python-engineer.com/posts/python-for-loops/)
- [Quick Python Refactoring Tips](https://www.python-engineer.com/posts/python-refactoring-tips/)
- [Async Views in Django 3.1](https://www.python-engineer.com/posts/django-async-views/)
- [Build A Machine Learning iOS App \| PyTorch Mobile Deployment](https://www.python-engineer.com/posts/pytorch-ios-app/)
- [HuggingFace Crash Course](https://www.python-engineer.com/posts/huggingface-crash-course/)
- [10 Deep Learning Projects With Datasets (Beginner & Advanced)](https://www.python-engineer.com/posts/10-deeplearning-projects/)
- [How To Deploy ML Models With Google Cloud Run](https://www.python-engineer.com/posts/cloud-run-deployment/)
- [MongoDB Crash Course With Python](https://www.python-engineer.com/posts/python-mongodb-crashcourse/)
- [Why I Don't Care About Code Formatting In Python \| Black Tutorial](https://www.python-engineer.com/posts/black-code-formatter/)
- [Build A Machine Learning Web App From Scratch](https://www.python-engineer.com/posts/ml-web-app-from-scratch/)
- [Beautiful Terminal Styling in Python With Rich](https://www.python-engineer.com/posts/rich-terminal-styling/)
- [How To Hack Neural Networks\!](https://www.python-engineer.com/posts/hacking-neural-networks/)
- [Should You Use FOR Or WHILE Loop In Python?](https://www.python-engineer.com/posts/for-vs-while-loop/)
- [Learn NumPy In 30 Minutes](https://www.python-engineer.com/posts/numpy-in-30-minutes/)
- [Quick Data Analysis In Python Using Mito](https://www.python-engineer.com/posts/mito-spreadsheets/)
- [Autoencoder In PyTorch - Theory & Implementation](https://www.python-engineer.com/posts/pytorch-autoencoder/)
- [How To Scrape Reddit & Automatically Label Data For NLP Projects \| Reddit API Tutorial](https://www.python-engineer.com/posts/reddit-api-tutorial/)
- [How To Build A Photo Sharing Site With Django](https://www.python-engineer.com/posts/django-photo-sharing/)
- [PyTorch Time Sequence Prediction With LSTM - Forecasting Tutorial](https://www.python-engineer.com/posts/pytorch-time-sequence/)
- [Create Conversational AI Applications With NVIDIA Jarvis](https://www.python-engineer.com/posts/nvidia-jarvis/)
- [Create A Chatbot GUI Application With Tkinter](https://www.python-engineer.com/posts/chatbot-gui-tkinter/)
- [Build A Stock Prediction Web App In Python](https://www.python-engineer.com/posts/stockprediction-app/)
- [Machine Learning From Scratch in Python - Full Course \[FREE\]](https://www.python-engineer.com/posts/mlfromscratch-course/)
- [Awesome Python Automation Ideas](https://www.python-engineer.com/posts/python-automation-ideas/)
- [How To Edit Videos With Python](https://www.python-engineer.com/posts/video-editing-with-python/)
- [How To Schedule Python Scripts As Cron Jobs With Crontab (Mac/Linux)](https://www.python-engineer.com/posts/cron-jobs-for-python/)
- [Build A Website Blocker With Python - Task Automation Tutorial](https://www.python-engineer.com/posts/website-blocker-in-python/)
- [How To Setup Jupyter Notebook In Conda Environment And Install Kernel](https://www.python-engineer.com/posts/setup-jupyter-notebook-in-conda-environment/)
- [Teach AI To Play Snake - Practical Reinforcement Learning With PyTorch And Pygame](https://www.python-engineer.com/posts/teach-ai-snake-reinforcement-learning/)
- [Python Snake Game With Pygame - Create Your First Pygame Application](https://www.python-engineer.com/posts/snake-pygame/)
- [PyTorch LR Scheduler - Adjust The Learning Rate For Better Results](https://www.python-engineer.com/posts/pytorch-lrscheduler/)
- [Docker Tutorial For Beginners - How To Containerize Python Applications](https://www.python-engineer.com/posts/docker-intro/)
- [Object Oriented Programming (OOP) In Python - Beginner Crash Course](https://www.python-engineer.com/posts/oop-course/)
- [FastAPI Introduction - Build Your First Web App](https://www.python-engineer.com/posts/fastapi-introduction/)
- [5 Machine Learning BEGINNER Projects (+ Datasets & Solutions)](https://www.python-engineer.com/posts/machine-learning-beginner-projects/)
- [Build A PyTorch Style Transfer Web App With Streamlit](https://www.python-engineer.com/posts/pytorch-style-transfer-streamlit/)
- [How to use the Python Debugger using the breakpoint()](https://www.python-engineer.com/posts/python-debugger-and-breakpoint/)
- [How to use the interactive mode in Python.](https://www.python-engineer.com/posts/python-interactive-mode/)
- [Support Me On Patreon](https://www.python-engineer.com/posts/patreon-support/)
- [PyTorch Tutorial - RNN & LSTM & GRU - Recurrent Neural Nets](https://www.python-engineer.com/posts/pytorch-rnn-lstm-gru/)
- [freeCodeCamp.org Released My Intermediate Python Course](https://www.python-engineer.com/posts/freecodecamp-python-course/)
- [PyTorch RNN Tutorial - Name Classification Using A Recurrent Neural Net](https://www.python-engineer.com/posts/pytorch-rnn/)
- [PyTorch Lightning Tutorial - Lightweight PyTorch Wrapper For ML Researchers](https://www.python-engineer.com/posts/pytorch-lightning/)
- [My Minimal VS Code Setup for Python - 5 Visual Studio Code Extensions](https://www.python-engineer.com/posts/vscode-python-setup/)
- [NumPy Crash Course 2020 - Complete Tutorial](https://www.python-engineer.com/posts/numpy-crash-course/)
- [Create & Deploy A Deep Learning App - PyTorch Model Deployment With Flask & Heroku](https://www.python-engineer.com/posts/pytorch-model-deployment-with-flask/)
- [Snake Game In Python - Python Beginner Tutorial](https://www.python-engineer.com/posts/snake-game-in-python/)
- [11 Tips And Tricks To Write Better Python Code](https://www.python-engineer.com/posts/11-tips-to-write-better-python-code/)
- [Python Flask Beginner Tutorial - Todo App](https://www.python-engineer.com/posts/flask-todo-app/)
- [Chat Bot With PyTorch - NLP And Deep Learning](https://www.python-engineer.com/posts/chatbot-pytorch/)
- [Build A Beautiful Machine Learning Web App With Streamlit And Scikit-learn](https://www.python-engineer.com/posts/streamlit-tutorial/)
- [Website Rebuild With Publish (Static Site Generator)](https://www.python-engineer.com/posts/website-rebuild-with-publish/)
- [Build & Deploy A Python Web App To Automate Twitter \| Flask, Heroku, Twitter API & Google Sheets API](https://www.python-engineer.com/posts/tweet-scheduler-flask-heroku/)
- [How to work with the Google Sheets API and Python](https://www.python-engineer.com/posts/google-sheets-api/)
- [TinyDB in Python - Simple Database For Personal Projects](https://www.python-engineer.com/posts/tinydb/)
- [How To Load Machine Learning Data From Files In Python](https://www.python-engineer.com/posts/how-to-load-data/)
- [Regular Expressions in Python - ALL You Need To Know](https://www.python-engineer.com/posts/regular-expressions/)
- [Complete FREE Study Guide for Machine Learning and Deep Learning](https://www.python-engineer.com/posts/ml-study-guide/)
- [Machine Learning From Scratch in Python](https://www.python-engineer.com/posts/ml-from-scratch-guide/)
- [YouTube Data API Tutorial with Python - Analyze the Data - Part 4](https://www.python-engineer.com/posts/youtube-data-api-04/)
- [YouTube Data API Tutorial with Python - Get Video Statistics - Part 3](https://www.python-engineer.com/posts/youtube-data-api-03/)
- [YouTube Data API Tutorial with Python - Find Channel Videos - Part 2](https://www.python-engineer.com/posts/youtube-data-api-02/)
- [YouTube Data API Tutorial with Python - Analyze Channel Statistics - Part 1](https://www.python-engineer.com/posts/youtube-data-api-01/)
- [The Walrus Operator - New in Python 3.8](https://www.python-engineer.com/posts/walrus-operator/)
- [How To Add A Progress Bar In Python With Just One Line](https://www.python-engineer.com/posts/progressbar/)
- [List Comprehension in Python](https://www.python-engineer.com/posts/list-comprehension/)
- [Select Movies with Python - Web Scraping Tutorial](https://www.python-engineer.com/posts/movie-selection/)
- [Download Images With Python Automatically - Web Scraping Tutorial](https://www.python-engineer.com/posts/image-downloader/)
- [Anaconda Tutorial - Installation and Basic Commands](https://www.python-engineer.com/posts/anaconda-basics/)
- Courses
Courses
- Advanced Python
Advanced Python
- [Lists - Advanced Python 01](https://www.python-engineer.com/courses/advancedpython/01-lists/)
- [Tuples - Advanced Python 02](https://www.python-engineer.com/courses/advancedpython/02-tuples/)
- [Dictionary - Advanced Python 03](https://www.python-engineer.com/courses/advancedpython/03-dict/)
- [Sets - Advanced Python 04](https://www.python-engineer.com/courses/advancedpython/04-sets/)
- [Strings - Advanced Python 05](https://www.python-engineer.com/courses/advancedpython/05-strings/)
- [Collections - Advanced Python 06](https://www.python-engineer.com/courses/advancedpython/06-collections/)
- [Itertools - Advanced Python 07](https://www.python-engineer.com/courses/advancedpython/07-itertools/)
- [Lambda Functions - Advanced Python 08](https://www.python-engineer.com/courses/advancedpython/08-lambda/)
- [Exceptions And Errors - Advanced Python 09](https://www.python-engineer.com/courses/advancedpython/09-exceptions/)
- [Logging - Advanced Python 10](https://www.python-engineer.com/courses/advancedpython/10-logging/)
- [JSON - Advanced Python 11](https://www.python-engineer.com/courses/advancedpython/11-json/)
- [Random Numbers - Advanced Python 12](https://www.python-engineer.com/courses/advancedpython/12-random-numbers/)
- [Decorators - Advanced Python 13](https://www.python-engineer.com/courses/advancedpython/13-decorators/)
- [Generators - Advanced Python 14](https://www.python-engineer.com/courses/advancedpython/14-generators/)
- [Threading vs Multiprocessing - Advanced Python 15](https://www.python-engineer.com/courses/advancedpython/15-thread-vs-process/)
- [Multithreading - Advanced Python 16](https://www.python-engineer.com/courses/advancedpython/16-threading/)
- [Multiprocessing - Advanced Python 17](https://www.python-engineer.com/courses/advancedpython/17-multiprocessing/)
- [Function arguments - Advanced Python 18](https://www.python-engineer.com/courses/advancedpython/18-function-arguments/)
- [The Asterisk (\*) operator - Advanced Python 19](https://www.python-engineer.com/courses/advancedpython/19-asterisk/)
- [Shallow vs Deep Copying - Advanced Python 20](https://www.python-engineer.com/courses/advancedpython/20-copy/)
- [Context Managers - Advanced Python 21](https://www.python-engineer.com/courses/advancedpython/21-contextmanagers/)
- ML From Scratch
ML From Scratch
- [KNN (K Nearest Neighbors) in Python - ML From Scratch 01](https://www.python-engineer.com/courses/mlfromscratch/01_knn/)
- [Linear Regression in Python - ML From Scratch 02](https://www.python-engineer.com/courses/mlfromscratch/02_linearregression/)
- [Logistic Regression in Python - ML From Scratch 03](https://www.python-engineer.com/courses/mlfromscratch/03_logisticregression/)
- [Linear and Logistic Regression Refactoring- ML From Scratch 04](https://www.python-engineer.com/courses/mlfromscratch/04_linearandlogisticregression/)
- [Naive Bayes in Python - ML From Scratch 05](https://www.python-engineer.com/courses/mlfromscratch/05_naivebayes/)
- [Perceptron in Python - ML From Scratch 06](https://www.python-engineer.com/courses/mlfromscratch/06_perceptron/)
- [SVM (Support Vector Machine) in Python - ML From Scratch 07](https://www.python-engineer.com/courses/mlfromscratch/07_svm/)
- [Decision Tree in Python Part 1/2 - ML From Scratch 08](https://www.python-engineer.com/courses/mlfromscratch/08_decisiontree1/)
- [Decision Tree in Python Part 2/2 - ML From Scratch 09](https://www.python-engineer.com/courses/mlfromscratch/09_decisiontree2/)
- [Random Forest in Python - ML From Scratch 10](https://www.python-engineer.com/courses/mlfromscratch/10_randomforest/)
- [PCA (Principal Component Analysis) in Python - ML From Scratch 11](https://www.python-engineer.com/courses/mlfromscratch/11_pca/)
- [K-Means Clustering in Python - ML From Scratch 12](https://www.python-engineer.com/courses/mlfromscratch/12_kmeans/)
- [AdaBoost in Python - ML From Scratch 13](https://www.python-engineer.com/courses/mlfromscratch/13_adaboost/)
- [LDA (Linear Discriminant Analysis) In Python - ML From Scratch 14](https://www.python-engineer.com/courses/mlfromscratch/14-lda/)
- PyTorch
PyTorch
- [Installation - PyTorch Beginner 01](https://www.python-engineer.com/courses/pytorchbeginner/01-installation/)
- [Tensor Basics - PyTorch Beginner 02](https://www.python-engineer.com/courses/pytorchbeginner/02-tensor-basics/)
- [Autograd - PyTorch Beginner 03](https://www.python-engineer.com/courses/pytorchbeginner/03-autograd/)
- [Backpropagation - PyTorch Beginner 04](https://www.python-engineer.com/courses/pytorchbeginner/04-backpropagation/)
- [Gradient Descent Using Autograd - PyTorch Beginner 05](https://www.python-engineer.com/courses/pytorchbeginner/05-gradient-descent/)
- [Training Pipeline - PyTorch Beginner 06](https://www.python-engineer.com/courses/pytorchbeginner/06-training-pipeline/)
- [Linear Regression - PyTorch Beginner 07](https://www.python-engineer.com/courses/pytorchbeginner/07-linear-regression/)
- [Logistic Regression - PyTorch Beginner 08](https://www.python-engineer.com/courses/pytorchbeginner/08-logistic-regression/)
- [Dataset And Dataloader - PyTorch Beginner 09](https://www.python-engineer.com/courses/pytorchbeginner/09-dataset-and-dataloader/)
- [Dataset Transforms - PyTorch Beginner 10](https://www.python-engineer.com/courses/pytorchbeginner/10-dataset-transforms/)
- [Softmax And Cross Entropy - PyTorch Beginner 11](https://www.python-engineer.com/courses/pytorchbeginner/11-softmax-and-crossentropy/)
- [Activation Functions - PyTorch Beginner 12](https://www.python-engineer.com/courses/pytorchbeginner/12-activation-functions/)
- [Feed Forward Neural Network - PyTorch Beginner 13](https://www.python-engineer.com/courses/pytorchbeginner/13-feedforward-neural-network/)
- [Convolutional Neural Network (CNN) - PyTorch Beginner 14](https://www.python-engineer.com/courses/pytorchbeginner/14-cnn/)
- [Transfer Learning - PyTorch Beginner 15](https://www.python-engineer.com/courses/pytorchbeginner/15-transferlearning/)
- [Tensorboard - PyTorch Beginner 16](https://www.python-engineer.com/courses/pytorchbeginner/16-tensorboard/)
- [Saving And Loading Models - PyTorch Beginner 17](https://www.python-engineer.com/courses/pytorchbeginner/17-saving-and-loading/)
- TensorFlow
TensorFlow
- [Installation - TensorFlow Beginner 01](https://www.python-engineer.com/courses/tensorflowbeginner/01-installation/)
- [Tensor Basics - TensorFlow Beginner 02](https://www.python-engineer.com/courses/tensorflowbeginner/02-tensor-basics/)
- [Neural Net - TensorFlow Beginner 03](https://www.python-engineer.com/courses/tensorflowbeginner/03-neuralnet/)
- [Regression - TensorFlow Beginner 04](https://www.python-engineer.com/courses/tensorflowbeginner/04-regression/)
- [Convolutional Neural Net (CNN) - TensorFlow Beginner 05](https://www.python-engineer.com/courses/tensorflowbeginner/05-cnn/)
- [Saving And Loading Models - TensorFlow Beginner 06](https://www.python-engineer.com/courses/tensorflowbeginner/06-saving-and-loading/)
- [Functional API -TensorFlow Beginner 07](https://www.python-engineer.com/courses/tensorflowbeginner/07-functionalAPI/)
- [Classify Lego Star Wars Minifigures - TensorFlow Beginner 08](https://www.python-engineer.com/courses/tensorflowbeginner/08-legoproject/)
- [Transfer Learning - TensorFlow Beginner 09](https://www.python-engineer.com/courses/tensorflowbeginner/09-transferlearning/)
- [Recurrent Neural Nets (RNN) - TensorFlow Beginner 10](https://www.python-engineer.com/courses/tensorflowbeginner/10-rnn/)
- [Text Classification - NLP Tutorial - TensorFlow Beginner 11](https://www.python-engineer.com/courses/tensorflowbeginner/11-nlp-text-classification/)
- Tags
Tags
- [Tags](https://www.python-engineer.com/tags/)
- Authors
Authors
- [Authors](https://www.python-engineer.com/authors/)
- [About](https://www.python-engineer.com/about/)
- [Newsletter](https://www.python-engineer.com/newsletter/)
On this page
- [1\. Type and OOP](https://www.python-engineer.com/posts/metaclasses-python/#1-type-and-oop)
- [2\. Understanding the type() function](https://www.python-engineer.com/posts/metaclasses-python/#2-understanding-the-type-function)
- [Creating classes dynamically using type()](https://www.python-engineer.com/posts/metaclasses-python/#creating-classes-dynamically-using-type)
- [3\. Creating Metaclass](https://www.python-engineer.com/posts/metaclasses-python/#3-creating-metaclass)
- [4\. Modifying a class state using Metaclass](https://www.python-engineer.com/posts/metaclasses-python/#4-modifying-a-class-state-using-metaclass)
- [5\. Use proper OOP principles](https://www.python-engineer.com/posts/metaclasses-python/#5-use-proper-oop-principles)
- [6\. When to use metaclasses?](https://www.python-engineer.com/posts/metaclasses-python/#6-when-to-use-metaclasses)
# What are metaclasses in Python
**A beginners guide to metaclasses in Python.**

**Pratik Choudhari** · · · February 07, 2022 · 9 min read
[Python](https://www.python-engineer.com/tags/#python) [Basics](https://www.python-engineer.com/tags/#basics)
***
Metaclass is an advanced Python concept and is not used in day-to-day programming tasks. They allow a user to precisely define a class state, change its attributes and control method behavior.
\#more
In this article, we will understand how metaclasses can be created and used in Python.
## 1\. Type and OOP[¶](https://www.python-engineer.com/posts/metaclasses-python/#1-type-and-oop "Permanent link")
Everything is an object in Python, including classes. Hence, if classes are an object, they must be created by another class also called as Metaclass.

So, a metaclass is just another class that creates class objects. Usually, `type` is the built-in metaclass Python uses for every class. But we can also create our own metaclasses with custom behavior.
## 2\. Understanding the `type()` function[¶](https://www.python-engineer.com/posts/metaclasses-python/#2-understanding-the-type-function "Permanent link")
To fully understand Metaclasses, one needs to thoroughly understand `type()`.
In Python, `type()` is used to identify the data type of a variable. If we have the following code
```
```
Console output would be:
```
<class 'int'>
```
Indicating `var` is an instance of the class `int`.
In the case of a user-defined class, we get the following output.
```
```
```
```
Here, we can see `foo_obj` is correctly identified as an instance of class `Foo`, but the type of class `Foo` indicates that it is an instance of class `type`, establishing the point that classes are indeed created by other classes.
## Creating classes dynamically using `type()`[¶](https://www.python-engineer.com/posts/metaclasses-python/#creating-classes-dynamically-using-type "Permanent link")
This is one more concept we should know before diving into metaclasses.
This usage of `type()` is fairly unknown. The `type()` function can take three arguments and can be used to create classes dynamically:
```
type(name: str, bases: tuple, attributes: dict)
```
- `name` indicates the name of a class
- `bases` is a tuple of classes to be inherited
- `attributes` is a dictionary including all variables and methods to be declared inside the new class
Example:
```
```
Output:
```
lorem ipsum sit domat
```
## 3\. Creating Metaclass[¶](https://www.python-engineer.com/posts/metaclasses-python/#3-creating-metaclass "Permanent link")
The main purpose of a metaclass is to change the class automatically when it's created.
To use class as a metaclass we pass `metaclass=ClassName` as a class parameter. The metaclass itself is implemented like a normal class with any behavior we want. Usually the `__new__` function is implemented.
The name of the metaclass should ideally make the intent of the class clear:
Example:
```
```
Output:
```
Attributes received in PrintAttributeMeta: {'__module__': '__main__', '__qualname__': 'Dummy', 'class_var1': 'lorem', 'class_var2': 45}
```
This meta class simply prints all attributes, and then creates and returns a new class by using the `type()` function.
Note that there’s output without creating an instance of the class because the `__new__()` method is called when the class is created.
## 4\. Modifying a class state using Metaclass[¶](https://www.python-engineer.com/posts/metaclasses-python/#4-modifying-a-class-state-using-metaclass "Permanent link")
Using Metaclasses, the user can perform multitude of validations and modification such as changing variable names, raising error on receiving an invalid data type, checking inheritance levels, etc.
For this example, we will write a Metaclass that raises a `ValueError` when a negative value is received in `attributes`.
```
```
Output:
```
```
We could also change attributes:
```
```
## 5\. Use proper OOP principles[¶](https://www.python-engineer.com/posts/metaclasses-python/#5-use-proper-oop-principles "Permanent link")
In the previous example we are calling `type` directly and aren't overriding or calling the parent's `__new__`. Let's do that instead:
```
```
Now our metaclass inherits from `type`, and by calling the `super.__new__()` we are using the OOP syntax and call the `__new__()` function of the base class.
## 6\. When to use metaclasses?[¶](https://www.python-engineer.com/posts/metaclasses-python/#6-when-to-use-metaclasses "Permanent link")
There are several reasons to do so:
- The intention is clear. When you read PositiveNumbersMeta, you know what's going to follow
- You can use OOP. Metaclass can inherit from metaclass, override parent methods, etc. Metaclasses can even use other metaclasses.
- You can structure your code better. You never use metaclasses for something as trivial as the above example. It's usually for something complicated. Having the ability to make several methods and group them in one class is very useful to make the code easier to read.
- You can hook on `__new__`, `__init__` and `__call__`. Which will allow you to do different stuff, Even if usually you can do it all in `__new__`, some people are just more comfortable using `__init__`.
Resource: Here's a great [StackOverflow answer](https://stackoverflow.com/questions/100003/what-are-metaclasses-in-python) that explains it well.
Note that Metaclasses are usually only used in more complex scenarios, and in 99% of cases you don't have to worry about it. One common use case is when creating an API. A typical example of this is the [Django ORM](https://docs.djangoproject.com/en/4.0/topics/db/models/).
***
FREE VS Code / PyCharm Extensions I Use
✅ Write cleaner code with Sourcery, instant refactoring suggestions: [Link\*](https://sourcery.ai/?utm_source=youtube&utm_campaign=pythonengineer)
***
Python Problem-Solving Bootcamp
🚀 Solve 42 programming puzzles over the course of 21 days: [Link\*](https://www.python-engineer.com/go/sponsor-pythonbootcamp)
\* These are affiliate link. By clicking on it you will not have any additional costs. Instead, you will support my project. Thank you! 🙏
***
[Previous Working with Images in OpenCV using Python](https://www.python-engineer.com/posts/opencv-images/)
[Next How to randomly select an item from a list?](https://www.python-engineer.com/posts/randomly-select-item/)
Copyright © 2023 Patrick Loeber
Made with [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/)
[Privacy Policy](https://www.python-engineer.com/privacy-policy/) · [Legal Notice](https://www.python-engineer.com/legal-notice/) |
| Readable Markdown | **A beginners guide to metaclasses in Python.**
[Python](https://www.python-engineer.com/tags/#python) [Basics](https://www.python-engineer.com/tags/#basics)
***
Metaclass is an advanced Python concept and is not used in day-to-day programming tasks. They allow a user to precisely define a class state, change its attributes and control method behavior.
In this article, we will understand how metaclasses can be created and used in Python.
## 1\. Type and OOP[¶](https://www.python-engineer.com/posts/metaclasses-python/#1-type-and-oop "Permanent link")
Everything is an object in Python, including classes. Hence, if classes are an object, they must be created by another class also called as Metaclass.

So, a metaclass is just another class that creates class objects. Usually, `type` is the built-in metaclass Python uses for every class. But we can also create our own metaclasses with custom behavior.
## 2\. Understanding the `type()` function[¶](https://www.python-engineer.com/posts/metaclasses-python/#2-understanding-the-type-function "Permanent link")
To fully understand Metaclasses, one needs to thoroughly understand `type()`.
In Python, `type()` is used to identify the data type of a variable. If we have the following code
```
```
Console output would be:
```
<class 'int'>
```
Indicating `var` is an instance of the class `int`.
In the case of a user-defined class, we get the following output.
```
```
```
```
Here, we can see `foo_obj` is correctly identified as an instance of class `Foo`, but the type of class `Foo` indicates that it is an instance of class `type`, establishing the point that classes are indeed created by other classes.
## Creating classes dynamically using `type()`[¶](https://www.python-engineer.com/posts/metaclasses-python/#creating-classes-dynamically-using-type "Permanent link")
This is one more concept we should know before diving into metaclasses.
This usage of `type()` is fairly unknown. The `type()` function can take three arguments and can be used to create classes dynamically:
```
type(name: str, bases: tuple, attributes: dict)
```
- `name` indicates the name of a class
- `bases` is a tuple of classes to be inherited
- `attributes` is a dictionary including all variables and methods to be declared inside the new class
Example:
```
```
Output:
```
lorem ipsum sit domat
```
The main purpose of a metaclass is to change the class automatically when it's created.
To use class as a metaclass we pass `metaclass=ClassName` as a class parameter. The metaclass itself is implemented like a normal class with any behavior we want. Usually the `__new__` function is implemented.
The name of the metaclass should ideally make the intent of the class clear:
Example:
```
```
Output:
```
Attributes received in PrintAttributeMeta: {'__module__': '__main__', '__qualname__': 'Dummy', 'class_var1': 'lorem', 'class_var2': 45}
```
This meta class simply prints all attributes, and then creates and returns a new class by using the `type()` function.
Note that there’s output without creating an instance of the class because the `__new__()` method is called when the class is created.
Using Metaclasses, the user can perform multitude of validations and modification such as changing variable names, raising error on receiving an invalid data type, checking inheritance levels, etc.
For this example, we will write a Metaclass that raises a `ValueError` when a negative value is received in `attributes`.
```
```
Output:
```
```
We could also change attributes:
```
```
## 5\. Use proper OOP principles[¶](https://www.python-engineer.com/posts/metaclasses-python/#5-use-proper-oop-principles "Permanent link")
In the previous example we are calling `type` directly and aren't overriding or calling the parent's `__new__`. Let's do that instead:
```
```
Now our metaclass inherits from `type`, and by calling the `super.__new__()` we are using the OOP syntax and call the `__new__()` function of the base class.
There are several reasons to do so:
- The intention is clear. When you read PositiveNumbersMeta, you know what's going to follow
- You can use OOP. Metaclass can inherit from metaclass, override parent methods, etc. Metaclasses can even use other metaclasses.
- You can structure your code better. You never use metaclasses for something as trivial as the above example. It's usually for something complicated. Having the ability to make several methods and group them in one class is very useful to make the code easier to read.
- You can hook on `__new__`, `__init__` and `__call__`. Which will allow you to do different stuff, Even if usually you can do it all in `__new__`, some people are just more comfortable using `__init__`.
Resource: Here's a great [StackOverflow answer](https://stackoverflow.com/questions/100003/what-are-metaclasses-in-python) that explains it well.
Note that Metaclasses are usually only used in more complex scenarios, and in 99% of cases you don't have to worry about it. One common use case is when creating an API. A typical example of this is the [Django ORM](https://docs.djangoproject.com/en/4.0/topics/db/models/).
***
FREE VS Code / PyCharm Extensions I Use
✅ Write cleaner code with Sourcery, instant refactoring suggestions: [Link\*](https://sourcery.ai/?utm_source=youtube&utm_campaign=pythonengineer)
***
Python Problem-Solving Bootcamp
🚀 Solve 42 programming puzzles over the course of 21 days: [Link\*](https://www.python-engineer.com/go/sponsor-pythonbootcamp)
\* These are affiliate link. By clicking on it you will not have any additional costs. Instead, you will support my project. Thank you! 🙏
*** |
| ML Classification | |
| ML Categories | null |
| ML Page Types | null |
| ML Intent Types | null |
| Content Metadata | |
| Language | en |
| Author | null |
| Publish Time | not set |
| Original Publish Time | 2022-11-26 22:52:01 (3 years ago) |
| Republished | No |
| Word Count (Total) | 3,282 |
| Word Count (Content) | 1,143 |
| Links | |
| External Links | 16 |
| Internal Links | 249 |
| Technical SEO | |
| Meta Nofollow | No |
| Meta Noarchive | No |
| JS Rendered | No |
| Redirect Target | null |
| Performance | |
| Download Time (ms) | 803 |
| TTFB (ms) | 473 |
| Download Size (bytes) | 17,494 |
| Shard | 54 (laksa) |
| Root Hash | 10843413975543007054 |
| Unparsed URL | com,python-engineer!www,/posts/metaclasses-python/ s443 |