Skip to main content

A library for object observability

Project description

bigbrother

Mutation callbacks for Python objects.

Build Status codecov License PyPI

bigbrother watches mutable Python objects and calls your callback when they change. It is useful when another layer needs to mark state dirty, schedule a refresh, or react to model changes without replacing every mutation call.

Install

pip install bigbrother

Example

from bigbrother import watch

changes = []


def track_change(obj, method, ref, call_args, call_kwargs):
    changes.append((method, call_args, call_kwargs))


state = watch({"items": []}, track_change, deepstate=True)
state["items"].append("alpha")

assert changes[-1] == ("append", ("alpha",), {})

Keep the object returned by watch(). Built-in containers are observed by returning watched container instances.

Supported Objects

bigbrother supports:

  • list, dict, and set
  • pydantic.BaseModel
  • plain Python objects and dataclasses with a __dict__

Objects without a __dict__, such as slot-only classes, are returned unchanged. Callbacks fire before the underlying mutation completes.

Documentation

Development

make develop
python -m pytest bigbrother/tests -q

License

bigbrother is licensed under Apache-2.0.

[!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.5.tar.gz (12.4 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.5-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bigbrother-0.1.5.tar.gz
Algorithm Hash digest
SHA256 84b06ce63c4ed1b6eb470ec1c385bafd6f7b0e18147e980a2fe5536b14b5cda3
MD5 94199029b3cf0d08bfdd52460fe6dc60
BLAKE2b-256 647a3eba72d6d04398ac3972e55adf54f2ff1e645b8f0e8134bdb93a694c266c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for bigbrother-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0e3f9d344944e8d31289d55b9e1ad1977a8768b4ff3aa947ceec488e5f92d300
MD5 27cc63814073f2ed5c60b4910b131e62
BLAKE2b-256 dcb6dd7625026679293783248a5b7f503e513bfb77ad90eed87319bf4868af4b

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