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.1.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.1.1-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hookup-0.1.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.1.1.tar.gz
Algorithm Hash digest
SHA256 ca1671d3093c19418c4f6ca939f0f6d5b57d8e054771d025649ed802711a6f30
MD5 c7d840a14f15747423c2634a3e24a3a9
BLAKE2b-256 5eeea3b4c76949c6879d3ed8140c49972040259c7098dacf7941baa5ee2986e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hookup-0.1.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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c4670c3c50ea3294e166b5aebedd1a393e2098c0fa9dbe9f78a33281a1c8c430
MD5 0546b9ee97f8db421d96230cdea6bf20
BLAKE2b-256 d2c19b462395a615c74d4a35c6381d30f1675791d0957401283710d706994041

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