Skip to main content

A simple global state manager to help pass values through mautiple py files

Project description

State Handler

A lightweight global state manager for Python.


Features

  • Simple global key-value storage
  • Accessible across your entire Python project
  • Lightweight and dependency-free
  • Event callbacks on state changes
  • Optional persistence support

Installation

pip install state-handler

Quick Start

from state_handler import state

# Set a value
state.set("username", "bob")

# Get a value
print(state.get("username"))

API Reference

set(key, value)

Store a value in global state.

get(key, default=None)

Retrieve a value.

delete(key)

Remove a value.

exists(key)

Returns True if key exists.

all()

Returns a copy of all current state values.


Persistence

state.save("state.json")
state.load("state.json")

Saves and loads state from a file.


Callbacks (Events)

Run code whenever state changes:

def on_change(key, old, new):
    print(f"{key} changed from {old} to {new}")

state.register_callback(on_change)

state.set("mode", "debug")
state.set("mode", "release")

Example

import state_handler as sh

sh.state.set("mode", "debug")

if sh.state.get("mode") == "debug":
    print("Debug mode is ON")

Why use this?

Sometimes you need shared state across multiple files without passing variables around. This package provides a simple global state system for Python projects.


Roadmap

  • Nested state support
  • Async event listeners
  • Thread-safe mode
  • State syncing between processes

License

MIT License

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

state_handler-0.1.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

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

state_handler-0.1.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file state_handler-0.1.1.tar.gz.

File metadata

  • Download URL: state_handler-0.1.1.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for state_handler-0.1.1.tar.gz
Algorithm Hash digest
SHA256 da01788b11fd6bfeeb00883312f1d9e600c35a2512993ad01fba782850d4071a
MD5 38dc10a8e1ac89ab1523e9e5c1b9b0e3
BLAKE2b-256 f4bbfc278a72655571aed9677be98c3a73d920a58bfc430d28c2d3b527bb1aa5

See more details on using hashes here.

File details

Details for the file state_handler-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: state_handler-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for state_handler-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 676582700e75e2c4883e343d5ae5f115b9d5f15a1720dc03b82f356416b20733
MD5 6468a7a8318a6c2afbf27faaa8c29062
BLAKE2b-256 b60e8cb9041e3c2ef7d2baa8836312a8c0dfd26d694a32a4fea2dd79450c3f39

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