observable_variable
Do you want to call a function every time a variable gets a new value?
This package allows you to create an observable. This instance of the ObservableVariable class has an attribute value. If you set a new value to this attribute, every callback will be called. You can add callbacks by calling the method bind with the function and arguments to be passed to the callback. Removing is as easy as to call unbind with the same callback and arguments or by calling unbind_all to remove all bound callbacks for this observable. By default the new value will be the first argument to be passed to the callback. To disable this set the attribute send_value to False.
obs = ObservableVariable()
def my_callback(value, first_arg, second_arg):
print("New value:", value)
print("First argument:", first_arg)
print("Second argument:", second_arg)
# binding a callback
obs.bind(my_callback, "arg 1", "arg 2")
obs.value = 1
>>> New value: 1
>>> First argument: arg 1
>>> Second argument: arg 2
# unbinding a specific function-args-combination
obs.unbind(my_callback, "arg 1", "arg 2")
obs.value = 2
# callback not called
obs.bind(lambda value: print(value))
# unbind all callbacks
obs.unbind_all()
obs.value = 3
# again callback not called
# deactivating the sending of the new value as the first argument
obs.send_value = False
Metadata
Release files for observable-variable 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| observable_variable-0.0.2.tar.gz | 4.2 kB | Without provenance | Details for observable_variable-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| observable_variable-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for observable_variable-0.0.2-py3-none-any.whl |
Total release size: 8.4 kB
Release files / observable_variable-0.0.2.tar.gz
| Download URL | observable_variable-0.0.2.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
400a64d51f7aa9fbfd085a7ca906c5478389014ab3f8e89afa9e3eb40b60f052
|
|
BLAKE2b-256 checksum How to use checksums |
c81370d4b24675a59e758338dda0c2ad3eebf9e8bd62950f8dd2e4c49a20191e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.14
|
Release files / observable_variable-0.0.2-py3-none-any.whl
| Download URL | observable_variable-0.0.2-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ac610de572bd501e8628feacee60c42a1ea90834c51982a5896b9802ad069c00
|
|
BLAKE2b-256 checksum How to use checksums |
1798e13c6ab8dd56c33a61556e93f665f8a00ce0dbf5af74610a084c7bb76bac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.14
|
Security for observable-variable 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.