Skip to main content
PyPI - Python Version PyPI - Version Ruff pre-commit.ci status https://codecov.io/gh/Nibblex/python-relattrs/graph/badge.svg?token=JL8M6865RB PyPI - License

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)

Source distribution for relattrs 2.0.2
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)

Table of built distributions (wheels) for relattrs 2.0.2
File Interpreter ABI Platform Actions
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 log

Release 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 log

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

Select from 2 files

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 log

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

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page