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 Coverage 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

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.3.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

bigbrother-0.1.3-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bigbrother-0.1.3.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for bigbrother-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5fe855efd4e364f6f3a14afad69f235bde93b6c2703dd6d4ec42c1f3a6be6747
MD5 546c590ec2e36bb0b83e7075fadc9df2
BLAKE2b-256 0c35de395ce759d2035e2f9d182b5bd6d09e3c5cedea2c36f8c5e4904a5422c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bigbrother-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for bigbrother-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ed9f931a0c90426a62c3af0441af62c78c3e637935669cae61d9165d3cc7cc14
MD5 d8ca3ffa4c4bf171e461577eb3aa837a
BLAKE2b-256 a96769d33da6b525988f59031f1d521e845e8810e7304b4e0366111bddeb11de

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