This release is a pre-release and may not be stable for production use.
pyxpo-storage
Fast, synchronous key-value storage for pyxpo apps written in Python. The API follows
react-native-mmkv, and the AsyncStorage method names (set_item,
get_item, multi_get, merge_item) work too, without await. Reads come from memory, and every write is on disk
when set returns. It is plain Python on top of SQLite, so there is no native code to link.
from pyxpo_storage import storage
storage.set("user.name", "Asha")
storage.get_string("user.name") # "Asha"
Features
- Synchronous: no
await.storage.set(...)andstorage.get_string(...)just work. - Typed values: str, int, float, bool and bytes, plus JSON objects through
set_object. - Durable: every write is committed before the call returns. Uses a SQLite file with WAL.
- React hooks:
use_storage_string,use_storage_number,use_storage_boolean,use_storage_buffer,use_storage_objectre-render when the key changes anywhere, anduse_storage_listenerhears every change. - Several stores:
Storage(id="user-42")is a separate file, handy per user. - AsyncStorage names:
set_item,get_item,remove_item,merge_item,multi_get,multi_set,multi_remove,multi_merge,clear. - Recovers from damage: an unreadable file is moved aside as
.corruptand the app starts empty. - Typed: ships
py.typed. camelCase names (getString,setObject) also work.
Nothing is encrypted. Keep tokens and passwords in
pyxpo-secure-store.
Contents
| If you are... | Start here |
|---|---|
| Saving a setting | Quick start |
| Binding a value to the UI | Hooks |
| Storing a dict or list | Objects |
| Coming from AsyncStorage | AsyncStorage names |
| One store per user | Several stores |
| Exact signatures | API reference · Errors |
| Seeing it in a real app | Recipe: settings screen |
| Stuck | Testing · Troubleshooting · FAQ |
Platform support
| Target | What works |
|---|---|
| Android, API 24+ | Everything. File in files/pyxpo-storage. |
| iOS 15+ | Everything. File in Library/Application Support/pyxpo-storage. |
| Desktop window and tests | Everything. File in .pyxpo-data/storage in the working folder. |
| Web page | Everything. File in .pyxpo-data/storage, kept in the browser's IndexedDB across reloads. The web build loads Pyodide's sqlite3. |
Requires Python 3.9+ and pyxpo>=0.1.0a1. Set PYXPO_STORAGE_DIR to move the files (useful in tests).
Install
pip install pyxpo-storage
[tool.pyxpo]
modules = ["storage"]
Rebuild the app. There are no plugin options, no permissions and no native code.
Quick start
from pyxpo import Button, Text, View, component
from pyxpo_storage import storage, use_storage_number, use_storage_string
@component
def Home():
name, set_name = use_storage_string("user.name")
launches, set_launches = use_storage_number("launches")
return View(
Text("Hello, %s" % (name or "stranger")),
Text("Opened %d times" % (launches or 0)),
Button("Set name", lambda: set_name("Asha")),
Button("Count", lambda: set_launches(lambda old: (old or 0) + 1)),
Button("Forget me", lambda: storage.clear_all()),
)
Tip: The hooks re-render the component when the key changes from anywhere, including other screens and
storage.set(...)calls.set_value(None)deletes the key, andset_value(lambda old: ...)updates from the current value.
Values
storage.set("name", "Asha") # str
storage.set("launches", 3) # int stays an int
storage.set("ratio", 0.5) # float (finite only)
storage.set("dark", True) # bool
storage.set("blob", b"\x00\x01") # bytes
storage.get_string("name") # None when missing or another type
storage.get_number("launches")
storage.get_boolean("dark")
storage.get_buffer("blob")
storage.contains("name")
storage.delete("name") # a missing key is fine
storage.get_all_keys()
storage.clear_all()
A getter returns None when the key is missing or holds another type. set(key, None) raises TypeError: use
delete(key). NaN and infinity raise ValueError.
Objects
storage.set_object("prefs", {"dark": True, "font": 16})
storage.get_object("prefs") # {"dark": True, "font": 16}
Objects are stored as JSON strings. get_object returns None when the key is missing or not valid JSON.
Hooks
| Hook | Value type |
|---|---|
use_storage_string(key) |
str or None |
use_storage_number(key) |
int, float or None |
use_storage_boolean(key) |
bool or None |
use_storage_buffer(key) |
bytes or None |
use_storage_object(key) |
any JSON value, or None |
use_storage_listener(fn) |
calls fn(key) for every change while mounted |
All take an optional instance (another Storage). Each returns (value, set_value). A setter of the wrong type raises
TypeError.
AsyncStorage names
storage.set_item("token", "abc") # strings only
storage.get_item("token")
storage.merge_item("prefs", '{"font": 18}') # merges JSON objects, nested too
storage.multi_get(["a", "b"]) # [["a", "1"], ["b", None]]
storage.multi_set([["a", "1"], ["b", "2"]]) # one transaction
storage.multi_remove(["a", "b"])
storage.clear()
Several stores
from pyxpo_storage import Storage
user = Storage(id="user-42") # its own file
user.set("theme", "dark")
id is 1 to 120 letters, digits, ., _ or -. Objects with the same id and folder share data and listeners. Pass
path="/some/folder" to put the file elsewhere. Storage({"id": "user-42"}) also works, and
encryptionKey raises ValueError, because there is no encryption.
Listeners and size
sub = storage.add_on_value_changed_listener(lambda key: print("changed", key))
sub.remove()
storage.size # bytes on disk
storage.trim() # give the space of removed values back
Errors
| Error | When | What to do |
|---|---|---|
TypeError |
A key is not a non-empty string, a value is None, a dict or other unsupported type, set_item gets a non-string, or a hook setter gets the wrong type. |
Use set_object for dicts and lists, delete for removal. |
ValueError |
NaN or infinity, a bad store id, an unknown option, or an encryptionKey. |
Fix the argument. |
| A damaged file | The SQLite file cannot be read. | Nothing: it is moved to <id>.sqlite.corrupt, and the store starts empty. A message goes to stderr. |
| A listener that raises | Your callback has a bug. | The error is printed to stderr. Other listeners and the write still succeed. |
Config
Set PYXPO_STORAGE_DIR to override where the files live. default_directory() returns the folder in use.
Web and desktop
The desktop window and tests use .pyxpo-data/storage in the working folder. The web page runs the same Python code
in Pyodide. The web build loads Pyodide's sqlite3 package, and the page keeps .pyxpo-data/storage in the browser's
IndexedDB, so values survive a reload. Clearing site data in the browser removes them.
Recipe: settings screen
from pyxpo import Button, Switch, Text, View, component
from pyxpo_storage import use_storage_boolean, use_storage_object
@component
def Settings():
dark, set_dark = use_storage_boolean("settings.dark")
prof, set_prof = use_storage_object("profile")
prof = prof or {"name": "", "font": 16}
return View(
Text("Dark mode"),
Switch(value=bool(dark), on_value_change=set_dark),
Text("Font size %d" % prof["font"]),
Button("Bigger", lambda: set_prof(dict(prof, font=prof["font"] + 1))),
Button("Reset", lambda: set_prof(None)),
)
Production checklist
- Secrets are in
pyxpo-secure-store, not here. - Per-user data uses
Storage(id=...)and is cleared on sign-out (clear_all()). - You keep values small. Large data belongs in
pyxpo-sqliteor files. - On the web you accept that clearing site data removes the values.
- Your tests set
PYXPO_STORAGE_DIRto a temp folder. - You handle
Nonefrom every getter.
Testing
Point the storage at a temp folder and use real storage, which is fast:
import pytest
from pyxpo_storage import Storage
@pytest.fixture
def store(tmp_path):
return Storage(id="test", path=str(tmp_path))
def test_roundtrip(store):
store.set("n", 3)
store.set_object("o", {"a": [1, 2]})
assert store.get_number("n") == 3
assert store.get_object("o") == {"a": [1, 2]}
assert store.get_string("n") is None
def test_listener(store):
seen = []
sub = store.add_on_value_changed_listener(seen.append)
store.set("k", "v")
store.delete("k")
sub.remove()
store.set("k", "w")
assert seen == ["k", "k"]
def test_merge(store):
store.set_item("p", '{"a": {"x": 1}}')
store.merge_item("p", '{"a": {"y": 2}}')
assert store.get_object("p") == {"a": {"x": 1, "y": 2}}
Troubleshooting
| Symptom | Cause and fix |
|---|---|
get_string returns None for a number |
Getters return None for another type. Use get_number. |
TypeError: storage keeps str, int, float, bool or bytes |
Use set_object for dicts and lists. |
| Tests share data | Set PYXPO_STORAGE_DIR or use Storage(path=tmp_path). |
ValueError: ... does not encrypt |
Remove encryptionKey. Use pyxpo-secure-store for secrets. |
A .corrupt file appeared |
The store was unreadable. The app started empty and kept the old file for you. |
| A value changed but the screen did not | Use a hook (use_storage_string) instead of reading in render. |
FAQ
Is it async? No. Reads and writes are synchronous and fast.
Is it safe from several threads? Yes, every access holds a lock.
Can I store a list? Yes, set_object("items", [1, 2, 3]).
Does it survive an app update? Yes. It is removed on uninstall, and backed up with the app.
Is it encrypted? No.
API reference
Storage(config=None, *, id="default", path=None) and storage
| Method | Notes |
|---|---|
set(key, value) |
str, int, float, bool or bytes. |
get_string, get_number, get_boolean, get_buffer (key) |
Value or None. |
set_object(key, value) / get_object(key) |
JSON values. |
contains(key), delete(key) (remove), get_all_keys(), clear_all() |
|
size, trim(), path |
Disk size, compaction, file path. |
add_on_value_changed_listener(fn) |
Returns an object with remove(). |
get_item, set_item, remove_item, merge_item, multi_get, multi_set, multi_remove, multi_merge, clear |
AsyncStorage names. |
Hooks and helpers
use_storage_string, use_storage_number, use_storage_boolean, use_storage_buffer, use_storage_object
(key, instance=None) return (value, set_value). use_storage_listener(fn, instance=None) returns nothing.
default_directory() returns the folder in use. camelCase aliases exist for all of them.
License
MIT
Metadata
Release files for pyxpo-storage 0.1.0a2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyxpo_storage-0.1.0a2.tar.gz | 19.0 kB | With provenance | Details for pyxpo_storage-0.1.0a2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyxpo_storage-0.1.0a2-py3-none-any.whl | Python 3 | none | any | Details for pyxpo_storage-0.1.0a2-py3-none-any.whl |
Total release size: 32.6 kB
Release files / pyxpo_storage-0.1.0a2.tar.gz
| Download URL | pyxpo_storage-0.1.0a2.tar.gz |
|---|---|
| Size | 19.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c2bb6aac803afd17fe9b7d330f2415e51359e22ff731ed499651b94e447a3a88
|
|
BLAKE2b-256 checksum How to use checksums |
88aaa05b73d1a64afd9b0c7138e4ddf145f1e866538484179b52456f0fe46cb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logRelease files / pyxpo_storage-0.1.0a2-py3-none-any.whl
| Download URL | pyxpo_storage-0.1.0a2-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
111b96892798ca5e568cd9446e8b1bbbb9450344b02b63910ed2db2c2b889e5a
|
|
BLAKE2b-256 checksum How to use checksums |
130cb355d21fa6c9d6b6a1838f74f0e049ff8db2a0cb92c005a9a5465fff5e6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logSecurity for pyxpo-storage 0.1.0a2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pyxpo_storage-0.1.0a2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.