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.1.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.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: savekit-2.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 6061374b1921e1836e358a2c5f524337a21960a1e5a128b6791f736ed11fd8f1
MD5 c88b520b8072478e42751974d581a462
BLAKE2b-256 7e8ac2ddaa409c8c0adde4b2772de66fe518c1ff707ade68f2948c5783f98146

See more details on using hashes here.

File details

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

File metadata

  • Download URL: savekit-2.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 97e2a040f0ec3ba23e3dc50d73621d48b947b2df7840908860d077105f94d87e
MD5 611e5acdae4c7ed908abddbdc8583150
BLAKE2b-256 86b9b0639c4578101b2ad2b4ef1149dc909671e4b54b002bc82d7d76c81fc22e

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