Last modified: Nov 27, 2026

Python Property with Arguments

Python properties are a powerful way to manage attribute access. They let you run code when you get or set a value. But what about property with arguments? That phrase can mean two things. It can mean passing arguments to the getter or setter. Or it can mean creating reusable property factories. This article covers both ideas. You will see clear examples and outputs. You will also learn when this pattern helps and when it hurts.

What Is a Python Property?

A property turns a method into an attribute. You use the property() built-in or the @property decorator. The goal is clean syntax. You access obj.value instead of obj.get_value(). The property runs your code behind the scenes.

Here is a basic example. The class stores a private attribute. The property returns it.


class Circle:
    def __init__(self, radius):
        self._radius = radius

    @property
    def radius(self):
        return self._radius

c = Circle(5)
print(c.radius)

5

This is the classic use case. The property has no arguments besides self. The attribute behaves like a normal value. If you want to know when this pattern is best, read about when to use property in Python.

Can a Property Take Arguments?

Yes and no. A property getter takes only self. A setter takes self and the new value. You cannot call c.radius(3) on a property. That is not how properties work. But you can pass arguments in two other ways.

First, the setter already receives one argument: the value being assigned. Second, you can create a property that returns a function. That returned function can accept arguments. This is the "property factory" pattern. It is common in advanced code.

Setter Arguments: The Built-in Case

The setter is the most natural place for an argument. It receives the value you assign. You can validate it before saving.


class BankAccount:
    def __init__(self, balance):
        self._balance = balance

    @property
    def balance(self):
        return self._balance

    @balance.setter
    def balance(self, amount):
        if amount < 0:
            raise ValueError("Balance cannot be negative")
        self._balance = amount

acct = BankAccount(100)
acct.balance = 250
print(acct.balance)
acct.balance = -5

250
ValueError: Balance cannot be negative

The setter argument is amount. It is the value on the right side of the equals sign. This is the standard way to pass data into a property. The property itself still takes no extra parameters. If you come from Java, the self argument may feel strange. See Python self vs Java this: Key Differences.

Property That Returns a Function

Sometimes you want a property to produce a callable. The property returns a function. That function accepts arguments. This is useful for computed views.


class Temperature:
    def __init__(self, celsius):
        self._celsius = celsius

    @property
    def celsius(self):
        return self._celsius

    @property
    def convert(self):
        def to_fahrenheit(offset=0):
            return (self._celsius * 9/5) + 32 + offset
        return to_fahrenheit

t = Temperature(25)
print(t.convert())
print(t.convert(10))

77.0
87.0

Here convert is a property. Accessing it returns a function. That function takes an optional offset argument. This pattern keeps the API clean. You still use t.convert like an attribute. Then you call it with arguments. The method to_fahrenheit uses self from the outer scope. If that confuses you, review What Is Self in Python? Explained.

Property Factory with Arguments

A property factory is a function that returns a property. The factory accepts arguments. Those arguments configure the property. This is how you build reusable validation logic.


def positive_property(attr_name):
    def getter(self):
        return getattr(self, attr_name)

    def setter(self, value):
        if value <= 0:
            raise ValueError(f"{attr_name} must be positive")
        setattr(self, attr_name, value)

    return property(getter, setter)

class Product:
    price = positive_property("_price")

    def __init__(self, price):
        self._price = price

p = Product(50)
print(p.price)
p.price = 80
print(p.price)
p.price = 0

50
80
ValueError: _price must be positive

The factory positive_property takes one argument: attr_name. It returns a property object. That property uses the argument to find the right attribute. This avoids repeating the same setter code in many classes. It is a good use of property with arguments. The class definition stays short and readable.

Using @property with Custom Logic

You can also combine the decorator with helper functions. The property getter can accept no arguments. But it can call other methods that do. Keep the public property simple.


class Order:
    def __init__(self, items):
        self.items = items

    def _calculate(self, tax_rate):
        total = sum(self.items)
        return total * (1 + tax_rate)

    @property
    def total_with_tax(self):
        return self._calculate(0.1)

o = Order([10, 20, 30])
print(o.total_with_tax)

66.0

The property total_with_tax takes no arguments. It calls _calculate with a fixed tax rate. If you need different rates, use a method or the function-returning property pattern. Do not force arguments into a property getter. That breaks the attribute contract.

Common Mistakes and How to Avoid Them

One mistake is trying to call a property like a method. obj.prop(5) fails. A property is not a method. Use a setter or a returned function instead.

Another mistake is adding required arguments to a getter. The getter signature must be def getter(self). Python calls it with only the instance. Any other arguments cause a TypeError.

A third mistake is hiding side effects. A property should feel like reading an attribute. If it takes arguments or does heavy work, a method is clearer. Use the factory pattern only when it simplifies repeated code.

Remember that self is the first argument in every instance method. The @property decorator relies on this. For a deeper look at class setup, see Python init and self: A Clear Guide.

When to Use Property with Arguments

Use the setter argument for validation and transformation. It is simple and expected. Use the function-returning property when you want a computed attribute that can be called with options. Use the factory when many classes share the same property logic.

Avoid arguments when a plain method would be clearer. Readability beats cleverness. Your future self will thank you.

Conclusion

Python properties do not accept extra arguments in the getter. But they do accept one argument in the setter. You can also return functions from properties or build property factories. These patterns give you flexible, readable code. Start with simple properties. Add arguments only when they solve a real problem. Keep your API predictable. That is the key to clean Python.