A lightweight JSON storage library with caching and events.
Project description
💾 SaveMZ
A lightweight and easy-to-use JSON database library for Python.
SaveMZ makes working with JSON files simple by providing an intuitive API for reading, writing, updating, and deleting data using dot-separated paths. It also includes a built-in cache system, events, and custom exceptions.
✨ Features
- 📦 Lightweight and easy to use
- ⚡ Built-in cache system
- 📁 Dot-separated path support
- ✏️ Read, write, update and delete values
- 🔄 Reload data from disk
- 🎯 Event system
- 🚨 Custom exceptions
- 🐍 Python 3.10+
📦 Installation
pip install savemz
🚀 Quick Start
from savemz import SaveMZ
db = SaveMZ("database.json")
db.set("user.name", "Julius")
db.set("user.age", 18)
print(db.get("user.name"))
db.delete("user.age")
📖 Methods
Read
db.read()
Returns the entire JSON object.
Write
db.write(data)
Writes a Python object to the JSON file.
You can also specify the indentation:
db.write(data, indent=4)
Get
db.get("user.name")
Returns the value stored at the given path.
Set
db.set("user.name", "John")
Creates or updates a value.
Delete
db.delete("user.name")
Deletes the specified key.
Reload
db.reload()
Reloads the file and clears the cache.
⚡ Events
Register an event:
from savemz import SaveMZ
db = SaveMZ("database.json")
def after_set(path, value):
print(f"{path} -> {value}")
db.onEvent("after_set", after_set)
db.set("user.name", "Alex")
Available events:
- before_read
- after_read
- before_write
- after_write
- before_set
- after_set
- before_delete
- after_delete
- before_reload
- after_reload
Remove an event:
db.offEvent("after_set", after_set)
🚨 Exceptions
SaveMZ provides custom exceptions for cleaner error handling.
Example:
from savemz import PathNotFoundError
try:
db.get("user.age")
except PathNotFoundError:
print("Path not found.")
📄 Example JSON
{
"user": {
"name": "John",
"age": 20
}
}
Access values using:
db.get("user.name")
Output:
John
📌 Why SaveMZ?
- Simple API
- Lightweight
- No external dependencies
- Fast cache system
- Event support
- Easy nested JSON access
- Beginner-friendly
- Clean and readable code
📄 Changelog
See the full changelog in:
CHANGELOG.md
📜 License
This project is licensed under the MIT License.
👨💻 Author
Julius
GitHub:
https://github.com/imozan/saveMZ
If you like this project, consider giving it a ⭐ on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file savemz-2.0.tar.gz.
File metadata
- Download URL: savemz-2.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
529d11523c19733251aa0cc15af88acea112997025812808a4867c71976e825b
|
|
| MD5 |
acf9327af59d267b5d3869de79403411
|
|
| BLAKE2b-256 |
44feb5e33914bdbcd787c10ddebbe70cdac3d66ef44a50d585c55ad42e2e08c6
|
File details
Details for the file savemz-2.0-py3-none-any.whl.
File metadata
- Download URL: savemz-2.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cbe6692f94144bd1ae33b5612084df9135c25d110e72fc68a8a47491e04f880
|
|
| MD5 |
9f68bf95c0cfe5d9cf596529076e58ba
|
|
| BLAKE2b-256 |
68f50d01ee085a18ac3503bdad00a0965307db39918aa2aec369cddb74543eaa
|