Skip to main content

Store and modify global app state in JSON (Python dictionary) to re-render front-end components.

Project description

jsonstate

Manage global App state in a JSON (Python dictionary).

Installation

  • pip install jsonstate

Usage

from jsonstate import State

state = State({
    "title": "State Example",
    "profile": {
        "name": "Foo",
    },
    "products": [
        {"name": "Foo", "description": "Foo spam"},
        {"name": "Bar", "description": "Bar spam"},
    ]
})
print_event = lambda **kwargs: print("Event", kwargs)
state.callbacks(key="title").append(print_event)
state['profile'].callbacks(key="name").append(print_event)
state.callbacks(key="products").append(print_event)

# This statement updates the state and also invokes on_change callback:
state["title"] = "Eggs"
# Event {'new_value': 'Eggs', 'old_value': 'State Example', 'action': 'update'}

state["profile"]["name"] = "Spam"
# Event {'new_value': 'Spam', 'old_value': 'Foo', 'action': 'update'}

# This statement also updates the state and invokes on_change callback:
state["products"].append({"name": "Eggs", "description": "Eggs spam"})
# Event {'new_value': {"name": "Eggs", "description": "Eggs spam"}, 'action': 'append'}

Development

Commonly used commands for package development:

  • make check - run unit tests and linters.
  • make fix - format code and fix detected fixable issues.
  • make publish - publishes current package version to pypi.org.
  • make compile - bump and freeze dependency versions in requirements*.txt files
  • make sync - upgrade installed dependencies in Virtual Environment (executed after make compile)

Toolset

This package uses these cutting edge tools:

  • ruff - for linting and code formatting
  • mypy - for type checking
  • pip-audit - for known vulnerability detection in dependencies
  • deadcode - for unused code detection
  • pytest - for collecting and running unit tests
  • coverage - for code coverage by unit tests
  • hatch - for publishing package to pypi.org
  • uv - for Python virtual environment and dependency management
  • pyproject.toml - configuration file for all tools
  • Makefile - aliases for commonly used command line commands

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

jsonstate-0.0.4.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

jsonstate-0.0.4-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file jsonstate-0.0.4.tar.gz.

File metadata

  • Download URL: jsonstate-0.0.4.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for jsonstate-0.0.4.tar.gz
Algorithm Hash digest
SHA256 41a2ac67171276a9e25a0351b752dc793ce1e6fa1b8d5ec69a922f8b1d958dab
MD5 e25b5f6210290f68f1495c2a40ee8357
BLAKE2b-256 92d877c94b32dc8e05dbaae5243600793f3afe621160f833b0032758b78e513e

See more details on using hashes here.

File details

Details for the file jsonstate-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: jsonstate-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for jsonstate-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 454ce9d0f956f2d3952927988ce3d777102c2fc94bafa379104fdcbebe677bcf
MD5 e8ee0fc1234bcbb3603990fcb8c04aca
BLAKE2b-256 1b56277700a2df2314214a660696db6c885b0b90ccbe9470f416cb39d3e94e51

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