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.

🌐
GeeksforGeeks
geeksforgeeks.org › python › difference-between-abstract-class-and-interface-in-python
Difference between abstract class and interface in Python - GeeksforGeeks
July 23, 2025 - We use an abstract class for creating huge functional units. 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 ...
🌐
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 - It specifies a set of methods that ... using abstract base classes (ABCs). For example, suppose we have a Shape interface that specifies a single method, area()....
🌐
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.
🌐
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():
🌐
k0nze
k0nze.dev › posts › python-interfaces-abstract-classes
Python’s Abstract Base Classes (ABC) and Interfaces Explained (With Code Snippets) | k0nze
February 22, 2024 - However, by default, Python doesn’t have interfaces and abstract classes. The reason for this can largely be attributed to the fact that Python is an interpreted language and doesn’t need a compiler to run your code. In a compiled language such as C++, the compiler turns the code you write into machine instructions. For example, at the time of compilation, it is checked if the arguments passed to a function are actually of the correct type stated in the method signature this allows for much faster code execution because at runtime there are no checks if the arguments that are passed to a method are compatible.
🌐
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 …
🌐
TutsWiki
tutswiki.com › abstract-classes-and-interfaces-in-python
Abstract classes and interfaces in Python :: TutsWiki Beta
The downside is the semantics of checks issubclass, isinstance, which intersect with ordinary classes (their inheritance hierarchy). No additional abstractions are built on the ABC. Interfaces are a declarative entity, they do not set any boundaries; simply asserts that the class implements and its object provides the interface.
Find elsewhere
🌐
Just Academy
justacademy.co › blog-detail › difference-between-abstract-class-and-interface-in-python
Difference Between Abstract Class And Interface In Python
In Python, an abstract class is a class that contains one or more abstract methods, which are defined in the class but must be implemented in its subclasses. Abstract classes can also have regular methods and attributes. On the other hand, an interface in Python is created using the `abc` module and is used to define a blueprint for classes that implement it.
🌐
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
🌐
w3resource
w3resource.com › python › python-abstract-classes-and-interfaces.php
Understanding Python Abstraction: Abstract Classes & Interfaces
Abstract Classes: Created using the "ABC" module, abstract classes cannot be instantiated and may contain abstract methods that must be implemented by any subclass. Interfaces: Python doesn’t have interfaces as a built-in concept, but abstract classes with only abstract methods can act as interfaces.
🌐
Python Guides
pythonguides.com › python-interface
Understand Python Interfaces
December 1, 2025 - Improve code readability: Interfaces act as documentation, clearly defining what a class should do. Enable polymorphism: You can write functions that accept any object implementing the interface, making your code flexible and reusable. Catch errors early: Abstract methods force subclasses to implement them, reducing runtime errors. Let me show you how I create interfaces in Python using the abc module.
🌐
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 - For example, you might have an abstract class ‘Person’ that contains properties like ‘name’ and ‘age’. Subclasses ‘Student’ and ‘Teacher’ can inherit from ‘Person’ and add their own specific properties, like ‘studentId’ or ‘teacherId’. In Python, you can create ...
🌐
Readthedocs
interface.readthedocs.io › en › latest › abc.html
interface vs. abc — interface 1.4.0 documentation
This means that interface can tell you if a class fails to implement an interface even if you never create any instances of that class. interface requires that method signatures of implementations are compatible with signatures declared in interfaces. For example, the following code using abc does not produce an error: >>> from abc import ABCMeta, abstractmethod >>> class Base(metaclass=ABCMeta): ...
🌐
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 ...
🌐
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 distinction between abstraction and interface does not exist.
🌐
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 ...
These methods establish a required interface, ensuring that any subclass provides its specific implementation. This approach enforces consistency across subclasses while allowing each to fulfill the required behavior uniquely, promoting organized and reliable code. By mastering abstract classes and abstract methods, you'll be able to easily add new types of derived classes without modifying existing code — a key principle of software design. For example, consider the following implementation, where you adhere to the defined interface without any modifications to the existing Shape class:
🌐
iO Flood
ioflood.com › blog › python-abstract-class
Python Abstract Classes | Usage Guide (With Examples)
February 10, 2024 - In this example, AbstractClassMeta is a metaclass that raises a TypeError if the class it’s being applied to doesn’t have any abstract methods. AbstractClass uses AbstractClassMeta as its metaclass and defines an abstract method my_abstract_method. The zope.interface library is a third-party library that provides a way to define interfaces and abstract classes in Python.