Python Abstract Property: Defining and Using Abstract Properties
Learn how to define abstract properties in Python using the abc module, combine @property with @abstractmethod, and avoid common implementation mistakes.

An abstract property in Python is a property that an abstract base class declares as required. Concrete subclasses must override it, typically by providing the getter the base class has marked as abstract. The standard way to define one is to combine the @property decorator with @abstractmethod from the abc module.
Defining an Abstract Property
The simplest abstract property requires only a getter. You declare it in the abstract base class and leave the implementation to subclasses. Here is a minimal example:
from abc import ABC, abstractmethod
class Shape(ABC):
@property
@abstractmethod
def area(self) -> float:
"""Return the area of the shape."""
class Circle(Shape):
def __init__(self, radius: float):
self.radius = radius
@property
def area(self) -> float:
return 3.14159 * self.radius ** 2In this code, Shape declares an abstract property area. The Circle subclass implements it as a read-only property. The @abstractmethod decorator marks the property as abstract, so any concrete subclass that does not override it cannot be instantiated. Attempting to create a Shape instance directly raises TypeError.
Why Use Abstract Properties
Abstract properties enforce a contract at the attribute level. Unlike an abstract method, which only mandates a callable method, an abstract property requires a specific attribute access pattern. This is valuable when you have a base class that defines a common interface but expects each subclass to supply its own data representation. For example, a DataSource base class might declare an abstract connection_string property, and each database-specific subclass returns the appropriate string. The rest of the code can then read connection_string without knowing the concrete class.
Abstract properties also make the intent explicit. A developer reading the base class immediately sees that any concrete subclass must provide this attribute, which improves code navigation and reduces the chance of a subclass silently missing a required attribute.
Combining @property with @abstractmethod
The correct way to declare an abstract property in modern Python (3.3+) is to stack @property and @abstractmethod. The order matters: @property goes on top, then @abstractmethod immediately below it. This is because @abstractmethod should wrap the underlying function that property will use.
class Base(ABC):
@property
@abstractmethod
def value(self):
"""Abstract getter."""In older Python versions, the abc module provided a dedicated abstractproperty decorator. It was deprecated in Python 3.3 and removed in Python 3.9. If you are maintaining code that still uses @abstractproperty, you should replace it with the stacked form. The stacked form works in every version from 3.3 onward and is the only supported syntax in current releases.
Handling Setters and Deleters
An abstract property can also define abstract setters and deleters. To require subclasses to implement a setter, use the @property decorator with @abstractmethod on the getter, and then decorate the setter with @abstractmethod as well. Here is an example:
class Temperature(ABC):
@property
@abstractmethod
def celsius(self) -> float:
"""Get the temperature in Celsius."""
@celsius.setter
@abstractmethod
def celsius(self, value: float) -> None:
"""Set the temperature in Celsius."""
class Thermostat(Temperature):
def __init__(self):
self._celsius = 20.0
@property
def celsius(self) -> float:
return self._celsius
@celsius.setter
def celsius(self, value: float) -> None:
if value < -273.15:
raise ValueError("Temperature below absolute zero")
self._celsius = valueIn this pattern, the base class marks both the getter and setter as abstract, and the concrete subclass supplies both in its overriding property. ABC enforcement works at the property-name level, not per getter or setter. If a subclass replaces the property with a concrete getter-only @property, it will not be forced to provide a setter just because the base class declared an abstract setter. Include the setter in the subclass property when the contract requires it. The same per-name behavior applies to a deleter.
Common Mistakes and Errors
One frequent mistake is forgetting to implement an abstract property in a subclass. The error message from Python identifies the missing method, for example TypeError: Can't instantiate abstract class Square with abstract method area. This happens at instantiation time, not at class definition time, so you may not notice until you try to create an object.
Another mistake is using the deprecated @abstractproperty decorator. While it still works in some legacy code, it raises a DeprecationWarning in Python 3.3 through 3.8 and is completely removed in 3.9. If you see this warning, switch to the stacked decorators.
A third issue arises when you define an abstract property with an implementation body in the base class. That is allowed: the property remains abstract, but the base class can provide a default implementation that concrete subclasses can call with super(). Because the method is still marked abstract, a concrete subclass must override it before it can be instantiated; merely inheriting the default is not enough. If you do not want a default, leave the body empty with a docstring, which is the common convention.
Compatibility and Python Versions
The behavior of abstract properties depends on the Python version you target. In Python 3.3 and later, the @property and @abstractmethod combination is fully supported. Python 3.9 removed abstractproperty. If you need to support Python 2, you would have to use @abstractproperty, but Python 2 is end-of-life and not recommended for new code.
| Python Version | Recommended Syntax | Legacy Syntax |
|---|---|---|
| 3.3+ | @property + @abstractmethod | @abstractproperty (deprecated) |
| 3.9+ | @property + @abstractmethod | Removed |
| 2.7 | Not supported | @abstractproperty |
When writing library code, use the modern stacked form. It works on Python 3.3 and later and avoids deprecation warnings.
Design and Maintainability Considerations
Abstract properties are a design tool, not a performance feature. They add a small overhead at class creation time because the abc machinery must process the decorators, but this is negligible compared to the cost of instantiation or method calls. The real benefit is maintainability: they make the required interface explicit and make omissions visible at instantiation time.
Use an abstract property when the attribute is conceptually a property—that is, when it represents a value that can be read or written with normal attribute syntax. If the operation is more naturally a method, use an abstract method instead. For example, a save() operation is a method, while a file_path attribute is a property.
One tradeoff is that abstract properties can lead to verbose code when a subclass only needs a simple attribute. In that case, you might consider using a plain abstract method that returns the value, or even a class attribute. However, if the attribute must be read-only or must support validation on set, the property form is the right choice.
Another consideration is how to mark each part of the property. Mark the getter with @abstractmethod to make the property abstract. If the property also requires a setter or deleter, mark those parts with @abstractmethod as well. Remember that abc enforcement is per property name: a concrete subclass that overrides the property with a getter-only @property is not forced to implement a setter, so include the setter in the subclass property whenever the base class declares one.
Finally, remember that abstract properties are enforced only when the class uses ABCMeta as its metaclass. If you define a class with class Base: and use @abstractmethod, the enforcement does not happen. Always inherit from ABC or set metaclass=ABCMeta explicitly.
By following these patterns, you can create clear, enforceable interfaces for attributes in your Python codebase, reducing bugs and making the design easier to reason about.
Try matching browser tools
All toolsSmall utilities that fit Python work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Python guides
All Python guidesPython iter(): How the Built-in Function Works
Explains Python's iter() built-in: how it creates iterators, the two-argument sentinel form, custom iterator classes, and common edge cases.
Python Pika: Queues, Exchanges, Routing Keys, and Acknowledgements
Learn how to use Python's Pika client with RabbitMQ: declare queues and exchanges, publish with routing keys, consume messages, and handle acknowledgements reliably.
Python Kafka: kafka-python vs Confluent Client
python kafka python vs confluent kafka: Compare kafka-python and Confluent Kafka Python clients: API differences, performance, feature coverage, and when to choose eac...
Python Kafka Offsets, Partitions, and Manual Commits
Learn how Kafka offsets and partitions work and how to manually commit offsets in Python consumers with kafka-python and confluent-kafka. Covers sync vs async commits, rebalances, and seeking.
More in Python
All Python guidesThe guides filed next to this one in Python, in library order.