Pyloid Docs
GithubLanguage
  • 💎What is Pyloid?
  • Getting Started
    • Prerequisites
    • Create Pyloid App
  • Core Concepts
    • Thread Safety
  • API
    • Python (Backend)
      • Pyloid
      • BrowserWindow
      • Monitor
      • TrayEvent
      • Utility Functions
      • RPC
      • Store
    • Javascript (Frontend)
      • Event
      • BaseAPI
      • RPC
  • Guides
    • Load Webview
    • Serve Frontend
    • Calling Python from JS
    • Calling JS from Python
    • Keyboard Shotcuts
    • Notification
    • Tray
    • Timer
    • File Watcher
    • Clipboard
    • Window Position
    • Devtools
    • Window Drag Region
    • Window Radius And Transparent
    • Autostart
    • Production Utils
    • Desktop Monitor
    • File Dialog
    • Splash Screen
Powered by GitBook
On this page
  • Class Instantiation
  • Methods
  • 1. get
  • 2. set
  • 3. remove
  • 4. all
  • 5. purge
  • 6. save
  • Summary

Was this helpful?

Edit on GitHub
  1. API
  2. Python (Backend)

Store

The Store class is a lightweight key-value database used by creating it via app.store("store.json") from a Pyloid app instance. You can store any Python object that is JSON serializable, and the data is persistently managed as a database file.


Class Instantiation

store = app.store("store.json")
  • app: Pyloid instance (Pyloid)

  • "store.json": Path to the database file


Methods

1. get

store.get(key: str) -> Any

Description

Returns the value associated with the specified key. If the key does not exist, returns None.

Parameters

  • key (str): The key to retrieve

Returns

  • Any: The value stored for the key, or None if not found

Example

from src.pyloid.pyloid import Pyloid

app = Pyloid(app_name="Pyloid-App")
store = app.store("store.json")

store.set("user", {"name": "Hong Gil-dong", "age": 30})
user = store.get("user")
print(user)  # {'name': 'Hong Gil-dong', 'age': 30}
print(store.get("nonexistent_key"))  # None

2. set

store.set(key: str, value: Any) -> bool

Description

Adds or updates a key-value pair in the database. The value must be a JSON-serializable Python object.

Parameters

  • key (str): The key to store

  • value (Any): The value to store (must be JSON serializable)

Returns

  • bool: Always returns True

Example

store = app.store("store.json")
store.set("settings", {"theme": "dark", "notifications": True})
store.set("counter", 42)
store.set("items", ["apple", "banana", "orange"])

3. remove

store.remove(key: str) -> bool

Description

Deletes the value associated with the specified key from the database.

Parameters

  • key (str): The key to remove

Returns

  • bool: Returns True if the key was deleted, False if the key did not exist

Example

store = app.store("store.json")
store.set("temp", "temporary data")
store.remove("temp")  # True
store.remove("nonexistent_key")  # False

4. all

store.all() -> List[str]

Description

Returns a list of all keys stored in the database.

Returns

  • List[str]: A list of all stored keys

Example

store = app.store("store.json")
store.set("key1", "value1")
store.set("key2", "value2")
keys = store.all()
print(keys)  # ['key1', 'key2']

5. purge

store.purge() -> bool

Description

Deletes all keys and values from the database.

Returns

  • bool: Always returns True

Example

store = app.store("store.json")
store.set("key1", "value1")
store.set("key2", "value2")
store.purge()  # True
print(store.all())  # []

6. save

store.save(option: Optional[int] = None) -> bool

Description

Saves the current state of the database to the file. You can specify orjson serialization options with the option parameter.

Parameters

  • option (Optional[int]): (Optional) orjson.OPT_* flag

Returns

  • bool: Returns True if saving was successful, False otherwise

Example

store = app.store("store.json")
store.set("key", "value")
store.save()  # True

Summary

  • Store is created from a Pyloid app instance using app.store("store.json").

  • You can store any Python object that is JSON serializable, such as strings, numbers, lists, and dictionaries.

  • Main methods: get, set, remove, all, purge, save

  • Data is persistently managed as a database file.

PreviousRPCNextJavascript (Frontend)

Last updated 29 days ago

Was this helpful?