python-relattrs
relattrs is a small utility library for recursively getting, setting, checking, and deleting attributes of an object using a dotted string representation. This can be particularly useful when dealing with nested objects.
The library provides four main functions:
rgetattr: Recursively gets an attribute from an object.
rhasattr: Recursively checks if an attribute exists on an object.
rsetattr: Recursively sets an attribute on an object.
rdelattr: Recursively deletes an attribute from an object.
Installation
You can install relattrs via pip:
pip install relattrs
Usage
rgetattr
Recursively gets an attribute from an object based on a dotted string representation.
Example:
from relattrs import rgetattr
class A:
class B:
class C:
value = 1
obj = A()
print(rgetattr(obj, "B.C.value")) # Output: 1
Example with *sep* parameter:
from relattrs import rgetattr
class A:
class B:
class C:
value = 1
obj = A()
print(rgetattr(obj, "B|C|value", sep="|")) # Output: 1
Example with *default* parameter:
from relattrs import rgetattr
class A:
class B:
class C:
value = 1
obj = A()
print(rgetattr(obj, "B.C.val", "Not found")) # Output: Not found
rhasattr
Recursively checks if an object has an attribute based on a dotted string representation.
Example:
from relattrs import rhasattr
class A:
class B:
class C:
value = 1
obj = A()
print(rhasattr(obj, "B.C.value")) # Output: True
print(rhasattr(obj, "B.C.val")) # Output: False
Example with *sep* parameter:
from relattrs import rhasattr
class A:
class B:
class C:
value = 1
obj = A()
print(rhasattr(obj, "B|C|value", sep="|")) # Output: True
print(rhasattr(obj, "B|C|val", sep="|")) # Output: False
rsetattr
Recursively sets an attribute on an object based on a dotted string representation.
Example:
from relattrs import rsetattr
class A:
class B:
class C:
value = 1
obj = A()
rsetattr(obj, "B.C.value", 2)
print(obj.B.C.value) # Output: 2
Example with *sep* parameter:
from relattrs import rsetattr
class A:
class B:
class C:
value = 1
obj = A()
rsetattr(obj, "B|C|value", 2, sep="|")
print(obj.B.C.value) # Output: 2
rdelattr
Recursively deletes an attribute from an object based on a dotted string representation.
Example:
from relattrs import rdelattr, rhasattr
class A:
class B:
class C:
value = 1
obj = A()
rdelattr(obj, "B.C.value")
print(rhasattr(obj, "B.C.value")) # Output: False
Example with *sep* parameter:
from relattrs import rdelattr, rhasattr
class A:
class B:
class C:
value = 1
obj = A()
rdelattr(obj, "B|C|value", sep="|")
print(rhasattr(obj, "B|C|value", sep="|")) # Output: False
License
This project is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for relattrs 2.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| relattrs-2.0.2.tar.gz | 5.1 kB | With provenance | Details for relattrs-2.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| relattrs-2.0.2-py3-none-any.whl | Python 3 | none | any | Details for relattrs-2.0.2-py3-none-any.whl |
Total release size: 9.5 kB
Release files / relattrs-2.0.2.tar.gz
| Download URL | relattrs-2.0.2.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
314a4e417ae544c8a0679fcde0461c8e308bb36ce31b4332c42f310e93a67615
|
|
BLAKE2b-256 checksum How to use checksums |
08205baf427ee665f6b391ce472191a6d8514cb76732d73678388c54714cbcbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / relattrs-2.0.2-py3-none-any.whl
| Download URL | relattrs-2.0.2-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d416e6b8def87bef4035ab282cf3497c330401d4e695733b706dc349f969a447
|
|
BLAKE2b-256 checksum How to use checksums |
918fae2a3e9e01a00c26d359da2efb5ea3095b065bda1f4055af423215fcda61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logSecurity for relattrs 2.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for relattrs-2.0.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.