Skip to main content

Tiny observer for the attributes of Python objects.

Project description

objerve

A tiny observer for the attributes of Python objects.

GitHub issues GitHub stars GitHub license

Installation

objerve can be installed by running pip install objerve

Example Usage

Let's say you have a class like that;

class M:
    qux = "blue"

    def __init__(self):
        self.bar = 55
        self.foo = 89
        self.baz = 121

To watch the changes, you need the add the @watch as a class decorator and watch_dict as a class variable.

watch_dict keys should be selected from __init__ or class variables and the values can be defined as a set, get and del. from objerve import watch

@watch
class M:
    watch_dict = {"foo": "set", "bar": "get", "baz": "del", "qux": "set"}
    qux = "blue"

    def __init__(self):
        self.bar = 55
        self.foo = 89
        self.baz = 121


m = M()
m.bar = 233


def abc():
    m.foo += 10


m.qux = "red"


def get_foo(m):
    m.bar


abc()
del m.baz
get_foo(m)

Output:

Set | foo = 89
  File "/home/blue/objerve/examples/example.py", line 11, in __init__
    self.foo = 89

Set | qux = red
  File "/home/blue/objerve/examples/example.py", line 23, in <module>
    m.qux = "red"

Set | foo = 99
  File "/home/blue/objerve/examples/example.py", line 20, in abc
    m.foo += 10

Delete | baz
  File "/home/blue/objerve/examples/example.py", line 31, in <module>
    del m.baz

Get | bar
  File "/home/blue/objerve/examples/example.py", line 27, in get_foo
    m.bar

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

objerve-0.1.0.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

objerve-0.1.0-py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page