Skip to main content

Reactive signals for Python with async support

Project description

reaktiv Python Version PyPI Version License

Reactive Signals for Python with first-class async support, inspired by Angular's reactivity model.

import asyncio
from reaktiv import Signal, ComputeSignal, Effect

async def main():
    count = Signal(0)
    doubled = ComputeSignal(lambda: count.get() * 2)

    async def log_count():
        print(f"Count: {count.get()}, Doubled: {doubled.get()}")

    Effect(log_count).schedule()
    count.set(5)  # Triggers: "Count: 5, Doubled: 10"
    await asyncio.sleep(0)  # Allow effects to process

asyncio.run(main())

Features

Angular-inspired reactivity
First-class async/await support
🧠 Automatic dependency tracking
💡 Zero external dependencies
🧩 Type annotations throughout
♻️ Efficient memory management

Installation

pip install reaktiv
# or with uv
uv pip install reaktiv

Quick Start

Basic Reactivity

import asyncio
from reaktiv import Signal, Effect

async def main():
    name = Signal("Alice")

    async def greet():
        print(f"Hello, {name.get()}!")

    # Create and schedule effect
    greeter = Effect(greet)
    greeter.schedule()

    name.set("Bob")  # Prints: "Hello, Bob!"
    await asyncio.sleep(0)  # Process effects

asyncio.run(main())

Async Effects

import asyncio
from reaktiv import Signal, Effect

async def main():
    data = Signal([])

    async def fetch_data():
        await asyncio.sleep(0.1)
        data.set([1, 2, 3])

    Effect(fetch_data).schedule()
    await asyncio.sleep(0.2)  # Allow async effect to complete

asyncio.run(main())

Computed Values

from reaktiv import Signal, ComputeSignal

# Synchronous context example
price = Signal(100)
tax_rate = Signal(0.2)
total = ComputeSignal(lambda: price.get() * (1 + tax_rate.get()))

print(total.get())  # 120.0
tax_rate.set(0.25)
print(total.get())  # 125.0

Core Concepts

Signals

import asyncio
from reaktiv import Signal

async def main():
    user = Signal("Alice")
    print(user.get())  # "Alice"
    user.set("Bob")
    await asyncio.sleep(0)  # Process any dependent effects

asyncio.run(main())

Effects in Async Context

import asyncio
from reaktiv import Signal, Effect

async def main():
    stock = Signal(100.0)

    async def stock_ticker():
        price = stock.get()
        print(f"Current price: {price}")
        await asyncio.sleep(0.1)

    effect = Effect(stock_ticker)
    effect.schedule()
    
    stock.set(105.5)
    await asyncio.sleep(0.2)
    effect.dispose()

asyncio.run(main())

Inspired by Angular Signals • Built for Python's async-first world

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

reaktiv-0.2.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

reaktiv-0.2.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file reaktiv-0.2.0.tar.gz.

File metadata

  • Download URL: reaktiv-0.2.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.8

File hashes

Hashes for reaktiv-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8e9330c229ab5de2173722807f070f3234fca9927ed6b8bc9651d03c6593b3cb
MD5 3ae63a7d6e9557ac3e38062a32971367
BLAKE2b-256 a9f8a9ab8267157ea95120c1b840980d07dd988a584e9df955d10e95d82e6d8b

See more details on using hashes here.

File details

Details for the file reaktiv-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: reaktiv-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.8

File hashes

Hashes for reaktiv-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7519bdc52e0a88c1fab18d8d23f5db898a0ee0970517a24793f7aca591c4e7d
MD5 64e945cc5c8d68c19cad1a6c9dcc55e0
BLAKE2b-256 9ff9ab243d2bf1cd3b4b446ba8a3f75bb20d83a41ccd9886c8fc650158a3ef15

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