How to make a class property?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In Python, the phrase "class property" is ambiguous. Most people actually mean an instance property created with @property. A true property on the class object itself is a different pattern and usually requires a custom descriptor.
The Common Case: Instance Property
This is the standard @property pattern:
This creates a managed attribute on each instance. Access looks like field access, but Python runs the getter and setter methods behind the scenes.
Why @property Is Useful
Properties let you:
- validate assignments
- compute values on demand
- preserve a simple attribute-style API
- change implementation later without changing calling code
That is why @property is so common for encapsulation.
What a True Class-Level Property Means
Sometimes the goal is this:
where some_value is computed like a property on the class itself, not on an instance.
Python's built-in property does not do that out of the box. It is an instance-level descriptor.
Custom Descriptor for Class-Level Access
Here version behaves like a read-only computed property on the class.
Class Property Versus Class Variable
Do not confuse a class property with a plain class variable:
This is just a class attribute. It is perfectly fine when you need shared stored data and no special logic.
You only need a property-like mechanism when access should be computed or controlled.
When to Use Each Pattern
Use an instance property when:
- the value belongs to each object separately
- validation or computed access is needed on instances
Use a class variable when:
- one shared stored value is enough
- no special getter logic is needed
Use a custom class-property descriptor when:
- the class itself should expose a computed attribute
- you want attribute-style access on the class object
Consider @classmethod Too
A lot of "class property" requirements are actually clearer as a class method:
Calling AppConfig.version() is explicit and often easier to understand than introducing a custom descriptor.
Common Pitfalls
The biggest mistake is assuming @property creates a property on the class object. It does not. It creates a descriptor for instance access.
Another mistake is using a custom class-property descriptor when a simple class variable or @classmethod would be clearer.
People also forget that descriptors add complexity. If the value is static and simple, plain class attributes are easier.
Finally, if you validate through @property, store the underlying value under a different name such as _radius to avoid infinite recursion.
One more practical rule helps a lot: if you catch yourself building a writable class-property descriptor, stop and ask whether explicit class methods would be clearer. In many codebases, they are.
Summary
- In Python,
@propertycreates managed attributes on instances, not on the class object itself. - Most "class property" questions are really about ordinary instance properties.
- Use a plain class variable for simple shared data.
- Use a custom descriptor only when you truly need class-level computed attribute access.
- Consider
@classmethodif explicit method syntax is clearer than descriptor magic.

