liiliepy State Management Library
A lightweight state management library for lilliepy, inspired by state management solutions like Zustand and XState.
Features
- State Containers: Manage global or local state in an intuitive way.
- Selectors: Derive state slices to minimize unnecessary re-renders.
- Transitions: (Optional) Add finite state machine (FSM) logic for more complex scenarios.
Installation
Simply include the liiliepy_state.py file in your project.
# Clone the repository (if applicable)
git clone <repository_url>
Quick Start
1. Define a Store
Create a state container to manage your application's state.
from liiliepy_state import StateContainer
# Define your store
counter_store = StateContainer({"count": 0})
# Define actions
def increment():
counter_store.set_state(lambda state: {"count": state["count"] + 1})
def decrement():
counter_store.set_state(lambda state: {"count": state["count"] - 1})
2. Use the Store in liiliepy Components
Connect your store to liiliepy components using the use_store hook.
from reactpy import component, html
from liiliepy_state import use_store
from my_store import counter_store, increment, decrement
@component
def CounterComponent():
state, _ = use_store(counter_store)
return html.div(
html.button({"onClick": lambda: decrement()}, "-"),
html.span(f"Count: {state['count']}"),
html.button({"onClick": lambda: increment()}, "+"),
)
3. Advanced Usage: Finite State Machines (FSM)
For more complex scenarios, use the FSMContainer to add finite state transitions.
from liiliepy_state import FSMContainer
# Define state transitions
fsm_store = FSMContainer("idle", {
"idle": {"START": "running"},
"running": {"STOP": "idle"},
})
# Transition actions
def start():
fsm_store.transition("START")
def stop():
fsm_store.transition("STOP")
Component Example
@component
def FSMComponent():
state, _ = use_store(fsm_store)
return html.div(
html.span(f"State: {state}"),
html.button({"onClick": lambda: start()}, "Start"),
html.button({"onClick": lambda: stop()}, "Stop"),
)
Roadmap
- Middleware Support: Add features like logging and persistence.
- Optimizations: Improve performance for concurrent updates.
- Testing: Cover edge cases and stress-test the library.
License
This project is licensed under the MIT License. Feel free to use and contribute!
Metadata
Release files for lilliepy-state 0.1
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 |
|---|---|---|---|---|
| lilliepy_state-0.1.tar.gz | 3.2 kB | Without provenance | Details for lilliepy_state-0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lilliepy_state-0.1-py3-none-any.whl | Python 3 | none | any | Details for lilliepy_state-0.1-py3-none-any.whl |
Total release size: 6.4 kB
Release files / lilliepy_state-0.1.tar.gz
| Download URL | lilliepy_state-0.1.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
076116732f8c8bd940a2ba6d28b226d091a336586c8b6db470bff0efa7e8ff99
|
|
BLAKE2b-256 checksum How to use checksums |
8adbe4c816bd683aa000f6fcd1b0093be79f97b161d3075b55b688aaf8bae78c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.1
|
Release files / lilliepy_state-0.1-py3-none-any.whl
| Download URL | lilliepy_state-0.1-py3-none-any.whl |
|---|---|
| Size | 3.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
52232bbab3bbee6d901baf5527cd2c07bc0164e6d7cd5b5f8fdc15c8ec7c0a39
|
|
BLAKE2b-256 checksum How to use checksums |
f4a78836b1de58271f4d818e0d221201af231555935d1e2f6ffc691874916c97
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.1
|
Security for lilliepy-state 0.1
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.