This release is a pre-release and may not be stable for production use.
pyxpo-secure-store
Encrypted key-value storage for secrets in pyxpo apps, written in Python: sign-in tokens, API keys and PINs in the iOS Keychain or the Android Keystore, with an optional Face ID, Touch ID or fingerprint check. The names follow expo-secure-store, in Python style.
import pyxpo_secure_store as SecureStore
await SecureStore.set_item_async("session_token", "tok_8f2c41d9")
token = await SecureStore.get_item_async("session_token") # "tok_8f2c41d9", or None
await SecureStore.delete_item_async("session_token")
Features
- Real encryption: iOS keeps values in the Keychain. Android encrypts them with an AES-256-GCM key that never
leaves the Android Keystore, and keeps the ciphertext in the app's private
SharedPreferences. - Biometric lock:
requireAuthenticationasks for Face ID, Touch ID or a fingerprint before a value is read (and, on Android, written). - Small, string-only API:
get_item_async,set_item_async,delete_item_async, plus two helpers that tell you what the device can do. - Checked input: keys and option names are validated, and a value that is not a string raises
TypeErrorwith a hint to usejson.dumps. - Keychain control (iOS): accessibility class, service name and access group.
- Desktop fallback: an in-memory dict, so tests and previews run without a phone. It is not encrypted.
- Typed: ships
py.typed. Every name also has its expo spelling (SecureStore.setItemAsync).
Contents
| If you are... | Start here |
|---|---|
| Saving a login token | Quick start |
| Protecting a value with Face ID or a fingerprint | Biometric lock |
| Choosing when the Keychain releases a value | Options |
| Wondering what survives a reinstall | Where the data lives |
| Looking for exact signatures | API reference · Errors |
| Seeing it in a real app | Recipe: keep a user signed in |
| Stuck | Testing · Troubleshooting · FAQ |
Platform support
| Target | What works |
|---|---|
| Android, API 24+ | Get, set, delete. Encryption with an Android Keystore key. requireAuthentication needs Android 10 or newer. |
| iOS 15+ | Get, set, delete in the Keychain, with keychainAccessible, keychainService and accessGroup. Face ID or Touch ID with requireAuthentication. |
Web page (pyxpo run web, pyxpo build web) |
The site's localStorage: values survive a reload, stored as plain text. requireAuthentication raises an error. |
Desktop window (pyxpo run desktop) |
An in-memory dict that is lost when the process ends. is_available_async() is False. Nothing is encrypted. |
Requires Python 3.9+ and pyxpo>=0.1.0a1.
Install
pip install pyxpo-secure-store
Add the module to your app's pyproject.toml:
[tool.pyxpo]
modules = ["secure-store"]
The module has native code, so rebuild the app after adding it (pyxpo run android or pyxpo run ios). On Android it
adds the USE_BIOMETRIC permission (granted at install). On iOS it adds the NSFaceIDUsageDescription key to
Info.plist. Change its text with a module option:
[tool.pyxpo.module_options.secure-store]
faceIDPermission = "Use Face ID to unlock your saved sign-in details."
Quick start
import pyxpo_secure_store as SecureStore
from pyxpo import Pressable, Text, View, component, use_state
@component
def Token():
shown, set_shown = use_state("nothing yet")
async def save():
await SecureStore.set_item_async("session_token", "tok_8f2c41d9")
set_shown("saved")
async def read():
set_shown(await SecureStore.get_item_async("session_token") or "no token")
return View(
Pressable(Text("Save"), on_press=save),
Pressable(Text("Read"), on_press=read),
Text(shown),
)
Tip: keep only secrets here: tokens, keys, PINs. Values should be small, a few KB at most. Use
pyxpo-storagefor ordinary settings andpyxpo-file-systemfor bulk data. A real token is shown above only as a dummy value.
Reading, writing and deleting
await SecureStore.set_item_async("token", "abc") # replaces what "token" held
value = await SecureStore.get_item_async("token") # "abc", or None when missing
await SecureStore.delete_item_async("token") # no error when it does not exist
| Function | Returns | Notes |
|---|---|---|
set_item_async(key, value, options=None) |
None |
value must be a str. Use json.dumps for anything else. |
get_item_async(key, options=None) |
str or None |
May show the biometric prompt (see below). |
delete_item_async(key, options=None) |
None |
Safe when the key is missing. |
is_available_async() |
bool |
True on a phone with the module linked, False on the desktop. |
can_use_biometric_authentication_async() |
bool |
True when biometrics are enrolled, so requireAuthentication items work. |
Keys may use letters, digits, ., - and _. Anything else raises ValueError. Pass the same options
(especially keychainService) when you read, write and delete one item.
Biometric lock
if await SecureStore.can_use_biometric_authentication_async():
await SecureStore.set_item_async("pin", "1234", {
"requireAuthentication": True,
"authenticationPrompt": "Unlock your PIN",
})
pin = await SecureStore.get_item_async("pin", {"requireAuthentication": True,
"authenticationPrompt": "Unlock your PIN"})
The system shows Face ID, Touch ID or the fingerprint sheet with your authenticationPrompt text. If the user
cancels, the call raises an error (see Errors) and you get no value. The screenshots in this README do not
show the biometric prompt, because an emulator or simulator has no enrolled face or finger by default.
Options
All keys are optional. An unknown key raises ValueError.
| Option | Default | Platform | Meaning |
|---|---|---|---|
keychainService |
"app" |
both | A namespace. Items with different services do not clash. Letters, digits, ., -, _. |
requireAuthentication |
False |
both | Ask for biometrics before the value is read (Android: also when written). |
authenticationPrompt |
"" |
both | The text in the biometric prompt. |
keychainAccessible |
WHEN_UNLOCKED |
iOS | When the Keychain gives the value out. One of the constants below. |
accessGroup |
"" |
iOS | A Keychain access group, to share items between your own apps. |
keychainAccessible constants (the same numbers as expo-secure-store):
| Constant | Value |
|---|---|
AFTER_FIRST_UNLOCK |
0 |
AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY |
1 |
ALWAYS |
2 |
WHEN_PASSCODE_SET_THIS_DEVICE_ONLY |
3 |
ALWAYS_THIS_DEVICE_ONLY |
4 |
WHEN_UNLOCKED (default) |
5 |
WHEN_UNLOCKED_THIS_DEVICE_ONLY |
6 |
Use AFTER_FIRST_UNLOCK for a token a background task must read while the phone is locked.
Where the data lives
| iOS | Android | |
|---|---|---|
| Storage | Keychain | App SharedPreferences, as ciphertext |
| Key | Managed by the Keychain | AES-256-GCM key in the Android Keystore |
| After the app is deleted | Items survive and come back on reinstall | Data is removed with the app |
| Backup | Follows the accessibility class (..._THIS_DEVICE_ONLY stays off backups) |
Not backed up with the keystore key, so a restored backup cannot be read |
Do not rely on a value being there after a reinstall. On iOS a returning item can be a stale token, so check it with your server.
Errors
| Error | When | What to do |
|---|---|---|
ValueError |
A key with a bad character, an unknown option, a bad keychainService, or a keychainAccessible outside 0-6. |
Fix the argument. The message names it. |
TypeError |
A value that is not a string. | json.dumps(obj) first. |
ModuleNotLinkedError (from pyxpo.module_api) |
The app was built without "secure-store" in modules. |
Add it and rebuild. |
Native error from get_item_async / set_item_async |
The user cancelled or failed the biometric prompt, or no biometrics are enrolled. | Show your own fallback, such as a password field. |
Web and desktop
On the web page values go to the site's localStorage under pyxpo-secure-store:<service>-<key>, so a signed-in
user stays signed in after a reload. The browser has no keychain: any script on the page can read them, and
requireAuthentication raises RuntimeError. Store only what a web app would keep anyway, such as a session token.
On the desktop window values live in a Python dict for the life of the process:
await SecureStore.set_item_async("k", "v")
await SecureStore.get_item_async("k") # "v", until the process ends
await SecureStore.is_available_async() # False
await SecureStore.can_use_biometric_authentication_async() # False
Treat the desktop store as a stand-in for tests and previews. Do not rely on it for real secrets, and
requireAuthentication has no effect there.
Recipe: keep a user signed in
Save the token after login, restore it on start, and sign out by deleting it.
import pyxpo_secure_store as SecureStore
from pyxpo import Pressable, Text, View, component, use_async, use_state
OPTS = {"keychainService": "myapp.auth", "keychainAccessible": SecureStore.AFTER_FIRST_UNLOCK}
async def log_in(user: str, password: str) -> str:
return "tok_8f2c41d9" # your server call; a dummy token here
async def restore():
return await SecureStore.get_item_async("session", OPTS)
@component
def App():
stored = use_async(restore, [])
token, set_token = use_state(None)
current = token or stored.value
async def sign_in():
value = await log_in("asha", "not-a-real-password")
await SecureStore.set_item_async("session", value, OPTS)
set_token(value)
async def sign_out():
await SecureStore.delete_item_async("session", OPTS)
set_token("")
if stored.loading:
return Text("Loading...")
if current:
return View(Text("Signed in"), Pressable(Text("Sign out"), on_press=sign_out))
return View(Text("Signed out"), Pressable(Text("Sign in"), on_press=sign_in))
Production checklist
- Only secrets are stored here, and each value is small.
- Every read, write and delete of one item uses the same
keychainServiceand options. - A restored token (it can come back after an iOS reinstall) is checked with your server.
- A cancelled biometric prompt has a fallback (a password field) and does not crash.
-
faceIDPermissiontext explains why the app wants Face ID, if you userequireAuthenticationon iOS. - You never log a secret or put one in a screenshot, a crash report or an analytics event.
- The desktop in-memory fallback is not mistaken for secure storage.
Testing
On the desktop test host the module is an in-memory dict, so ordinary tests need no fakes. Clear it between tests:
import asyncio
import pyxpo_secure_store as SecureStore
def test_round_trip():
SecureStore._memory.clear()
asyncio.run(SecureStore.set_item_async("token", "abc"))
assert asyncio.run(SecureStore.get_item_async("token")) == "abc"
asyncio.run(SecureStore.delete_item_async("token"))
assert asyncio.run(SecureStore.get_item_async("token")) is None
To test a biometric failure, replace the function with a fake that raises:
def test_cancelled_prompt(monkeypatch):
async def cancelled(key, options=None):
raise RuntimeError("user cancelled")
monkeypatch.setattr(SecureStore, "get_item_async", cancelled)
Troubleshooting
| Symptom | Cause and fix |
|---|---|
ValueError: invalid key |
The key has a space or a symbol. Use letters, digits, ., -, _. |
TypeError: SecureStore values must be strings |
Pass json.dumps(value) and json.loads it when you read. |
get_item_async returns None after a restart on the desktop |
The desktop store is in memory only. Run on a phone. |
| A value is missing after a reinstall on Android | Android removes the data with the app. Ask the user to sign in again. |
| A value is still there after a reinstall on iOS | Keychain items survive app deletion. Delete it on first launch if that is not what you want. |
| Reading fails while the phone is locked | The item uses WHEN_UNLOCKED. Save it with AFTER_FIRST_UNLOCK if a background task needs it. |
requireAuthentication fails on an old Android |
It needs Android 10 or newer. |
| The Face ID prompt is missing on iOS | Check faceIDPermission and that Face ID is enrolled. The Simulator needs Features > Face ID > Enrolled. |
ModuleNotLinkedError |
Add "secure-store" to modules and rebuild. |
FAQ
Is it safe for passwords? It stores them in the platform's secure store, which is the right place. Prefer short-lived tokens over raw passwords.
How large can a value be? Keep it to a few KB. The Keychain and the Keystore are not built for bulk data.
Can I store a dict? Yes, as json.dumps(d), and json.loads it after reading.
Does it sync across devices? Not by itself. iOS can sync Keychain items through iCloud Keychain depending on the
accessibility class. Use ..._THIS_DEVICE_ONLY to keep an item on one device.
Is setItemAsync the same as set_item_async? Yes. Every function has both spellings.
API reference
Functions
| Function (expo name) | Returns |
|---|---|
set_item_async(key, value, options=None) (setItemAsync) |
None |
get_item_async(key, options=None) (getItemAsync) |
str or None |
delete_item_async(key, options=None) (deleteItemAsync) |
None |
is_available_async() (isAvailableAsync) |
bool |
can_use_biometric_authentication_async() (canUseBiometricAuthenticationAsync, canUseBiometricAuthentication) |
bool |
Constants
AFTER_FIRST_UNLOCK, AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY, ALWAYS, WHEN_PASSCODE_SET_THIS_DEVICE_ONLY,
ALWAYS_THIS_DEVICE_ONLY, WHEN_UNLOCKED, WHEN_UNLOCKED_THIS_DEVICE_ONLY (see Options).
Module options
Option ([tool.pyxpo.module_options.secure-store]) |
Meaning |
|---|---|
faceIDPermission |
The NSFaceIDUsageDescription text on iOS. |
License
MIT
Metadata
Release files for pyxpo-secure-store 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_secure_store-0.1.0a2.tar.gz | 22.4 kB | With provenance | Details for pyxpo_secure_store-0.1.0a2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyxpo_secure_store-0.1.0a2-py3-none-any.whl | Python 3 | none | any | Details for pyxpo_secure_store-0.1.0a2-py3-none-any.whl |
Total release size: 40.2 kB
Release files / pyxpo_secure_store-0.1.0a2.tar.gz
| Download URL | pyxpo_secure_store-0.1.0a2.tar.gz |
|---|---|
| Size | 22.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7b6372c941ae10739c5ce9f7f075d31e177d13e2b2644adca936a8ca74797f24
|
|
BLAKE2b-256 checksum How to use checksums |
d94c7e1fda55e763f7ad4f7a0104bc971ded1048e9a8a478acf11db0dd153821
|
| 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_secure_store-0.1.0a2-py3-none-any.whl
| Download URL | pyxpo_secure_store-0.1.0a2-py3-none-any.whl |
|---|---|
| Size | 17.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
14f1a8e996a70ac2ccbb7447dd5ffadf66b08e27feb9cfa609f09c128cbbc482
|
|
BLAKE2b-256 checksum How to use checksums |
3646148d1fb3d92818334fba2c8b192446e0877a27b39b72d5f615d8a9c0c8ee
|
| 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-secure-store 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_secure_store-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.