Skip to main content

Watch attributes on a class and trigger a callback on change

Project description

Hookup is a Python decorator to monitor one or more attributes on a given object, and trigger a callback function to be called when the attribute(s) value changes.

Example:

from hookup import hookup

@hookup(attrs=["version"], callback="update_version")
class Software:
    def __init__(self):
        version = 1

    def update_version(self):
        # This is the callback function that will be called when the attribute's value changes
        with open("version.txt") as _file:
            _file.write(self.version)

software = Software()
software.version=2

Installation

To install Hookup, simply:

$ pip install hookup

Usage

Hookup is designed to be used as a decorator on a class:

@hookup(attrs=["version"], callback="update_version")
class Software:

You must pass in the two required arguments:

  1. attrs - a List of attributes that will be watched for changes
  2. callback - a function belonging to the class used as a callback

Upon the value of any watched attribute (attrs) changing from one value to another, the callback function will be executed.

The callback function will be called with no additional parameters. For example, the following would both be valid callbacks:

def callback(self):
def callback(self, option="default"):

Contributing

  1. Check for open issues or open a new issue to kick off discussion
  2. Fork the repository on Github, create a branch and make your code changes
  3. Write a test which shows that the bug was fixed, or that the new feature works as expected
  4. Send a PR with a clear description of the change

Changelog

0.1.1 (2021-11-10)

  • Initial release

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

hookup-0.0.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hookup-0.0.1-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file hookup-0.0.1.tar.gz.

File metadata

  • Download URL: hookup-0.0.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.10 Linux/4.19.104-microsoft-standard

File hashes

Hashes for hookup-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9914b75889265e50052fa46c339df3681ca5128e6f51593c3aee0833eb5f0622
MD5 f44bc9f41a9148c36cafb8d1be41c27b
BLAKE2b-256 2f3cf3b5848fd2fca8d8addc9fa12e59ee602ab5a8d57da9e6b08a4e15af280d

See more details on using hashes here.

File details

Details for the file hookup-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: hookup-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.10 Linux/4.19.104-microsoft-standard

File hashes

Hashes for hookup-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f5054bb03a25f7557c718645ef5575505204ec23aea0401c4ef4032225baa76a
MD5 8cf9bbefd3e7aa7b4955785ecb26e480
BLAKE2b-256 8555cfa5983eacad196c285ab845c79693f1880a455a5756006665a84bb334c1

See more details on using hashes here.

Supported by

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