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",
    "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.callbacks(key="products").append(print_event)

# This statement updates the state and also invokes on_change callback:
state["products"]["name"] = "Eggs"
# Event {'new_value': 'Eggs', 'old_value': 'State Example', '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.3.tar.gz (4.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.3-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jsonstate-0.0.3.tar.gz
Algorithm Hash digest
SHA256 9c4518859ea0e354747f40eadc9941c5fae434a0d0feb8e9c42754b449d70c8d
MD5 6d3e4c1f5269312449ac4c32274fc5b2
BLAKE2b-256 4b1fa0e75427b75c10c3ff610eea659ebcdae86f5fd4f7efdc0979bb98d9c596

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jsonstate-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b550f6397b4ccdd9982717a114ee5ea80e77e1e81f5ca8b5351dcba9e2cc5efc
MD5 22b62c7f7a852e1f6de4ed2991fe818a
BLAKE2b-256 e495aedd6843bb75db427860438359b4c9747b9477cc85304e836ba60ae1e8fa

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