What you'll see sometimes is the following:

class Abstract1:
    """Some description that tells you it's abstract,
    often listing the methods you're expected to supply."""

    def aMethod(self):
        raise NotImplementedError("Should have implemented this")

Because Python doesn't have (and doesn't need) a formal Interface contract, the Java-style distinction between abstraction and interface doesn't exist. If someone goes through the effort to define a formal interface, it will also be an abstract class. The only differences would be in the stated intent in the docstring.

And the difference between abstract and interface is a hairsplitting thing when you have duck typing.

Java uses interfaces because it doesn't have multiple inheritance.

Because Python has multiple inheritance, you may also see something like this

class SomeAbstraction:
    pass  # lots of stuff - but missing something

class Mixin1:
    def something(self):
        pass  # one implementation

class Mixin2:
    def something(self):
        pass  # another

class Concrete1(SomeAbstraction, Mixin1):
    pass

class Concrete2(SomeAbstraction, Mixin2):
    pass

This uses a kind of abstract superclass with mixins to create concrete subclasses that are disjoint.

Answer from S.Lott on Stack Overflow
Top answer
1 of 8
693

What you'll see sometimes is the following:

class Abstract1:
    """Some description that tells you it's abstract,
    often listing the methods you're expected to supply."""

    def aMethod(self):
        raise NotImplementedError("Should have implemented this")

Because Python doesn't have (and doesn't need) a formal Interface contract, the Java-style distinction between abstraction and interface doesn't exist. If someone goes through the effort to define a formal interface, it will also be an abstract class. The only differences would be in the stated intent in the docstring.

And the difference between abstract and interface is a hairsplitting thing when you have duck typing.

Java uses interfaces because it doesn't have multiple inheritance.

Because Python has multiple inheritance, you may also see something like this

class SomeAbstraction:
    pass  # lots of stuff - but missing something

class Mixin1:
    def something(self):
        pass  # one implementation

class Mixin2:
    def something(self):
        pass  # another

class Concrete1(SomeAbstraction, Mixin1):
    pass

class Concrete2(SomeAbstraction, Mixin2):
    pass

This uses a kind of abstract superclass with mixins to create concrete subclasses that are disjoint.

2 of 8
231

What is the difference between abstract class and interface in Python?

An interface, for an object, is a set of methods and attributes on that object.

In Python, we can use an abstract base class to define and enforce an interface.

Using an Abstract Base Class

For example, say we want to use one of the abstract base classes from the collections module:

import collections
class MySet(collections.Set):
    pass

If we try to use it, we get an TypeError because the class we created does not support the expected behavior of sets:

>>> MySet()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't instantiate abstract class MySet with abstract methods
__contains__, __iter__, __len__

So we are required to implement at least __contains__, __iter__, and __len__. Let's use this implementation example from the documentation:

class ListBasedSet(collections.Set):
    """Alternate set implementation favoring space over speed
    and not requiring the set elements to be hashable. 
    """
    def __init__(self, iterable):
        self.elements = lst = []
        for value in iterable:
            if value not in lst:
                lst.append(value)
    def __iter__(self):
        return iter(self.elements)
    def __contains__(self, value):
        return value in self.elements
    def __len__(self):
        return len(self.elements)

s1 = ListBasedSet('abcdef')
s2 = ListBasedSet('defghi')
overlap = s1 & s2

Implementation: Creating an Abstract Base Class

We can create our own Abstract Base Class by setting the metaclass to abc.ABCMeta and using the abc.abstractmethod decorator on relevant methods. The metaclass will be add the decorated functions to the __abstractmethods__ attribute, preventing instantiation until those are defined.

import abc

For example, "effable" is defined as something that can be expressed in words. Say we wanted to define an abstract base class that is effable, in Python 2:

class Effable(object):
    __metaclass__ = abc.ABCMeta
    @abc.abstractmethod
    def __str__(self):
        raise NotImplementedError('users must define __str__ to use this base class')

Or in Python 3, with the slight change in metaclass declaration:

class Effable(object, metaclass=abc.ABCMeta):
    @abc.abstractmethod
    def __str__(self):
        raise NotImplementedError('users must define __str__ to use this base class')

Now if we try to create an effable object without implementing the interface:

class MyEffable(Effable): 
    pass

and attempt to instantiate it:

>>> MyEffable()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't instantiate abstract class MyEffable with abstract methods __str__

We are told that we haven't finished the job.

Now if we comply by providing the expected interface:

class MyEffable(Effable): 
    def __str__(self):
        return 'expressable!'

we are then able to use the concrete version of the class derived from the abstract one:

>>> me = MyEffable()
>>> print(me)
expressable!

There are other things we could do with this, like register virtual subclasses that already implement these interfaces, but I think that is beyond the scope of this question. The other methods demonstrated here would have to adapt this method using the abc module to do so, however.

Conclusion

We have demonstrated that the creation of an Abstract Base Class defines interfaces for custom objects in Python.

๐ŸŒ
Medium
medium.com โ€บ @shashikantrbl123 โ€บ interfaces-and-abstract-classes-in-python-understanding-the-differences-3e5889a0746a
Interfaces and Abstract Classes in Python: Understanding the Differences | by Shashi Kant | Medium
April 10, 2023 - In this blog post, we explored the concepts of interfaces and abstract classes in Python. We saw that interfaces define a contract between a class and its users, while abstract classes define a common interface for a group of related classes.
๐ŸŒ
Real Python
realpython.com โ€บ python-interface
Implementing an Interface in Python โ€“ Real Python
February 21, 2024 - The abstract method must be overridden by the concrete class that implements the interface in question. To create abstract methods in Python, you add the @abc.abstractmethod decorator to the interfaceโ€™s methods. In the next example, you update the FormalParserInterface to include the abstract methods .load_data_source() and .extract_text():
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ difference-between-abstract-class-and-interface-in-python
Difference between abstract class and interface in Python - GeeksforGeeks
July 23, 2025 - An abstract class is used to offer a standard interface for various implementations of a component. ... Python does not come with any abstract classes by default. Python has a module called ABC that serves as the foundation for building Abstract ...
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ abc.html
abc โ€” Abstract Base Classes
In addition, the collections.abc ... interface, for example, if it is hashable or if it is a mapping. 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 ...
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Difference between interface and abstracts - Python Help - Discussions on Python.org
September 8, 2023 - Hi @all Could you explain what is the actual difference between interface and abstracts in python programming, what we can achieve by using two? What is the concept of oops behind the scene here? How oops concepts is โ€ฆ
๐ŸŒ
k0nze
k0nze.dev โ€บ posts โ€บ python-interfaces-abstract-classes
Pythonโ€™s Abstract Base Classes (ABC) and Interfaces Explained (With Code Snippets) | k0nze
February 22, 2024 - It is possible to give a method decorated with @abstractmethod an implementation in the interface but this implementation is never used because all implementers need to override it. Using the Python abc module, you can now implement abstract classes and interfaces in the same way as in the Java example above.
๐ŸŒ
Medium
medium.com โ€บ @abdelrhmannasser โ€บ when-to-use-abstract-classes-vs-interfaces-in-python-clear-examples-and-explanations-6b8553a16013
When to Use Abstract Classes vs. Interfaces in Python: Clear Examples and Explanations | by Abdelrahman Nasser | Medium
September 3, 2024 - Unlike abstract classes, interfaces cannot contain any implementation โ€” only method declarations. Any class that implements an interface is obligated to provide concrete implementations for all its methods.
Find elsewhere
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-interface
Understand Python Interfaces - Python Guides
December 1, 2025 - It specifies a set of methods that ... Python does not have a built-in interface keyword like some other languages, it uses the abc module to create abstract base classes that serve as interfaces....
๐ŸŒ
TutsWiki
tutswiki.com โ€บ abstract-classes-and-interfaces-in-python
Abstract classes and interfaces in Python :: TutsWiki Beta
Abstract base classes and interfaces are entities that are similar in purpose and meaning. Both the first and second are a peculiar way of documenting the code and help to limit (decouple) the interaction of individual abstractions in the program (classes). Python is a very flexible language.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Python Interfaces and Abstract Base Class (ABC): A Must-Know for Advanced Programmers - YouTube
Take your Python programming skills to the next level with this must-know topic: interfaces and abstract classes. Learn how to implement these important conc...
Published ย  February 22, 2024
๐ŸŒ
QuickStart
quickstart.com โ€บ blog โ€บ software-engineering โ€บ when-and-how-to-use-abstract-class-and-interface
Abstract Class vs Interface| OOP, Python, C+ | Software Engineering
September 24, 2024 - Abstract classes provide a blueprint for classes, allowing a mix of abstract and concrete methods, while interfaces define contracts for classes, supporting multiple inheritance and enforcing method implementation.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ abstract-classes-in-python
Abstract Classes in Python - GeeksforGeeks
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 ย  December 13, 2024
๐ŸŒ
W3Resource
w3resource.com โ€บ python-interview โ€บ how-do-you-achieve-abstraction-using-abstract-classes-or-interfaces-in-python.php
Achieving abstraction: Abstract classes and interfaces in Python
August 16, 2023 - Abstract classes define a common interface for their subclasses, while interfaces define a set of methods that must be implemented by classes that implement the interface. The use of abstract classes and interfaces allows you to create a high-level ...
๐ŸŒ
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 ...
In Python, the abc (Abstract Base Classes) module provides tools for defining abstract base classes. An abstract base class is a class that cannot be instantiated directly and often includes one or more abstract methods. These classes serve as blueprints for other classes, enforcing a consistent ...
๐ŸŒ
w3resource
w3resource.com โ€บ python โ€บ python-abstract-classes-and-interfaces.php
Understanding Python Abstraction: Abstract Classes & Interfaces
August 23, 2024 - Abstract Classes: Created using ... Python doesnโ€™t have interfaces as a built-in concept, but abstract classes with only abstract methods can act as interfaces....
๐ŸŒ
Plain English
python.plainenglish.io โ€บ data-classes-abstraction-interfaces-in-python-ea107d235d3e
Data Classes, Abstraction, and Interfaces in Python | Python in Plain English
October 11, 2022 - If we choose engine as our domain concept, then we can create an engine abstract class, then we can create child classes from abstract parents like a diesel engine, etc. And we can create sub-functionalities for engines as interfaces. Python does not have a format interface contact, and Java-style ...
๐ŸŒ
Just Academy
justacademy.co โ€บ blog-detail โ€บ difference-between-abstract-class-and-interface-in-python
Difference Between Abstract Class And Interface In Python
It can contain both implemented methods and abstract methods (methods without a body that must be implemented by subclasses). On the other hand, an interface in Python is a collection of abstract methods that a class can implement.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-abstract-classes
Python Abstract Classes: A Comprehensive Guide with Examples | DataCamp
January 22, 2025 - The abc module in Python offers strong built-in support for abstract classes. The module, which stands for "Abstract Base Classes," gives programmers the necessary tools to create abstract classes, including the abstractmethod decorator and the ABC class. By defining abstract methods and requiring their implementation in subclasses, these tools help you maintain uniformity and conformity to a predetermined interface.