Skip to main content

A lightweight, persistent key-value storage toolkit for Python projects, using SQLite via SQLAlchemy. Supports storing primitive types, complex objects, and Pydantic models with full context manager support and project-root storage.

Project description

SaveKit

SaveKit is a lightweight persistent key–value storage system built on top of SQLite using SQLAlchemy. It is designed for Python projects that need to store configuration, state, or small amounts of data reliably without additional infrastructure.

Key Features

  • Local persistence using SQLite
  • Simple key–value interface
  • Support for primitive types and JSON-serializable structures
  • Native support for Pydantic models
  • Safe SQLAlchemy session handling
  • Optional context manager usage
  • Export and import data as JSON
  • Automatic storage inside a project-level store directory

Architecture

SaveKit is composed of two main components:

  • StoreItem: A SQLAlchemy model representing a persisted key–value entry.
  • SaveKit: A service class responsible for all persistence operations.

All database and serialization logic is fully encapsulated inside SaveKit, keeping consumer code clean and free of persistence concerns.

Requirements

  • Python 3.10+
  • SQLAlchemy
  • Pydantic

Initialization Behavior

When a SaveKit instance is created:

  • The project root is resolved using os.getcwd()
  • A directory named store is created if it does not exist
  • A SQLite database file is created inside that directory
  • Required tables are created automatically

The database name can be customized during initialization.

Example

from savekit import SaveKit

store = SaveKit()
store = SaveKit(db_name="my_app_data")

Usage Overview

SaveKit supports two usage patterns:

  • Direct usage, where sessions are created and closed automatically
  • Context manager usage for grouped operations within a single session

Direct Usage Example

store = SaveKit()

store.set_item("theme", "dark")
value = store.get_item("theme")

Context Manager Usage Example

with SaveKit() as store:
    store.set_item("counter", 10)
    store.set_item("enabled", True)

Supported Operations

Store a Value

Supports storing:

  • Primitive values
  • Dictionaries and lists
  • Pydantic BaseModel instances
store.set_item("count", 5)
store.set_item("settings", {"retry": 3, "timeout": 30})

Storing a Pydantic Model

from pydantic import BaseModel

class User(BaseModel):
    id: int
    name: str

user = User(id=1, name="Alice")
store.set_item("user", user)

Retrieve a Value

  • Fetch values by key
  • Provide a default value if the key does not exist
  • Optionally parse the stored value into a Pydantic model
theme = store.get_item("theme", default="light")

Retrieve as Pydantic Model

user = store.get_item("user", model=User)

Delete a Value

Removes a specific key from the store.

store.delete_item("theme")

Retrieve All Values

Returns the entire store content as a dictionary.

data = store.get_all_items()

Clear Store

Deletes all entries from the store.

store.clear_store()

Export Data

Exports all stored data to a JSON file.

store.export_store("backup.json")

Import Data

Imports data from a JSON file, replacing the current store content.

store.import_store("backup.json")

Reload Store

Reloads and returns all items from the database.

data = store.reload_store()

Error Handling

  • Invalid serialization raises ValueError
  • Database-related failures raise RuntimeError
  • Sessions are always closed safely, even on errors

Recommended Use Cases

  • Persistent application configuration
  • Simple local cache
  • Process state storage
  • Internal tools and prototypes
  • CLI applications and productive scripts

Limitations

  • Not designed for high concurrency workloads
  • Not a replacement for a full relational database
  • Intended for lightweight, local persistence only

License

Free to use for personal and professional projects.

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

savekit-2.0.2.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

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

savekit-2.0.2-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file savekit-2.0.2.tar.gz.

File metadata

  • Download URL: savekit-2.0.2.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for savekit-2.0.2.tar.gz
Algorithm Hash digest
SHA256 f29dd51315fadc24e22cc3d5f924dbb1a5b15673a508ad24020a2591c25de8de
MD5 d88ed6da116e46409b7ce6ceb1115a67
BLAKE2b-256 ef83c02c58239bd9f7e6b13bf2f1cbec031d9f555e89ff951d62c2322f9fb5e4

See more details on using hashes here.

File details

Details for the file savekit-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: savekit-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for savekit-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 848eb5b136068fb10feb45be4ee5941475a4e1ef71633b7447d308189f08dd80
MD5 2bc4dff319435fb8b58f6a8f48877cec
BLAKE2b-256 7205de70c700444eca8a2c4bec4a2e44d3916d9d20f66a027f8673af58f5dacd

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