Skip to main content

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:

  • str
  • int
  • float
  • bool
  • None

This prevents unexpected behavior with mutable objects.

❌ Not recommended for:

  • list
  • dict
  • set
  • 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

refvar-0.2.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

refvar-0.2.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

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

Hashes for refvar-0.2.0.tar.gz
Algorithm Hash digest
SHA256 083eb131cda12223bd6c2b7c0d0023ad39bd1a1d1eacd6108e182d172d8945be
MD5 c8de92a2196d1c40c1f649d49691610d
BLAKE2b-256 c4d160047076315fa82a52ec3510baba42198efde182a000c47fb9dedc6914bf

See more details on using hashes here.

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

Hashes for refvar-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 47dcfe18c4a34fe28919d1c218e271241e586960467adc5b5bb25116174693cc
MD5 2fc44e558dceff8952a485b8aa9b6f45
BLAKE2b-256 0f9bc0b583b902ffcf1087bc186f9590fe3f2cf165b6c329697c63c9027ad801

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