Have a look at abc module. For 2.7: link. For 3.6: link Simple example for you:

from abc import ABC, abstractmethod

class A(ABC):
    def __init__(self, value):
        self.value = value
        super().__init__()

    @abstractmethod
    def do_something(self):
        pass


class B(A):
    @abstractmethod
    def do_something_else(self):
        pass

class C(B):
    def do_something(self):
        pass

    def do_something_else(self):
        pass
Answer from luminousmen on Stack Overflow
🌐
Python
docs.python.org › 3 › library › abc.html
abc — Abstract Base Classes
This module provides the metaclass ABCMeta for defining ABCs and a helper class ABC to alternatively define ABCs through inheritance: ... A helper class that has ABCMeta as its metaclass. With this class, an abstract base class can be created by simply deriving from ABC avoiding sometimes confusing ...
Discussions

inheritance - Abstract methods in Python - Stack Overflow
I am having trouble in using inheritance with Python. While the concept seems too easy for me in Java yet up till now I have been unable to understand in Python which is surprising to me at least. I More on stackoverflow.com
🌐 stackoverflow.com
object oriented - Abstract base classes and mix-ins in python - Software Engineering Stack Exchange
Should my concrete classes then only inherit from the mixin, or from both the mixin and ABC? If it's up to me either way, what do you gain or lose from each approach? Is this even the correct way to use a mixin? ... In any language, the typical motivation for defining an Interface or Abstract class ... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
May 1, 2023
Should we use an abstract class when we know a parent class should never be directly accessed?
Why not a non-class module, so instances aren't possible at all? More on reddit.com
🌐 r/learnpython
9
1
October 4, 2021
How to create abstract properties in python abstract classes? - Stack Overflow
I want all the classes that inherit from Base to provide the name property, so I made this property an @abstractmethod. Then I created a subclass of Base, called Base_1, which is meant to supply some functionality, but still remain abstract. There is no name property in Base_1, but nevertheless python ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Medium
elfi-y.medium.com › inheritance-in-python-with-abstract-base-class-abc-5e3b8e910e5e
Inheritance in Python with Abstract Base Class(ABC) | by E.Y. | Medium
January 13, 2021 - A class that has a metaclass derived from ABCMeta cannot be instantiated unless all of its abstract methods and properties are overridden. The abstract methods can be called using any of the normal ‘super’ call mechanisms. Note that the abstractmethod() only affects subclasses derived using regular inheritance; “virtual subclasses” registered with register() method are not affected.
🌐
DataCamp
datacamp.com › tutorial › python-abstract-classes
Python Abstract Classes: A Comprehensive Guide with Examples | DataCamp
January 22, 2025 - The ABC class is a built-in Python feature that serves as a fundamental basis for developing abstract classes. You must inherit from ABC to define an abstract class. The class is abstract and cannot be instantiated directly, as indicated by this inheritance.
🌐
Python Course
python-course.eu › oop › the-abc-of-abstract-base-classes.php
20. The 'ABC' of Abstract Base Classes | OOP | python-course.eu
This impression is wrong: An abstract method can have an implementation in the abstract class! Even if they are implemented, designers of subclasses will be forced to override the implementation. Like in other cases of "normal" inheritance, the abstract method can be invoked with super() call mechanism.
🌐
CodeSignal
codesignal.com › learn › courses › revisiting-oop-concepts-in-python › lessons › understanding-abstract-classes-and-abstract-methods-in-python
Understanding Abstract Classes and Abstract Methods in ...
Think of it as a blueprint for other classes. It often includes one or more abstract methods. A class that inherits from an abstract class must implement all its abstract methods. In Python, the abc (Abstract Base Classes) module provides tools for defining abstract base classes.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › abstract-classes-in-python
Abstract Classes in Python - GeeksforGeeks
An Abstract Base Class (ABC) defines methods that must be implemented by its subclasses, ensuring that the subclasses follow a consistent structure. ABCs allow you to define common interfaces that various subclasses can implement while enforcing a level of abstraction. Python provides the abc module to define ABCs and enforce the implementation of abstract methods in subclasses.
Published   September 3, 2025
Top answer
1 of 1
1

There are generally many good ways to implement this. However, everyone have their own preferences, so mostly which of the following you use is up to you. Here's the three approaches:

  1. Do it the way you are currently implementing it. For a basic structure, it'll be something similar to this:
from abc import ABCMeta

class Abstract(metaclass=ABCMeta):
    def write(self):
        raise NotImplementedError()

class Mixin():
    def meth1(self, *args, **kwargs):
        """ do something here"""

class ActualUsefulImplementedClass(Abstract, Mixin):
    """ write your methods here. You will have access to all the helper methods of the mix-in class."""
  1. Implementing the methods as functions (presumably in another file in the same directory as the current file) and call them from inside the class will also be OK:
from abc import ABCMeta
from helpers import func1, func2, func3, ...

class Abstract(metaclass=ABCMeta):
    def write(self):
        raise NotImplementedError()

class ActualUsefulImplementedClass(Abstract, Mixin):
    """ write your methods here. Access the helper functions imported above directly in your methods."""
    # for example
    def do_something(self, *args, **kwargs):
        func1(*args)

This approach does have it's drawbacks, namely:

  • If by any chance your helper methods acts on an instance of some self-defined class, then this approach will break. Of course, you can pass-in the instance as an argument, but that is a very, very bad idea in terms of software engineering ideas and principles.
  • Also, if you want to inherit them once and have access to them without additional code for all of the ActualUsefulImplementedClass's subclasses, then this approach doesn't fit the bill.
  • Finally, if you want a strictly OOP approach, or don't want the helper functions to pollute your current module scope's namespace, then this isn't the best fit as well.
  1. Similar to the first approach stated above (number 1), but create another middle-level class that doesn't use the mix-in. It will be something like the following:
from abc import ABCMeta

class Abstract(metaclass=ABCMeta):
    def write(self):
        raise NotImplementedError()

class Mixin():
    def meth1(self, *args, **kwargs):
        """ do something here"""

class MiddleMan(Abstract):
    """ write your methods here. You will not have access to the helper methods of the mix-in class."""

class ActualUsefulImplementedClass(MiddleMan, Mixin):
    """ You will have both the actual method implementations and the helper methods here without much or any code."""

However, the above code will only work if you don't need the helper methods inside your methods' implementations and only need them outside of the class. If you need them inside the methods' code, then use the first approach. If you only need the helpers outside of the class, then use this approach.


Note: I use docstrings in the line immediately after the class or method definition line whenever applicable. It describes some of the abilities and limitations of the approach, so please read them as well.

🌐
Python Tutorial
pythontutorial.net › home › python oop › python abstract classes
Python Abstract Class
March 31, 2025 - Summary: in this tutorial, you’ll learn about Python Abstract classes and how to use it to create a blueprint for other classes. In object-oriented programming, an abstract class is a class that cannot be instantiated. However, you can create classes that inherit from an abstract class.
🌐
Reddit
reddit.com › r/learnpython › should we use an abstract class when we know a parent class should never be directly accessed?
r/learnpython on Reddit: Should we use an abstract class when we know a parent class should never be directly accessed?
October 4, 2021 -

I'm attempting to code something to perform a computation and I'm a bit unsure on how to handle inheriting. The idea is that there are a few "compute" classes that each do something a bit different from one another, but nevertheless share some underlying functionality. So I have a "parent" class that they each inherit from. However, there will never be a reason to directly access the parent class though. Should I be using an abstract class? I think these might be relevant since they are used to mix into the classes but aren't directly accessed. Although I don't know if this is really necessary or the best way to go about this.

🌐
Towards Data Science
towardsdatascience.com › home › latest › how to use abstract classes in python
How to Use Abstract Classes in Python | Towards Data Science
January 21, 2025 - We can create an abstract class by inheriting from the ABC class which is part of the abc module.
🌐
Real Python
realpython.com › inheritance-composition-python
Inheritance and Composition: A Python OOP Guide – Real Python
January 11, 2025 - The Employee class in the example above is what is called an abstract base class. Abstract base classes exist to be inherited, but never instantiated. Python provides the abc module to formally define abstract base classes.
🌐
Dive into Python
diveintopython.org › home › learn python programming › classes in python › abstract classes
Abstract Base Classes in Python - Learn How to Create and Use Them
May 3, 2024 - A class that inherits from an abstract base class must implement all the abstract methods declared in the base class, unless it is also an abstract class. An abstract class is a Python class that cannot be instantiated, and it is used to define ...
🌐
Real Python
realpython.com › lessons › abstract-classes
Abstract Classes (Video) – Real Python
The Employee class exists just to be inherited from—not to be instantiated itself. That means it’s what’s called an abstract class. 01:56 We can’t instantiate it, but only inherit from it. In order to utilize a helpful abstract decorator, 02:05 we can import some special modules in the Python standard library.
Published   April 14, 2020
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › abstract class in python
Abstract Class in Python | With Example and Interface Comparison
June 1, 2025 - Dog inherits from Animal and implements the sound() method, providing the required functionality for the abstract method. ... Unlike Animal, we can instantiate Dog because it has provided implementations for all abstract methods. In this case, the sound() method returns "Bark" when called. ... Abstract classes are meant to serve as blueprints for other classes. By preventing direct instantiation, Python ensures that an abstract class cannot be used before a subclass fully implements it.
🌐
CodeFatherTech
codefather.tech › home › blog › create an abstract class in python: a step-by-step guide
Create an Abstract Class in Python: A Step-By-Step Guide
December 8, 2024 - A child class of an abstract class can be instantiated only if it overrides all the abstract methods in the parent class. The term override in Python inheritance indicates that a child class implements a method with the same name as a method implemented in its parent class.
Top answer
1 of 13
760

Use the abc module to create abstract classes. Use the abstractmethod decorator to declare a method abstract, and declare a class abstract using one of three ways, depending upon your Python version.

In Python 3.4 and above, you can inherit from ABC. In earlier versions of Python, you need to specify your class's metaclass as ABCMeta. Specifying the metaclass has different syntax in Python 3 and Python 2. The three possibilities are shown below:

Copy# Python 3.4+
from abc import ABC, abstractmethod
class Abstract(ABC):
    @abstractmethod
    def foo(self):
        pass
Copy# Python 3.0+
from abc import ABCMeta, abstractmethod
class Abstract(metaclass=ABCMeta):
    @abstractmethod
    def foo(self):
        pass
Copy# Python 2
from abc import ABCMeta, abstractmethod
class Abstract:
    __metaclass__ = ABCMeta

    @abstractmethod
    def foo(self):
        pass

Whichever way you use, you won't be able to instantiate an abstract class that has abstract methods, but will be able to instantiate a subclass that provides concrete definitions of those methods:

>>> Abstract()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't instantiate abstract class Abstract with abstract methods foo
>>> class StillAbstract(Abstract):
...     pass
... 
>>> StillAbstract()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't instantiate abstract class StillAbstract with abstract methods foo
>>> class Concrete(Abstract):
...     def foo(self):
...         print('Hello, World')
... 
>>> Concrete()
<__main__.Concrete object at 0x7fc935d28898>
2 of 13
152

The old-school (pre-PEP 3119) way to do this is just to raise NotImplementedError in the abstract class when an abstract method is called.

Copyclass Abstract(object):
    def foo(self):
        raise NotImplementedError('subclasses must override foo()!')

class Derived(Abstract):
    def foo(self):
        print 'Hooray!'

>>> d = Derived()
>>> d.foo()
Hooray!
>>> a = Abstract()
>>> a.foo()
Traceback (most recent call last): [...]

This doesn't have the same nice properties as using the abc module does. You can still instantiate the abstract base class itself, and you won't find your mistake until you call the abstract method at runtime.

But if you're dealing with a small set of simple classes, maybe with just a few abstract methods, this approach is a little easier than trying to wade through the abc documentation.