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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jsonstate-0.0.6.tar.gz
Algorithm Hash digest
SHA256 e7f5259946cc9d240d7e17681ae1add8b9161a041f3327736c9b76aa7f0507e2
MD5 05246ad96a267978b422b8f11f5b0ea7
BLAKE2b-256 71d0063885192c6e1aebe29e6da093f215052df1564c9e72771b9578f879a629

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jsonstate-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 204fee0feb786fddab20e12387328d20b9fcb3f217f10a4c0b01d6ae6d4f65f3
MD5 98d347e11ea0bcd7c856f68a94705a50
BLAKE2b-256 34979f621886021cf61e602409838098a5802ee3691650ded7496e6a5d0016f4

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