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
๐ŸŒ
Real Python
realpython.com โ€บ python-interface
Implementing an Interface in Python โ€“ Real Python
February 21, 2024 - In this tutorial, you'll explore how to use a Python interface. You'll come to understand why interfaces are so useful and learn how to implement formal and informal interfaces in Python.
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

How do I implement interfaces in python?
In Python, interfaces are not explicitly supported as they are in Java or C#. However, you can achieve interface-like behavior using abstract base classes (ABCs) provided by the abc module. Abstract base classes allow you to define methods that must be implemented by derived (subclass) classes, ... More on designgurus.io
๐ŸŒ designgurus.io
1
10
November 23, 2024
Classes and Implementing Interfaces
Take a look here: https://realpython.com/python-interface/ More on reddit.com
๐ŸŒ r/learnpython
10
1
February 9, 2021
Python interfaces? What is it for? Or it is there because a Java developer happens to write Python?
In Zope it is a part of larger structure where classes are pluggable by configuration. So you can have user object with name, email and password stored in a database or you can change a configuration and have the user object look up the user data in LDAP etc. So Zope is 100% configurable in that regard. the contract for new objects and classes is that they follow the interface, and declare to do so. In older versions you could somewhat do the same, but it worked by convention. And only for one type at a time. So a class can implement an interface and the system can understand it. Making it possible to do something like: class User: implements(UserData) implements(PresentationPage) implements(SQLStorage) It is a technically really clever solution that I have really disliked using in practice. More on reddit.com
๐ŸŒ r/Python
14
2
July 15, 2016
Interfaces with Protocols: why not ditch ABC for good?
Whereas with Protocols it's gonna be ( good tutorial ): I think that is not a good example of how to write programs. What he did by having protocols I would have done by using mixins. The way that I see objects is that they have various capabilities that can be mixed in. multiple inheritance in python would have been a much better way to implement that example in my opinion. I would also say that the author of this tutorial needs to learn a thing or 2 about an inversion of control and dependency injection. The author basically sets up a straw man problem and then solves his straw man problem. He had no business creating instances of the object outside of the class itself. If he had simply called a constructor methods within the classes then the other class wouldn't have been attempting to make instances of those other classes. More on reddit.com
๐ŸŒ r/Python
34
63
January 22, 2023
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_interfaces.htm
Python - Interfaces
We can create and implement interfaces in two ways โˆ’ ... Formal interfaces in Python are implemented using abstract base class (ABC).
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ python tutorial โ€บ interface in python
Interface in Python | How to Create Interface in Python with Examples
May 14, 2024 - Guide to Interface in Python. Here we discuss the two ways in python to create and implement the interface along with the examples.
Call ย  +917738666252
Address ย  Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-interface-module
Python-interface module - GeeksforGeeks
March 26, 2020 - Interface acts as a blueprint for designing classes, so interfaces are implemented using implementer decorator on class. If a class implements an interface, then the instances of the class provide the interface.
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-interface
Understand Python Interfaces - Python Guides
December 1, 2025 - Learn how to implement Python interfaces using abstract base classes with practical examples. Master interfaces to write clean, scalable Python code.
Find elsewhere
๐ŸŒ
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 - When we use the Python issubclass method, it will call this method behind the scenes. See below for a discussion of what that method does. Then, each property and method in the interface is implemented as an abstract method using the @abc.abstractmethod decorator.
๐ŸŒ
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 - For example, suppose we have a Shape interface that specifies a single method, area(). We can define the Shape interface in Python using the abc module as follows: from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def area(self): pass ยท Now, any class that implements the Shape interface must provide an implementation of the area() method.
๐ŸŒ
GitHub
gist.github.com โ€บ 1559689
Sample Interface implementation in python ยท GitHub
Sample Interface implementation in python. GitHub Gist: instantly share code, notes, and snippets.
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ interface in python
Interface in Python
January 4, 2026 - Interfaces are fundamental in Python's object-oriented programming, enabling well-structured, extensible code. This article covers interface declaration, implementation, the role of methods, interface inheritance, and the relationship with abstract classes. Practical examples demonstrate creating and implementing interfaces, showcasing informal and formal interfaces, and with introducing the "zope.interface" library.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Python Interface | Object Oriented Programming | Python Tutorial - YouTube
In this video, we'll dive into the concept of interfaces in Python, exploring how they help in defining a blueprint for classes, ensuring a consistent and pr...
Published ย  August 24, 2024
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ interface in python
Interface in Python - Scaler Topics
June 23, 2024 - Interfaces, typically a set of ... uses the abc module, zope.interface offers stricter semantics. This article explores interfaces in Python, detailing their significance, implementation, and differences from abstract classes....
๐ŸŒ
Dot Net Tutorials
dotnettutorials.net โ€บ home โ€บ interfaces in python
Interfaces in Python with Examples - Dot Net Tutorials
July 5, 2020 - We can create interfaces by using abstract classes which have only abstract methods. Interface can contain: ... As we know, abstract methods should be implemented in the subclass of interface (Abstract Class).
๐ŸŒ
Medium
medium.com โ€บ @tomisinabiodun โ€บ how-to-implement-an-interface-in-python-6d3658d248c
How to Implement an Interface in Python | by Tomisin Abiodun | Medium
April 6, 2022 - How to Implement an Interface in Python Python has no native implementation of interfaces โ€” but thatโ€™s where abstract classes and abstract methods come into play. Interfaces are so vital in โ€ฆ
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ guide-to-interfaces-in-python
Guide to Interfaces in Python
June 26, 2023 - Any object that implements a specific set of methods can be treated as implementing a specific "interface". While Duck Typing provides an implicit way to mimic interface-like behavior, Python also offers a more explicit way through Abstract Base Classes.
๐ŸŒ
Javatpoint
javatpoint.com โ€บ interface-in-python
Interface in Python - Javatpoint
Interface in Python with tutorial, tkinter, button, overview, canvas, frame, environment set-up, first python program, etc.
๐ŸŒ
ThePythonGuru
thepythonguru.com โ€บ python-classes-and-interfaces
Python Classes and Interfaces - ThePythonGuru.com
January 7, 2020 - Beware of the large number of methods required to implement custom container types correctly. Have your custom container types inherit from the interfaces defined in collections.abc to ensure that your classes match required interfaces and behaviors. ... This site generously supported by DataCamp. DataCamp offers online interactive Python Tutorials ...
๐ŸŒ
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