A lightweight reactive variable for simple values in Python.
Project description
refvar
A lightweight and dependency-free reactive variable system for Python.
refvar allows you to store simple values and automatically execute callbacks whenever the value changes.
Ideal for small applications, state control, or simple reactive patterns — without requiring any frameworks.
🚀 Features
- Reactive reference variable (
Ref) - Callbacks automatically triggered on value change
- Extremely lightweight (< 50 lines)
- Zero dependencies
- Clean and intuitive API:
ref(value)ref(new_value)to update.get(),.set(),.bind(),.unbind()
- Safe by design — supports only simple types
⚠ Supported Types
Ref is intentionally limited to immutable simple values:
strintfloatboolNone
This prevents unexpected behavior with mutable objects.
❌ Not recommended for:
listdictset- custom classes
- functions
- anything mutable
If you need full reactive programming, use a framework —
refvar is specifically designed for lightweight use.
📦 Installation
pip install refvar
🔧 Usage
Basic Example
from refvar import Ref
x = Ref(10)
def on_change(ref, new_value):
print("Value changed to:", new_value)
x.bind(on_change)
x(20) # Updates the value and triggers the callback
print(x.value) # 20
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file refvar-0.2.0.tar.gz.
File metadata
- Download URL: refvar-0.2.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
083eb131cda12223bd6c2b7c0d0023ad39bd1a1d1eacd6108e182d172d8945be
|
|
| MD5 |
c8de92a2196d1c40c1f649d49691610d
|
|
| BLAKE2b-256 |
c4d160047076315fa82a52ec3510baba42198efde182a000c47fb9dedc6914bf
|
File details
Details for the file refvar-0.2.0-py3-none-any.whl.
File metadata
- Download URL: refvar-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47dcfe18c4a34fe28919d1c218e271241e586960467adc5b5bb25116174693cc
|
|
| MD5 |
2fc44e558dceff8952a485b8aa9b6f45
|
|
| BLAKE2b-256 |
0f9bc0b583b902ffcf1087bc186f9590fe3f2cf165b6c329697c63c9027ad801
|