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
692

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
230

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 default.
🌐
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 …
🌐
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.
🌐
Justacademy
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.
🌐
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.
🌐
k0nze
k0nze.dev › posts › python-interfaces-abstract-classes
Python’s Abstract Base Classes (ABC) and Interfaces Explained (With Code Snippets) | k0nze
February 22, 2024 - When inheriting from an interface (e.g. implementing it) the @abstractmethod decorator ensures that all methods decorated with it are overridden by the implementing class. 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.
🌐
Real Python
realpython.com › python-interface
Implementing an Interface in Python – Real Python
February 21, 2024 - You'll learn how interfaces can ... for designing classes. Like classes, interfaces define methods. Unlike classes, these methods are abstract....
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 ... 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....
🌐
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
🌐
Python Guides
pythonguides.com › python-interface
Interface In Python
1 week ago - 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.
🌐
Advanced python
gkindex.com › python-advanced › python-abstract-class-vs-interface.jsp
Python Abstract Class vs Interface | Gkindex
July 11, 2023 - An abstract class will become an interface when it contains only abstract methods and there are no concrete methods.
🌐
Reddit
reddit.com › r/python › python interfaces: choose protocols over abc
r/Python on Reddit: Python Interfaces: Choose Protocols Over ABC
February 12, 2023 - There is a substantial difference: abstract class ensures that an implementation meets certain requirements when a subclass is declared, while protocol checks if an instance meets certain requirements when it's being used.
🌐
w3resource
w3resource.com › python › python-abstract-classes-and-interfaces.php
Understanding Python Abstraction: Abstract Classes & Interfaces
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....
🌐
Codefinity
codefinity.com › blog › Interface-vs-Abstract-Class
Interface vs Abstract Class
It delineates a set of methods that a class must implement, thereby specifying a contract that the implementing class agrees to fulfill. Interfaces are instrumental in decoupling the definition of tasks from their execution, promoting a high degree of modularity and flexibility in software design. ... Contract-Driven Design: Interfaces are pure declarations without any hint of implementation. They encapsulate what actions an object can perform without dictating how those actions are executed. This abstraction allows different classes to offer diverse implementations of the same interface, fostering polymorphism.
🌐
iO Flood
ioflood.com › blog › python-abstract-class
Python Abstract Classes | Usage Guide (With Examples)
February 10, 2024 - In this example, MyInterface is an abstract class that serves as an interface. MyClass is a concrete class that provides an implementation for the methods defined in MyInterface. Using abstract classes for more complex scenarios like these can greatly enhance the structure and readability of your code. However, as with any powerful tool, it’s important to use these techniques judiciously and in the right context. While the abc module is a powerful tool for creating abstract classes in Python, there are other approaches you can use, such as metaclasses and third-party libraries like zope.interface.
Top answer
1 of 16
2497

Interfaces

An interface is a contract: The person writing the interface says, "hey, I accept things looking that way", and the person using the interface says "OK, the class I write looks that way".

An interface is an empty shell. There are only the signatures of the methods, which implies that the methods do not have a body. The interface can't do anything. It's just a pattern.

For example (pseudo code):

// I say all motor vehicles should look like this:
interface MotorVehicle
{
    void run();

    int getFuel();
}

// My team mate complies and writes vehicle looking that way
class Car implements MotorVehicle
{

    int fuel;

    void run()
    {
        print("Wrroooooooom");
    }


    int getFuel()
    {
        return this.fuel;
    }
}

Implementing an interface consumes very little CPU, because it's not a class, just a bunch of names, and therefore there isn't any expensive look-up to do. It's great when it matters, such as in embedded devices.


Abstract classes

Abstract classes, unlike interfaces, are classes. They are more expensive to use, because there is a look-up to do when you inherit from them.

Abstract classes look a lot like interfaces, but they have something more: You can define a behavior for them. It's more about a person saying, "these classes should look like that, and they have that in common, so fill in the blanks!".

For example:

// I say all motor vehicles should look like this:
abstract class MotorVehicle
{

    int fuel;

    // They ALL have fuel, so lets implement this for everybody.
    int getFuel()
    {
         return this.fuel;
    }

    // That can be very different, force them to provide their
    // own implementation.
    abstract void run();
}

// My teammate complies and writes vehicle looking that way
class Car extends MotorVehicle
{
    void run()
    {
        print("Wrroooooooom");
    }
}

Implementation

While abstract classes and interfaces are supposed to be different concepts, the implementations make that statement sometimes untrue. Sometimes, they are not even what you think they are.

In Java, this rule is strongly enforced, while in PHP, interfaces are abstract classes with no method declared.

In Python, abstract classes are more a programming trick you can get from the ABC module and is actually using metaclasses, and therefore classes. And interfaces are more related to duck typing in this language and it's a mix between conventions and special methods that call descriptors (the __method__ methods).

As usual with programming, there is theory, practice, and practice in another language

2 of 16
993

The key technical differences between an abstract class and an interface are:

  • Abstract classes can have constants, members, method stubs (methods without a body) and defined methods, whereas interfaces can only have constants and methods stubs.

  • Methods and members of an abstract class can be defined with any visibility, whereas all methods of an interface must be defined as public (they are defined public by default).

  • When inheriting an abstract class, a concrete child class must define the abstract methods, whereas an abstract class can extend another abstract class and abstract methods from the parent class don't have to be defined.

  • Similarly, an interface extending another interface is not responsible for implementing methods from the parent interface. This is because interfaces cannot define any implementation.

  • A child class can only extend a single class (abstract or concrete), whereas an interface can extend or a class can implement multiple other interfaces.

  • A child class can define abstract methods with the same or less restrictive visibility, whereas a class implementing an interface must define the methods with the exact same visibility (public).

🌐
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 methods, let alone initialize an instance of one.