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 default.
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
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
Python Interfaces: Choose Protocols Over ABC
Protocols and abstract classes are not interchangeable. You cannot simply choose one over the other. 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. They are different in the same way as "They are of the same kind" and "There are things that both of them can do". Please, don't confuse people with such articles. More on reddit.com
🌐 r/Python
20
64
February 12, 2023
Interface type for OOP in python - Ideas - Discussions on Python.org
It should be a soft keyword to ensure backward compatibility (I found more than 3M python code with the interface symbole on GitHub : Code search results · GitHub ) With this keyword, this code from abc import abstractmethod, ABCMeta class MyInterface(metaclass=ABCMeta): @abstractmethod def ... More on discuss.python.org
🌐 discuss.python.org
0
April 8, 2025
🌐
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.
🌐
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 › @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.
Find elsewhere
🌐
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
🌐
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.
🌐
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.
🌐
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 interface for a group of derived classes.
🌐
Quora
quora.com › What-is-the-difference-between-interface-and-abstract-class
What is the difference between interface and abstract class? - Quora
Answer (1 of 23): 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, ...
🌐
Python.org
discuss.python.org › ideas
Interface type for OOP in python - Ideas - Discussions on Python.org
April 8, 2025 - To create templates for objects in an OOP project, you have to use abc and its decorator @abstractmethod. I was thinking of symplifying this process by introducing a new interface keyword. It should be a soft keyword to ensure backward compatibility (I found more than 3M python code with the interface symbole on GitHub : Code search results · GitHub ) With this keyword, this code from abc import abstractmethod, ABCMeta class MyInterface(metaclass=ABCMeta): @abstractmethod def myMeth...
Top answer
1 of 3
3

UML class diagrams answer three questions well:

  • What knows about what? (Note the lines)
  • What are these things called? (Note the class names)
  • How do you talk to these things? (Note the method signatures)

If you’re trying to explain something that isn’t the answer to those questions then use something else to explain.

Note: Abstract classes and Interfaces are different mainly in those languages that use Interface as a keyword. Typically this means they didn’t implement multiple inheritance correctly the first time around and hacked it into their language later by adding the Interface keyword.

A lower case i, “interface”, simply describes how you can talk to it. Completely ignores how it works.

2 of 3
1

Communicate the big picture

To communicate the big picture about a set of classes that are supposed to work together, you may consider the following:

  • An UML class diagram (structure), to explain the involved classes, their responsibilities, and their relationships. In your case, you would typically document the operations (UML term for methods) that each class has to provide for your interaction to work.
  • An UML sequence diagram (dynamics), to explain how involved objects of these classes interact by creating each other, and communicating (i.e. calling their operations). Keep diagrams simple, you may make several such diagram, each explaining a specific scenario.

These two simple diagrams help to grasp at a glance the classes involved and how they work together.

Improve your customer/developer's experience

It's not graphical overview vs. self-explanatory code: it's both together. The diagrams are the map that tells where to look for the treasure. The users can then navigate quickly to the related parts with their to find more information. But without the map, the customers might take a lot longer to figure out how all the parts fit together.

To maximise the experience:

  • Keep it lean: show only on the key elements of your design. Don't put all attributes and methods; this would only lead to unreadable diagrams that might frighten away your audience ;-)
  • Ideally, you'd use the the diagrams together with a short explanatory text on the landing page of your documentation,
  • You may provide also an API documentation generated automatically from your comments.

If you're using python, you can give a quick trial at PyReverse (it's part of Pylint, a tool you should consider if you're making mission critical SCADA systems) : it generates automatically some UML class diagrams. But usually, for a design overview, you'll be as fast drawing it from scratch.

Abstract class or not?

Form is a class since it provides an implementation for some methods. It's probably not an abstract class by the book, if it can be instantiated.

Nevertheless, nothing prevents you to show it as abstract on the diagram, to underline that a subclass must be created to make it work. Personally, I'd show is as a normal class and would show one subclass in the diagram that shows the operation that should/could be overridden.

🌐
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....
🌐
Echo $Musings
hongzhucui.com › posts › python interface and protocol
Python interface and protocol | Echo $Musings
August 22, 2024 - Use abstract classes if you need a stricter, enforced inheritance hierarchy and want to use inheritance for code reuse or have shared default methods. Use protocols when you need flexible, interface-like behavior and want to work with any class ...
🌐
Rednafi
rednafi.com › python › interfaces, mixins and building powerful custom data structures in python
Interfaces, mixins and building powerful custom data structures in Python | Redowan's Reflections
July 3, 2020 - So if you want to implement an interface that the users can’t initiate independently and that forces them to implement all the methods in the concrete sub classes, formal interface is the way to go. In Python, the idiomatic way to define formal interfaces is via the abc module. Let’s transform the previously mentioned ICalc interface into a formal one: from abc import ABC, abstractmethod class ICalc(ABC): """Formal interface: Abstract calculator class.""" @abstractmethod def add(self, a, b): pass @abstractmethod def sub(self, a, b): pass @abstractmethod def mul(self, a, b): pass @abstractmethod def div(self, a, b): pass
🌐
Machine Learning Plus
machinelearningplus.com › python › python-abcs-the-complete-guide-to-abstract-base-classes
Python ABCs- The Complete Guide to Abstract Base Classes – Machine Learning Plus
Abstract Base Classes in Python are classes that cannot be instantiated directly and serve as blueprints for other classes. They define a common interface that subclasses must implement, ensuring consistency across your codebase.
🌐
Kansas State University
textbooks.cs.ksu.edu › cc410 › i-oop › 06-inheritance-polymorphism › 06-python-interfaces › index.html
Python Interfaces :: CC 410 Textbook
June 17, 2024 - import abc from typing import List class IMyStack(metaclass=abc.ABCMeta): @classmethod def __subclasshook__(cls, subclass: type) -> bool: if cls is IMyStack: attrs: List[str] = [] callables: List[str] = ['push', 'pop', 'peek'] ret: bool = True for attr in attrs: ret = ret and (hasattr(subclass, attr) and isinstance(getattr(subclass, attr), property)) for call in callables: ret = ret and (hasattr(subclass, call) and callable(getattr(subclass, call))) return ret else: return NotImplemented @abc.abstractmethod def push(self, o: object) -> None: raise NotImplementedError @abc.abstractmethod def pop(self) -> object: raise NotImplementedError @abc.abstractmethod def peek(self) -> object: raise NotImplementedError · This is a simpler interface which simply defines methods for push, pop, and peek. Once we’ve created an interface, we can then create a class that implements that interface.
🌐
DataCamp
datacamp.com › tutorial › python-abstract-classes
Python Abstract Classes: A Comprehensive Guide with Examples | DataCamp
January 22, 2025 - With this foundation, let's dive ... enabling developers to enforce attribute consistency alongside methods. Abstract classes can specify properties that subclasses must implement in addition to methods. This feature enables developers to impose a uniform interface for properties ...