https://github.com/furkanonder/objerve
A tiny observer for the attributes of Python objects.
https://github.com/furkanonder/objerve
hook observer
Last synced: about 1 month ago
JSON representation
A tiny observer for the attributes of Python objects.
- Host: GitHub
- URL: https://github.com/furkanonder/objerve
- Owner: furkanonder
- License: mit
- Created: 2022-06-14T20:43:02.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-10T14:23:54.000Z (almost 3 years ago)
- Last Synced: 2025-04-07T13:04:07.289Z (2 months ago)
- Topics: hook, observer
- Language: Python
- Homepage:
- Size: 175 KB
- Stars: 34
- Watchers: 2
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Installation
_objerve_ can be installed by running `pip install objerve`
## Example Usage
Let's say you have a class like that;
```python
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. Within the
arguments of the `watch` decorator you should pass in lists for the keyword arguments of
the attributes you wish to watch.```python
from objerve import watch@watch(set={"foo", "qux"}, get={"bar", "foo"}, delete={"baz"})
class M:
qux = "blue"def __init__(self):
self.bar = 55
self.foo = 89
self.baz = 121m = M()
m.bar = 233def abc():
m.foo += 10m.qux = "red"
def get_foo(m):
m.barabc()
m.foo
del m.baz
get_foo(m)
```Output:
```sh
Set | foo = 89
File "/home/blue/objerve/examples/example.py", line 9, in __init__
self.foo = 89Set | qux = red
File "/home/blue/objerve/examples/example.py", line 21, in
m.qux = "red"Get | foo
File "/home/blue/objerve/examples/example.py", line 18, in abc
m.foo += 10Set | foo = 99
File "/home/blue/objerve/examples/example.py", line 18, in abc
m.foo += 10Get | foo
File "/home/blue/objerve/examples/example.py", line 29, in
m.fooDelete | baz
File "/home/blue/objerve/examples/example.py", line 30, in
del m.bazGet | bar
File "/home/blue/objerve/examples/example.py", line 25, in get_foo
m.bar
```