observer-pattern
Simple Observer Pattern Implementation
from observer_pattern import Observable
counter = 0
def plus_n(n):
global counter
counter += n
def plus_2n(n):
global counter
counter += 2*n
def plus_3n(n):
global counter
counter += 3*n
observable = Observable()
observable.subscribe(plus_n)
observable.subscribe(plus_2n)
observable.subscribe(plus_3n)
observable.notify(2)
observable.unsubscribe(plus_3n)
observable.notify(5)
print(counter) # 27
print(len(observable)) # 2
You can pass any number of args and kwargs
def print_product(a, b):
print(a * b)
observable = Observable()
observable.subscribe(print_product)
observable.notify(3, b=5) # 15
print(print_product in observable) # True
Metadata
Release files for observer-pattern 1.0.0
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 |
|---|---|---|---|---|
| observer_pattern-1.0.0.tar.gz | 14.2 kB | Without provenance | Details for observer_pattern-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| observer_pattern-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for observer_pattern-1.0.0-py3-none-any.whl |
Total release size: 28.4 kB
Release files / observer_pattern-1.0.0.tar.gz
| Download URL | observer_pattern-1.0.0.tar.gz |
|---|---|
| Size | 14.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c045e42434b0462507ef7000cf54c1cd2c2f02f02d804a59e6866d2fe54071ac
|
|
BLAKE2b-256 checksum How to use checksums |
ca83708013ca685377e3883ca521e221a54871aaa0403275017159548b4c2bf0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.0
|
Release files / observer_pattern-1.0.0-py3-none-any.whl
| Download URL | observer_pattern-1.0.0-py3-none-any.whl |
|---|---|
| Size | 14.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2903f0075dca46efd446f8996d78770d65966a6b1ab26a2f530c9c6fc5f715b9
|
|
BLAKE2b-256 checksum How to use checksums |
39affcf790b0200f3304d94e69952cd5c3a2ddb940c1cd2cf514e7a5d6426087
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.0
|
Security for observer-pattern 1.0.0
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.