Skip to main content

A lightweight JSON storage library with caching and events.

Project description

💾 SaveMZ

Python Version License

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

savemz-2.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

savemz-2.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file savemz-2.1.tar.gz.

File metadata

  • Download URL: savemz-2.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for savemz-2.1.tar.gz
Algorithm Hash digest
SHA256 37e82bc6888d5226f27895c478eb8c461a8e6c935e212a8e67ca0290873aea50
MD5 c33d1cdf666f86a014cd158b3f5a8870
BLAKE2b-256 fbee328e01dc7c660faea61a0747538f752ea0ffe5dc94c3b1a8e681ebb07efc

See more details on using hashes here.

File details

Details for the file savemz-2.1-py3-none-any.whl.

File metadata

  • Download URL: savemz-2.1-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

Hashes for savemz-2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b866528e89a52488b425fd24419ede61608542efc345d746f1a635a43a487ad1
MD5 9db40cd210625a119d0cf8ec2eb004dc
BLAKE2b-256 7ba9920fcd9aa7b60c30a549c267b098533f84872070ebbc149aaeb11955a6e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page