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['products'].callbacks().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': 'add'}

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.5.tar.gz (5.4 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.5-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jsonstate-0.0.5.tar.gz
Algorithm Hash digest
SHA256 4b93d1bc944253d733a215594c74ba8213b1511b5da634b74bcf6e48ffd1400b
MD5 665938864ec3d405d623d00ea7ea09cc
BLAKE2b-256 6ea871829d78d5905264358637f44f921c2319ec20ad01827447627945673a70

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jsonstate-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c3053fd53cfc649b641214dc1afc44df076ebcdcd0d3b50dd995e3be2fddf9fa
MD5 c6d840fb187f1413845767a6193deca6
BLAKE2b-256 45113611bb9c29c10f21ff62c84fbf419fd4f0c4b5b7ef028e9b6674f00c04ce

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