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

๐ŸŒ
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. You'll also examine the differences between Python interfaces and those in other programming languages.
Discussions

Classes and Implementing Interfaces
Take a look here: https://realpython.com/python-interface/ More on reddit.com
๐ŸŒ r/learnpython
10
1
February 9, 2021
Using OOP interfaces in Python
Interfaces are very handy for dependency injection. Say that you have a DB interface that let's you query data from a database. You can have two implementations of it, one for Postgres and one for Sqlite. You can use the Sqlite implementation in your tests and still pass type checks. More on reddit.com
๐ŸŒ r/Python
45
43
July 9, 2025
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
How to implement interfaces in Python effectively? - TestMu AI Community
How do I implement interfaces in Python? In C#, I can define an interface and implement it as shown below: public interface IInterface { void show(); } public class MyClass : IInterface { #region IInterface Members public void show() { Console.WriteLine("Hello World!"); } #endregion } I tried ... More on community.testmu.ai
๐ŸŒ community.testmu.ai
0
January 1, 2025
๐ŸŒ
Better Programming
betterprogramming.pub โ€บ neat-python-interface-e1371de63406
Neat Python Interface. Tips to avoid bloated OOP interfaces | by Oleg Sinavski | Better Programming
February 24, 2023 - It is a blueprint of interactions with an object (reading a few answers here is not going to hurt). Do you need interfaces in Python at all? There are several good posts about it: ... Iโ€™m going to assume that you read all that and decided to go with interfaces. I think Protocols are the best way to create interfaces in Python.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-ensure-robust-interface-design-in-python-397989
How to ensure robust interface design in Python | LabEx
This tutorial will guide you through the fundamentals of Python interface design, provide best practices for developing resilient interfaces, and explore effective implementation strategies to ensure your Python applications remain maintainable and adaptable over time.
๐ŸŒ
Python
peps.python.org โ€บ pep-0008
PEP 8 โ€“ Style Guide for Python Code | peps.python.org
The naming convention for functions may be used instead in cases where the interface is documented and used primarily as a callable.
๐ŸŒ
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 - Interfaces and abstract classes are two important concepts in object-oriented programming. They allow us to write clean, maintainable, and flexible code. In this blog post, weโ€™ll explore the similarities and differences between interfaces and abstract classes in Python, and learn when to use each approach.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ guide-to-interfaces-in-python
Guide to Interfaces in Python
June 26, 2023 - By acting as contracts that enforce ... Python takes a flexible and practical approach to interfaces, embracing both explicit interfaces through Abstract Base Classes and implicit interfaces via Duck Typing....
Find elsewhere
๐ŸŒ
Better Programming
betterprogramming.pub โ€บ 4-best-practices-to-create-command-line-interfaces-in-python-5043fbb7c52b
4 Best Practices To Create Command-Line Interfaces in Python | by Patrick Kalkman | Better Programming
May 24, 2021 - 4 Best Practices To Create Command-Line Interfaces in Python Real-world examples that show how to implement command-line interfaces in Python If you are like me, you probably have many Python scripts โ€ฆ
๐ŸŒ
CodeRivers
coderivers.org โ€บ blog โ€บ python-interface
Python Interfaces: Concepts, Usage, and Best Practices - CodeRivers
January 20, 2025 - Python interfaces, whether through duck typing or Abstract Base Classes, play a crucial role in creating modular, maintainable, and extensible code. Duck typing offers a flexible and dynamic way to define and use interfaces, while ABCs provide a more formal and structured approach. By following best practices and common usage patterns, developers can write Python code that is easier to understand, test, and scale.
๐ŸŒ
CodeRivers
coderivers.org โ€บ blog โ€บ python-user-interface
Python User Interface: A Comprehensive Guide - CodeRivers
January 30, 2025 - A well-designed UI can enhance ... interfaces. This blog will explore the fundamental concepts, usage methods, common practices, and best practices of Python user interfaces....
๐ŸŒ
Reddit
reddit.com โ€บ r/python โ€บ interfaces with protocols: why not ditch abc for good?
r/Python on Reddit: Interfaces with Protocols: why not ditch ABC for good?
January 22, 2023 -

Hello, if one finds interfaces useful in Python (>=3.8) and is convinced that static type-checking is a must, then why not ditch ABC and always use Protocols? I understand that the fundamental idea of a protocol is slightly different from an interface, but in practice, I had great success replacing abc's with Protocols without regrets.

With abc you would write (https://docs.python.org/3/library/abc.html) :

from abc import ABC, abstractmethod

class Animal(ABC):
   @abstractmethod
   def eat(self, food) -> float:
       pass

Whereas with Protocols it's gonna be (good tutorial):

from typing import Protocol

class Animal(Protocol):
   def eat(self, food) -> float:
       ...

Scores in my subjective scoring system :)

CapabilityABCProtocols
Runtime checking11 (with a decorator)
Static checking with mypy11
Explicit interface (class Dog(Animal):)11
Implicit interface with duck-typing (class Dog:)0.5 (kind of with register, but it doesn't work with mypy yet)1
Default method implementation (def f(self): return 5)-1 (implementations shouldn't be in the interfaces)-1 (same, and mypy doesn't catch this)
Callback interface01
Number of code lines-1 (requires ABC inheritance and abstracmethod for every method)0 (optionalProtocol inheritance)
Total score1.54

So I do not quite see why one should ever use ABC except for legacy reasons. Other (IMHO minor) points in favour of ABC I've seen were about interactions with code editors.

Did I miss anything?

I put more detailed arguments into a Medium. There are many tutorials on using Protocols, but not many on ABC vs Protocols comparisons. I found a battle of Protocols vs Zope, but we are not using Zope, so it's not so relevant.

๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_interfaces.htm
Python - Interfaces
It uses abstract base classes (in short ABC module) and @abstractmethod decorator to create interfaces. NOTE: In Python, abstract classes are also created using ABC module.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ interface in python
Interface in Python - Scaler Topics
June 23, 2024 - Even if both objects have the same function swim, we can now tell which one implements the Boat interface and which one implements the Fish interface. We recently learned how to write our own abstract base classes. However, creating custom abstract base classes is frequently discouraged in favor of using subclasses; the built-in ones. The Python standard library has a plethora of helpful ABCs that we may simply reuse.
๐ŸŒ
TestMu AI Community
community.testmu.ai โ€บ ask a question
How to implement interfaces in Python effectively? - TestMu AI Community
January 1, 2025 - How do I implement interfaces in Python? In C#, I can define an interface and implement it as shown below: public interface IInterface { void show(); } public class MyClass : IInterface { #region IInterface Members public void show() { Console.WriteLine("Hello World!"); } #endregion } I tried to create a Python equivalent for this using the following code: class IInterface(object): def init(self): pass def show(self): raise Exception("NotImplementedException") class MyClass(IInte...
Top answer
1 of 1
1

The type systems of Python on the one hand and C# and Java on the other hand work in a fundamentally different way.

C# and Java use a nominal type system: Two types are the same if they have the same name. Additionally, they use strong typing: assignment (and parameter passing) between references is only allowed if the target type is in the set of types formed by enumerating the source's type and declared sub-types.

Python on the other hand uses a structural type system: Two types are considered compatible if you can do the same operations on them. This is also called duck-typing (if it quacks like a duck and walks like a duck, then you can treat it as a duck).

Furthermore, type declarations for function parameters and return types are a relatively new addition to Python and they are not actively used by the Python runtime environment.

As Python doesn't require the match in type names and doesn't actively check type matches on function calls, there has traditionally been much less incentive to use interface declarations in Python than in C#/Java. And due to the structural typing, there is still no need to explicitly mention a class implements interface X. A function that is documented to need an argument of type X will accept anything that is structurally compatible with X, not just classes that explicitly mention implementing X.

Thus, interfaces in Python are useful documentation tools, but they are not needed to support Dependency Injection or Mocking in testcases, like they are in C# and Java.

๐ŸŒ
Medium
aignishant.medium.com โ€บ the-ultimate-guide-to-interfaces-protocols-and-abcs-in-python-8a991d7a4430
The Ultimate Guide to Interfaces, Protocols, and ABCs in Python | by Nishant Gupta | Medium
March 6, 2025 - Three key concepts โ€” interfaces, protocols, and Abstract Base Classes (ABCs) โ€” provide different ways to establish contracts and shared behaviors in your code. While these concepts overlap in purpose, they differ significantly in implementation and use cases. This guide explores these powerful abstraction mechanisms in Python, offering practical examples, detailed implementation patterns, and best ...
๐ŸŒ
Medium
medium.com โ€บ @arnab194 โ€บ implementing-interfaces-in-python-da74b0d499c8
Implementing Interfaces in Python | by ARNAB PAL | Medium
March 2, 2023 - Defining your own metaclass and controlling instance creation or class creation is not recommended unless you need more control over class creation, enforcing certain coding practices. Here we first created a metaclass named BaseMeta . For explicit metaclass declaration, your class must inherit from type Class. Here the __new__ method contains the logic for enforcing interfaces.
๐ŸŒ
Andrewbrookins
andrewbrookins.com โ€บ technology โ€บ building-implicit-interfaces-in-python-with-protocol-classes
Building Implicit Interfaces in Python with Protocol Classes โ€“ Andrew Brookins
July 5, 2020 - Protocol classes allow us to define an interface, called a protocol, and use static type-checking via mypy to verify that objects satisfy the interface โ€“ without classes having to declare that they satisfy the interface or subclass anything. So, why is this called a โ€œprotocolโ€ and what kinds of things is it good for? Letโ€™s go deeper to answer those questions. The built-in function len() works with any object that has a __len__() method. Objects donโ€™t have to declare that they have a __len__() method or subclass any special classes to work with len(). Python programmers call this state of affairs a protocol, and the most common example is probably the iteration protocol.