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 ...
Discussions

Difference between interface and abstracts
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 getting varied in python language? Could you please guide me on getting good ... More on discuss.python.org
🌐 discuss.python.org
0
0
September 8, 2023
What's the practical difference between an interface, a type, and an abstract class in OOP languages like Python? - Stack Overflow
What's the practical difference between an interface, a type, and an abstract class in OOP languages like Python? Links to Wikipedia: Interface, type and abstract class. More on stackoverflow.com
🌐 stackoverflow.com
Understanding the Need for Abstract Classes and Interfaces – Why Not Just Use Concrete Classes?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
28
5
August 30, 2024
Abstract vs Interface
Like has already said, this depends on the language, but the general case is as follows: Abstract classes are just classes that are marked as uninstantiable. You are forced to extend them and instantiate the sub class instead. An abstract class can contain a mixture of concrete and abstract methods, and even variables/fields, so not everything WITHIN an abstract class has to be abstract itself. An interface is entirely "abstract". It's a list of methods that an object has to implement and cannot contain any implementations at all. An additional point of interest is in regards to languages with single inheritance only, where you are only allowed to extend a single class. Often times in those languages they will still let you implement multiple interfaces. In those situations if you're modeling your class as something that's both an X and a Y, you would have to use interfaces over classes, or one class and multiple interfaces. More on reddit.com
🌐 r/AskProgramming
29
3
July 24, 2025
🌐
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.
🌐
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 …
🌐
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():
Find elsewhere
🌐
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.
🌐
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.
🌐
w3resource
w3resource.com › python › python-abstract-classes-and-interfaces.php
Understanding Python Abstraction: Abstract Classes & Interfaces
August 23, 2024 - 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 - Python Guides
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.
🌐
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:
🌐
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 ...
🌐
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 ...
🌐
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.
🌐
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.
🌐
Sinavski
sinavski.com › home › interfaces abc vs. protocols
Interfaces: abc vs. Protocols - Oleg Sinavski
August 1, 2021 - Python is somewhat different from other popular languages since there are no interfaces on a language level. However, there are several library implementations: ... from abc import ABC, abstractmethod class Animal(ABC): @abstractmethod def eat(self, food) -> float: pass @abstractmethod def sleep(self, hours) -> float: pass
🌐
GoDaddy
godaddy.com › resources › news › engineering › interfaces and metaclasses in python
Interfaces and Metaclasses in Python - GoDaddy Blog
March 5, 2024 - For this example, let’s just focus on forcing classes to implement any methods marked as “abstract” in the class hierarchy. Our version of an interface will be a bit stronger than Python’s ABC, in that it won’t allow us to even define a class that fails to implement all necessary ...