Skip to main content

A pure python object change and history tracker. Monitor all changes in your objects lifecycle and trigger callback functions to capture them.

Project description

object-tracker

A pure python object state tracker. Monitor all changes in your object’s lifecycle, query the history changelog, and trigger callback functions to capture them.

View the Github repository and the official docs.

$ pip install object-tracker

Tested for python 3.6, 3.7 and above.

Key Features

  • Determine if a python object has changed state during it’s lifecycle.

  • Investigate change history by querying a structured changelog.

  • Trigger callback functions whenever an (or any) attribute has changed.

  • Use it as a decorator, a class mixin or on its own.

License

Copyright (c) Saurabh Pujari
All rights reserved.

This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree.

Usage :

Use the @track decorator to track an object’s attributes.

from object_tracker import track

def observer(attr, old, new):
    print(f"Observer : {attr} -> {old} - {new}")

@track('name', 'age', observers=[observer,])
class User:
    def __init__(self, name, age):
        self.name = name
        self.age = age

user = User(name='Alice', age=30)
user.name = 'Bob'
# Observer : name -> Alice - Bob
print(user.tracker.has_changed())
# True
print(user.tracker.has_attribute_changed('name'))
# True

Or use the Tracker class

class MyClass:
    pass

obj = MyClass()
tracker = Tracker(obj)
obj.attribute = 'new_value'
print(tracker.has_changed(obj))
# True

Or use it with the mixin class TrackerMixin:

from object_tracker import TrackerMixin, Tracker

 class User(TrackerMixin):
     def __init__(self, name, age):
         self.name = name
         self.age = age
         self.tracker = Tracker()

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

object-tracker-2.0.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

object_tracker-2.0.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file object-tracker-2.0.0.tar.gz.

File metadata

  • Download URL: object-tracker-2.0.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.13

File hashes

Hashes for object-tracker-2.0.0.tar.gz
Algorithm Hash digest
SHA256 4c87c9ffddff9d2434f122446b9ca60c87f210d1c7e210043091ce3f97cc7f8f
MD5 f4599418114747dcd0b5e06717a37ae1
BLAKE2b-256 3a6c55e5f7a3cc83216578b3893a13f9cb6d4154c8a234033d7762d346a69d11

See more details on using hashes here.

File details

Details for the file object_tracker-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for object_tracker-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 409d5d6ea7bb8c363382d4391f6606e747d144499af3d2f9dcdd8daa82ffb906
MD5 1f1095e91f84808754de1e0b3a857dfc
BLAKE2b-256 0d3371b54d414e904df31f72be3a16391f254deee0633488a22c24cec912099d

See more details on using hashes here.

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