Metadata-Version: 2.4
Name: refvar
Version: 0.2.2
Summary: A lightweight reactive variable for simple values in Python.
Author-email: Emerson Erlando <emerson.mtr3@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Emerson
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/Emersonmtr3-prog/refvar
Project-URL: Repository, https://github.com/Emersonmtr3-prog/refvar
Keywords: reactive,state,variable,ref,lightweight
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# refvar

`refvar` is a lightweight and reactive library for reference management in Python. It allows you to create mutable references to immutable types (such as `str`, `int`, `bool`) that can be shared across multiple modules and updated centrally.

The main goal is to solve the problem where importing simple variables into different files loses the link to the original value. Additionally, the library supports **callbacks**, allowing functions to be executed automatically whenever the value changes.

---

## 🚀 Features

- Reactive variable (`Ref`)
- Callbacks triggered automatically when the value changes
- Extremely lightweight (< 50 lines)
- Zero dependencies
- Simple and intuitive API:

- `ref(value)`

- `ref(new_value)` `.set()` to update

- `ref()` `.get()` to retrieve the content

- `.bind()` `.unbind()` to call a function

---

## ✨ Features

- **Single Source of Truth:** Pass variables between modules without losing the reference.

- **Reactivity:** "Bind" callbacks that trigger when the value is updated.

- **Pythonic Syntax:** Implements magic methods (`__call__`, `__eq__`, `__bool__`, `__str__`) for intuitive use.

- **Lightweight:** Uses `__slots__` for high memory efficiency.

---

## ✅ Recommended Types

`Ref` is recommended for **simple and immutable values**:

- `str`

- `int`

- `float`

- `bool`

- `None`

This avoids 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` was specifically designed to be lightweight and simple.

---

## 📦 Installation

```bash
pip install refvar
```

---

## 🔧 Usage Example

### Basic Example

```python
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

value = x()
print(value, type(value)) # 20 <class 'int'>

value = x.get()
print(value, type(value)) # 20 <class 'int'>

value = x
print(value, type(value)) # 20 <class 'ref.core.Ref'>
