pyhold
PyPi: Click Here
pyhold is a lightweight, persistent data store built in pure Python with multiple data structure support. Designed for MVPs, CLI tools, and embedded apps that need quick and reliable state saving — no database required.
✅ Features
- Dictionary-style access:
store["token"] = "abc"
- Key-Value store: Dedicated key-value operations with GUI
- Linked List: Persistent linked list with full list operations
- Auto-syncs to XML on change
- Supports
int
, str
, float
, bool
, dict
, list
, tuple
, None
- Fully human-readable and editable
- Zero external dependencies
- Built-in GUI for all data structures
📋 Requirements
Python Version: 3.7 or higher
Built-in Dependencies (included with Python):
tkinter
- For GUI functionality (included in most Python installations)
xml.etree.ElementTree
- For XML file operations
json
- For complex data type serialization
ast
- For literal evaluation
Note: The GUI features require tkinter
, which is included in most Python installations but may need to be installed separately on some Linux distributions:
sudo apt-get install python3-tk
sudo yum install tkinter
sudo dnf install python3-tkinter
Installation
pip install pyhold
🗂️ Key-Value Store
The key-value store provides dictionary-like functionality with persistent storage to XML files.
Basic Usage
from pyhold import pyhold
kv_store = pyhold("my_data.xml", mode="keyvalue", auto_sync=True, auto_reload=True)
Core Functions
Dictionary-style Operations
kv_store["username"] = "john_doe"
kv_store["age"] = 25
kv_store["settings"] = {"theme": "dark", "notifications": True}
print(kv_store["username"])
print(kv_store["age"])
if "username" in kv_store:
print("User found!")
del kv_store["age"]
kv_store.pop("age")
Utility Functions
value = kv_store.get("missing_key", "default_value")
keys = kv_store.keys()
values = kv_store.values()
items = kv_store.items()
print(len(kv_store))
kv_store.clear()
kv_store.save_pyhold()
kv_store.load_pyhold()
Write Function
kv_store.write("api_key", "abc123")
kv_store.write("counter", 42)
GUI Interface
kv_store.show_gui()
Complete Example
from pyhold import pyhold
config = pyhold("app_config.xml", mode="keyvalue")
config["app_name"] = "MyApp"
config["version"] = "1.0.0"
config["debug_mode"] = True
config["database"] = {
"host": "localhost",
"port": 5432,
"name": "myapp_db"
}
config["features"] = ["auth", "logging", "api"]
print(f"App: {config['app_name']} v{config['version']}")
print(f"Debug: {config['debug_mode']}")
print(f"DB Host: {config['database']['host']}")
if "auth" in config["features"]:
print("Authentication is enabled")
config["version"] = "1.1.0"
config["debug_mode"] = False
config.show_gui()
🔗 Linked List
The linked list provides a persistent, index-based data structure with full list operations.
Basic Usage
from pyhold import pyhold
ll = pyhold("my_list.xml", mode="linkedlist", auto_sync=True, auto_reload=True)
Core Functions
List-style Operations
ll.append("first item")
ll.append(42)
ll.append({"nested": "data"})
print(ll[0])
print(ll[1])
ll[0] = "updated first item"
if "first item" in ll:
print("Item found!")
print(len(ll))
Insertion and Removal
ll.insert(1, "inserted item")
ll.remove("inserted item")
ll.pop(0)
ll.pop()
del ll[0]
Search and Analysis
try:
index = ll.index("first item")
print(f"Found at index: {index}")
except ValueError:
print("Item not found")
count = ll.count("first item")
other_list = pyhold("other.xml", mode="linkedlist")
other_list.append("first item")
print(ll == other_list)
List Manipulation
ll.reverse()
ll.sort()
ll.sort(reverse=True)
ll.extend(["item1", "item2", "item3"])
list1 = pyhold("list1.xml", mode="linkedlist")
list2 = pyhold("list2.xml", mode="linkedlist")
combined = list1 + list2
repeated = ll * 3
Utility Functions
ll.clear()
ll.save_pyhold()
ll.load_pyhold()
print(str(ll))
GUI Interface
ll.show_gui()
Complete Example
from pyhold import pyhold
tasks = pyhold("todo_list.xml", mode="linkedlist")
tasks.append("Buy groceries")
tasks.append("Write documentation")
tasks.append("Review code")
tasks.append("Deploy application")
tasks.insert(0, "URGENT: Fix critical bug")
print(f"Total tasks: {len(tasks)}")
print(f"First task: {tasks[0]}")
print(f"Last task: {tasks[-1]}")
try:
index = tasks.index("Write documentation")
print(f"Documentation task at index: {index}")
except ValueError:
print("Task not found")
tasks[1] = "Buy groceries and milk"
tasks.remove("Review code")
tasks.sort()
tasks.reverse()
tasks.show_gui()
📁 Dictionary Store
The dictionary store provides a simple key-value interface using the main pyhold
class.
Basic Usage
from pyhold import pyhold
store = pyhold("mydata.xml", mode="keyvalue", auto_sync=True, auto_reload=True)
store["username"] = "anjan"
store["token"] = "abc123"
print(store["username"])
store.pop("username")
Complete Example
from pyhold import pyhold
app_data = pyhold("app_data.xml", mode="keyvalue")
app_data["user_id"] = 12345
app_data["session_token"] = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
app_data["preferences"] = {
"theme": "dark",
"language": "en",
"notifications": True
}
app_data["last_login"] = "2024-01-15T10:30:00Z"
user_id = app_data.get("user_id")
session_token = app_data["session_token"]
theme = app_data["preferences"]["theme"]
app_data["last_login"] = "2024-01-15T11:45:00Z"
if "session_token" in app_data:
print("User is logged in")
app_data.pop("session_token")
🔧 Configuration Options
All classes support these initialization parameters:
filename
(str): XML file path for persistence (default: "pyhold.xml")
mode
(str): Data structure mode - "keyvalue" or "linkedlist" (default: "keyvalue")
auto_sync
(bool): Automatically save changes to file (default: True)
auto_reload
(bool): Automatically load from file on initialization (default: True)
🎨 GUI Features
Both key-value and linked list stores include a comprehensive GUI with:
- Visual data management: Add, edit, delete items
- Search functionality: Filter items by key/value
- Type selection: Choose data types (str, int, float, bool, list, dict, tuple)
- File operations: Manual save, reload, export to JSON
- Real-time updates: See changes immediately
- Error handling: User-friendly error messages
📋 Supported Data Types
- Primitive types:
int
, str
, float
, bool
, None
- Complex types:
dict
, list
, tuple
- Automatic type detection and preservation
- Human-readable XML storage
🚀 Use Cases
- Configuration management: App settings, user preferences
- Session storage: User data, authentication tokens
- Data caching: Temporary data persistence
- CLI tools: Command history, user settings
- Prototyping: Quick data storage without database setup
- Embedded applications: Lightweight data persistence
🔧 Troubleshooting
GUI Not Working
If you encounter issues with the GUI:
- Linux: Install tkinter:
sudo apt-get install python3-tk
(Ubuntu/Debian) or sudo yum install tkinter
(CentOS/RHEL)
- macOS: Usually included with Python. If missing:
brew install python-tk
- Windows: Usually included with Python installation
File Permission Errors
- Ensure you have write permissions in the directory where you're creating XML files
- Check if the XML file is not locked by another process
Data Type Issues
- Complex data types (dict, list, tuple) are automatically serialized to JSON
- None values are properly handled
- Boolean values are preserved correctly
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
git clone https://github.com/AnjanB3012/pyhold.git
cd pyhold
pip install -e .
Running Tests
from pyhold import pyhold
kv = pyhold("test.xml", mode="keyvalue")
kv["test"] = "value"
assert kv["test"] == "value"
ll = pyhold("test_list.xml", mode="linkedlist")
ll.append("item1")
assert ll[0] == "item1"
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
📝 Changelog
Version 0.2.0
- Added comprehensive GUI for both key-value and linked list stores
- Improved error handling and data type support
- Enhanced documentation with examples
- Added search and filter functionality in GUI
- Export to JSON functionality
Version 0.1.0
- Initial release with basic key-value and linked list functionality
- XML persistence support
- Basic dictionary-style operations