
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
A familiar API from the Web, adapted to storing data locally with Python.
A familiar localStorage API from the Web, adapted for Python applications
Simple, fast, and reliable local data storage with multiple backend options
getAll()
, getMany()
, and removeAll()
methodspip install localStoragePro
from localStoragePro import lsp, localStoragePro
# Option 1: Using the convenient singleton instance
lsp('com.myapp.data').setItem('user_id', '12345')
user_id = lsp.getItem('user_id') # Returns: '12345'
# Option 2: Creating your own instance
storage = localStoragePro('com.myapp.data')
# Store data (any serializable type)
storage.setItem('theme', 'dark')
storage.setItem('settings', '{"notifications": true}')
# Retrieve data
theme = storage.getItem('theme') # Returns: 'dark'
# Remove items
storage.removeItem('theme')
print(storage.getItem('theme')) # Returns: None
# Clear all data
storage.clear()
import asyncio
from localStoragePro import async_lsp, AsyncLocalStoragePro
async def main():
# Option 1: Using the convenient singleton instance
await async_lsp('com.myapp.data').setItem('user_id', '12345')
user_id = await async_lsp.getItem('user_id') # Returns: '12345'
# Option 2: Creating your own instance
storage = AsyncLocalStoragePro('com.myapp.data')
# Store data asynchronously
await storage.setItem('theme', 'dark')
await storage.setItem('settings', '{"notifications": true}')
# Retrieve data
theme = await storage.getItem('theme') # Returns: 'dark'
# Remove items
await storage.removeItem('theme')
# Concurrent operations
tasks = [
storage.setItem('key1', 'value1'),
storage.setItem('key2', 'value2'),
storage.setItem('key3', 'value3')
]
await asyncio.gather(*tasks)
# Bulk retrieval
all_data = await storage.getAll()
# Clear all data
await storage.clear()
# Run the async example
asyncio.run(main())
Choose the backend that fits your needs:
Backend | Best For | Pros | Cons |
---|---|---|---|
sqlite (default) | Most applications | Fast, ACID compliant, handles large datasets | Single file dependency |
json | Simple apps, human-readable data | Readable, easy debugging | Can be slower for large datasets |
text | Key-value files | Individual files per key, simple | Many files, slower for bulk operations |
# Choose your backend
storage_sqlite = localStoragePro('myapp', 'sqlite') # Default
storage_json = localStoragePro('myapp', 'json') # Human-readable
storage_text = localStoragePro('myapp', 'text') # Individual files
asyncio.to_thread()
support)Efficiently work with multiple keys at once:
from localStoragePro import lsp
# Set up some data
lsp('bulk_demo').setItem('name', 'Suraj Mandal')
lsp.setItem('email', 'localstoragepro.oss@mandalsuraj.com')
lsp.setItem('role', 'Developer')
lsp.setItem('location', 'India')
# Get all stored data
all_data = lsp.getAll()
print(all_data)
# {'name': 'Suraj Mandal', 'email': 'localstoragepro.oss@mandalsuraj.com', 'role': 'Developer', 'location': 'India'}
# Get specific keys only
user_info = lsp.getMany(['name', 'email'])
print(user_info)
# {'name': 'Suraj Mandal', 'email': 'localstoragepro.oss@mandalsuraj.com'}
# Remove all data at once
lsp.removeAll()
print(len(lsp.getAll())) # 0
Method | Description | Returns |
---|---|---|
setItem(key, value) | Store a value with the given key | None |
getItem(key) | Retrieve value by key | str | None |
removeItem(key) | Remove item by key | None |
getAll() | Get all key-value pairs | Dict[str, str] |
getMany(keys) | Get multiple values by keys | Dict[str, str] |
removeAll() | Remove all items | None |
clear() | Clear all stored data (alias for removeAll) | None |
Method | Description | Returns |
---|---|---|
async setItem(key, value) | Store a value with the given key | None |
async getItem(key) | Retrieve value by key | str | None |
async removeItem(key) | Remove item by key | None |
async getAll() | Get all key-value pairs | Dict[str, str] |
async getMany(keys) | Get multiple values by keys | Dict[str, str] |
async removeAll() | Remove all items | None |
async clear() | Clear all stored data (alias for removeAll) | None |
# Synchronous API
from typing import Dict, List, Optional, Any
def setItem(self, key: str, value: Any) -> None: ...
def getItem(self, key: str) -> Optional[str]: ...
def removeItem(self, key: str) -> None: ...
def getAll(self) -> Dict[str, str]: ...
def getMany(self, keys: List[str]) -> Dict[str, str]: ...
def removeAll(self) -> None: ...
def clear(self) -> None: ...
# Asynchronous API
async def setItem(self, key: str, value: Any) -> None: ...
async def getItem(self, key: str) -> Optional[str]: ...
async def removeItem(self, key: str) -> None: ...
async def getAll(self) -> Dict[str, str]: ...
async def getMany(self, keys: List[str]) -> Dict[str, str]: ...
async def removeAll(self) -> None: ...
async def clear(self) -> None: ...
import json
from localStoragePro import lsp
# Store complex data as JSON
user_profile = {
"name": "Suraj Mandal",
"preferences": {"theme": "dark", "language": "en"},
"projects": ["localStoragePro", "Other Projects"]
}
lsp('json_example').setItem('profile', json.dumps(user_profile))
# Retrieve and parse JSON
profile_data = json.loads(lsp.getItem('profile'))
print(profile_data['name']) # "Suraj Mandal"
import asyncio
import json
from localStoragePro import async_lsp
async def main():
# Store multiple items concurrently
tasks = [
async_lsp('async_example').setItem('key1', 'value1'),
async_lsp.setItem('key2', 'value2'),
async_lsp.setItem('key3', 'value3')
]
await asyncio.gather(*tasks)
# Retrieve all data
data = await async_lsp.getAll()
print(f"Stored {len(data)} items")
# Bulk retrieval is more efficient
subset = await async_lsp.getMany(['key1', 'key3'])
print(subset) # {'key1': 'value1', 'key3': 'value3'}
asyncio.run(main())
from localStoragePro import lsp
lsp('myapp.config').setItem('db_host', 'localhost')
lsp.setItem('db_port', '5432')
lsp.setItem('debug_mode', 'true')
lsp.setItem('log_level', 'INFO')
# Load all config at startup
app_config = lsp.getAll()
print(f"Connecting to {app_config['db_host']}:{app_config['db_port']}")
localStoragePro gracefully handles common error scenarios:
from localStoragePro import lsp
# Getting non-existent keys returns None
result = lsp('error_handling_demo').getItem('does_not_exist')
print(result) # None
# Getting many with mixed existing/non-existing keys
result = lsp.getMany(['exists', 'does_not_exist', 'also_exists'])
print(result) # Only returns existing keys
# Removing non-existent keys doesn't raise errors
lsp.removeItem('does_not_exist') # Safe operation
# Multiple removeAll() calls are safe
lsp.removeAll()
lsp.removeAll() # No error
We welcome contributions! Here's how you can help:
# Clone the repository
git clone https://github.com/surajmandalcell/localStoragePro.git
cd localStoragePro
# Install development dependencies
make install-dev
# Run tests
make test
# Build package
make build
# Run examples
python examples/example.py
python examples/async_example.py # Requires Python 3.9+
This project is licensed under the MIT License - see the LICENSE file for details.
Star this repo if you find it useful!
Made by Suraj Mandal
FAQs
A familiar API from the Web, adapted to storing data locally with Python.
We found that localStoragePro demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.