Skip to main content

A library for object observability

Project description

bigbrother

An evil, awful, terrible, no-good library for watching objects for mutation. Do not use this library.

Build Status codecov License PyPI

Overview

bigbrother is a mutation observer library. You can use it to watch your objects for changes. When your object changes, bigbrother will trigger your choice of callback.

x = {1: "a", 2: "b", 3: "c"}

def track_changes(obj, method, ref, call_args, call_kwargs):
    print(f"method: {method}, args: {args}, kwargs: {kwargs}")

x = watch(x, track_changes)

x[1] = "x"

# prints: method: setitem, args: (1, 'x'), kwargs: {}

bigbrother can also embed itself recursively in your object by passing in argument deepstate=True.

Callback

def callback(obj, method, ref, call_args, call_kwargs):
    '''Callback called when object is mutated

    Args:
        obj (Any): The object being mutated via `method`
        method (str): The method called on the object (dunders removed)
        ref (Any): Reference object. If callback installed recursively, `ref` will be the entrypoint
        call_args (Tuple[Any]): Positional arguments that `method` was called with on `obj`
        call_kwargs (Dict[Any, Any]): Keyword arguments that `method` was called with on `obj`
    '''

Supported types

Builtins

Most builtin types are read-only and cannot have their method structure mutated, so we observe via replacement with thin wrappers.

  • list via _ObservedList
    • append
    • clear
    • extend
    • insert
    • pop
    • remove
    • sort
    • __setattr__
    • __setitem__
  • dict via _ObservedDict
    • clear
    • pop
    • popitem
    • update
    • __setattr__
    • __setitem__
  • set via _ObservedSet
    • add
    • clear
    • difference_update
    • discard
    • intersection_update
    • pop
    • remove
    • symmetric_difference_update
    • update
    • __setattr__

Libraries

  • pydantic.BaseModel

[!NOTE] This library was generated using copier from the Base Python Project Template repository.

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

bigbrother-0.1.4.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

bigbrother-0.1.4-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file bigbrother-0.1.4.tar.gz.

File metadata

  • Download URL: bigbrother-0.1.4.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for bigbrother-0.1.4.tar.gz
Algorithm Hash digest
SHA256 fcde068a71605e209197405759086e496357f6203a49f3dbebaa64dd4ec26151
MD5 83160e55dc6ffcf9e43c4cb0e5f85916
BLAKE2b-256 ea6acc89eb14f4213850c347c7ad540c82005c1d7c0cd899a7a6227a857260cd

See more details on using hashes here.

File details

Details for the file bigbrother-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: bigbrother-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for bigbrother-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3098ce8a22a1ae9b3da71c29deac3e7da9cfd35e88318ff096169f7d4bc3a38b
MD5 d5984f446b5eeddff9108522d417fb35
BLAKE2b-256 31bb5a78a2f0d015d892163a9bc447f4ff31b7e4f81da76137819ab4d733f690

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