As mentioned by other here:

Interfaces are not necessary in Python. This is because Python has proper multiple inheritance, and also ducktyping, which means that the places where you must have interfaces in Java, you don't have to have them in Python.

That said, there are still several uses for interfaces. Some of them are covered by Pythons Abstract Base Classes, introduced in Python 2.6. They are useful, if you want to make base classes that cannot be instantiated, but provide a specific interface or part of an implementation.

Another usage is if you somehow want to specify that an object implements a specific interface, and you can use ABC's for that too by subclassing from them. Another way is zope.interface, a module that is a part of the Zope Component Architecture, a really awesomely cool component framework. Here you don't subclass from the interfaces, but instead mark classes (or even instances) as implementing an interface. This can also be used to look up components from a component registry. Supercool!

Answer from Lennart Regebro on Stack Overflow
Top answer
1 of 8
272

As mentioned by other here:

Interfaces are not necessary in Python. This is because Python has proper multiple inheritance, and also ducktyping, which means that the places where you must have interfaces in Java, you don't have to have them in Python.

That said, there are still several uses for interfaces. Some of them are covered by Pythons Abstract Base Classes, introduced in Python 2.6. They are useful, if you want to make base classes that cannot be instantiated, but provide a specific interface or part of an implementation.

Another usage is if you somehow want to specify that an object implements a specific interface, and you can use ABC's for that too by subclassing from them. Another way is zope.interface, a module that is a part of the Zope Component Architecture, a really awesomely cool component framework. Here you don't subclass from the interfaces, but instead mark classes (or even instances) as implementing an interface. This can also be used to look up components from a component registry. Supercool!

2 of 8
239

Implementing interfaces with abstract base classes is much simpler in modern Python 3 and they serve a purpose as an interface contract for plug-in extensions.

Create the interface/abstract base class:

from abc import ABC, abstractmethod

class AccountingSystem(ABC):

    @abstractmethod
    def create_purchase_invoice(self, purchase):
        pass

    @abstractmethod
    def create_sale_invoice(self, sale):
        log.debug('Creating sale invoice', sale)

Create a normal subclass and override all abstract methods:

class GizmoAccountingSystem(AccountingSystem):

    def create_purchase_invoice(self, purchase):
        submit_to_gizmo_purchase_service(purchase)

    def create_sale_invoice(self, sale):
        super().create_sale_invoice(sale)
        submit_to_gizmo_sale_service(sale)

You can optionally have common implementation in the abstract methods as in create_sale_invoice(), calling it with super() explicitly in the subclass as above.

Instantiation of a subclass that does not implement all the abstract methods fails:

class IncompleteAccountingSystem(AccountingSystem):
    pass

>>> accounting = IncompleteAccountingSystem()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't instantiate abstract class IncompleteAccountingSystem with abstract methods
create_purchase_invoice, create_sale_invoice

You can also have abstract properties, static and class methods by combining corresponding annotations with @abstractmethod.

Abstract base classes are great for implementing plugin-based systems. All imported subclasses of a class are accessible via __subclasses__(), so if you load all classes from a plugin directory with importlib.import_module() and if they subclass the base class, you have direct access to them via __subclasses__() and you can be sure that the interface contract is enforced for all of them during instantiation.

Here's the plugin loading implementation for the AccountingSystem example above:

...
from importlib import import_module

class AccountingSystem(ABC):

    ...
    _instance = None

    @classmethod
    def instance(cls):
        if not cls._instance:
            module_name = settings.ACCOUNTING_SYSTEM_MODULE_NAME
            import_module(module_name)
            subclasses = cls.__subclasses__()
            if len(subclasses) > 1:
                raise InvalidAccountingSystemError('More than one '
                        f'accounting module: {subclasses}')
            if not subclasses or module_name not in str(subclasses[0]):
                raise InvalidAccountingSystemError('Accounting module '
                        f'{module_name} does not exist or does not '
                        'subclass AccountingSystem')
            cls._instance = subclasses[0]()
        return cls._instance

Then you can access the accounting system plugin object through the AccountingSystem class:

>>> accountingsystem = AccountingSystem.instance()

(Inspired by this PyMOTW-3 post.)

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
September 8, 2023
How do I implement interfaces in python?
Attempting to instantiate an abstract class or a subclass that doesn’t implement all abstract methods will raise a TypeError. Python relies heavily on duck typing, meaning you don’t need formal interfaces to enforce a contract. More on designgurus.io
🌐 designgurus.io
1
10
November 23, 2024
Function interface for a class (design question)
how should i do best to make a function interface that wraps a “private” class? i have this function i want to use let’s call it func(), and the point is to expose it via package __init__, but the core functionality is done using a class, so it wraps a class and does some stuff how should ... More on discuss.python.org
🌐 discuss.python.org
0
January 7, 2025
Classes and Implementing Interfaces
Take a look here: https://realpython.com/python-interface/ More on reddit.com
🌐 r/learnpython
10
1
February 9, 2021
🌐
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 a class must implement in order to be considered compatible with the interface. In Python, interfaces can be implemented using abstract base classes (ABCs).
🌐
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 - The attrs list is a list of all of the Python properties that should be part of our interface - in this case it should have a size and empty property. The callables list is a list of all the callable methods other than properties. So, our IMyCollection class will include add, remove, get, and contains methods.
🌐
GeeksforGeeks
geeksforgeeks.org › python › difference-between-abstract-class-and-interface-in-python
Difference between abstract class and interface in Python - GeeksforGeeks
July 23, 2025 - Declaring interface: In Python, an interface is defined using Python class statements and is a subclass of interface.Interface which is the parent interface for all interfaces.
🌐
Medium
medium.com › towardsdev › interfaces-en-python-2a7365a9ba14
Interfaces in Python
April 11, 2025 - In Python, the concept of an ... or C#), but it can be achieved — and is recommended — using Abstract Base Classes (ABCs) or Protocols (PEP 544)....
Find elsewhere
🌐
Real Python
realpython.com › python-interface
Implementing an Interface in Python – Real Python
February 21, 2024 - In certain circumstances, you may not need the strict rules of a formal Python interface. Python’s dynamic nature allows you to implement an informal interface. An informal Python interface is a class that defines methods that can be overridden, but there’s no strict enforcement.
🌐
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.
🌐
Tutorialspoint
tutorialspoint.com › python › python_interfaces.htm
Python - Interfaces
The required functionality must be implemented by the methods of any class that inherits the interface. The method defined without any executable code is known as abstract method. In languages like Java and Go, there is keyword called interface which is used to define an interface. Python doesn't have it or any similar keyword.
🌐
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
🌐
Chelsea Troy
chelseatroy.com › 2020 › 11 › 14 › why-use-or-not-use-interfaces-in-python
Why use (or not use) interfaces in Python? – Chelsea Troy
November 15, 2020 - An abstract class implements some ... is concerned, an interface is just a special case of abstract class that implements no methods and requires subclasses to implement all the methods....
🌐
Better Programming
betterprogramming.pub › neat-python-interface-e1371de63406
Neat Python Interface
February 24, 2023 - I think Protocols are the best way to create interfaces in Python. This is what we are going to use here. Here, we are going to discuss what makes a good interface. You’re designing a Zoo simulator and made an interface for “a generic animal”: class Animal(Protocol): def current_weight(self) ...
🌐
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 …
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-interface-module
Python-interface module - GeeksforGeeks
March 26, 2020 - In python, interface is defined using python class statements and is a subclass of interface.Interface which is the parent interface for all interfaces.
🌐
Scaler
scaler.com › home › topics › interface in python
Interface in Python - Scaler Topics
June 23, 2024 - As previously demonstrated, there is no explicit 'interface' keyword in Python for establishing an interface. In Python, an abstract class with solely abstract methods is used to construct an interface.
🌐
Python
peps.python.org › pep-0245
PEP 245 – Python Interface Syntax | peps.python.org
An interface object is then created using the extends list for the base interfaces and the saved interface elements. The interface name is bound to this interface object in the original local namespace. This PEP also proposes an extension to Python’s ‘class’ statement:
🌐
Stack Abuse
stackabuse.com › guide-to-interfaces-in-python
Guide to Interfaces in Python
June 26, 2023 - Even though Python does not explicitly support interfaces in the same way as some other languages, they play a pivotal role in structuring and organizing Python programs effectively. Here, interfaces aren't merely a language construct, but a design principle that helps improve code readability, maintainability, reusability, and testing. The prime advantage of using interfaces is that they greatly enhance code readability. By defining clear, predictable behaviors through interfaces, developers can quickly understand what a class is supposed to do, without needing to scrutinize its entire implementation.
🌐
Python.org
discuss.python.org › python help
Function interface for a class (design question) - Python Help - Discussions on Python.org
January 7, 2025 - how should i do best to make a function interface that wraps a “private” class? i have this function i want to use let’s call it func(), and the point is to expose it via package __init__, but the core functionality is done using a class, so it wraps a class and does some stuff how should i best do this? i prefer not to write all the parameters twice since the PrivateClass will only ever be used internally. my code below is how i do it now: def PrivateClass: def __init__(params): ...
🌐
ThePythonGuru
thepythonguru.com › python-classes-and-interfaces › index.html
Python Classes and Interfaces - ThePythonGuru.com
January 7, 2020 - Another approach is to define a small class that encapsulates the state you want to track: In other languages, you might expect that now defaultdict would have to be modified to accommodate the interface of CountMissing. But in Python, thanks to first-class functions, you can reference the CountMissing.missing method directly on an object and pass it to defaultdict as the default value hook.