Skip to main content

MemoBox

MemoBox is a tiny, local, persistent memory store for Python programs.

It uses a JSON file, so there is no database server, account, API key, or setup required.

Install

pip install MemoBox

Quick start

from MemoBox import Brain

brain = Brain()

brain.remember("username", "sam")
brain.remember("theme", "dark")

print(brain.recall("username"))
# sam

print(brain.exists("theme"))
# True

brain.forget("theme")

Categories

brain.remember("python", "PyPI", category="interests")
brain.remember("robotics", "Arduino", category="interests")

print(brain.category("interests"))

Search

brain.remember("project", "MemoBox")
brain.remember("language", "Python")

print(brain.search("python"))

Custom storage path

brain = Brain("my_memory.json")

By default MemoBox stores data in .MemoBox/memory.json in the current working directory.

Expiring memory

You can store a value with an expiration time:

brain.remember("temporary", "hello", expires="1h")

Supported units:

  • s — seconds
  • m — minutes
  • h — hours
  • d — days

Examples: 30s, 10m, 2h, 7d.

API

Brain(path=None)

Creates a memory store.

remember(key, value, category=None, expires=None)

Stores or replaces a value.

recall(key, default=None)

Returns a value, or default if it does not exist.

forget(key)

Removes a key. Returns True if it existed.

exists(key)

Checks whether a non-expired key exists.

all(category=None)

Returns all stored values, optionally filtered by category.

category(name)

Returns all values in a category.

search(query)

Searches keys, categories, and stringified values.

clear(category=None)

Clears everything, or only one category.

Example

from MemoBox import Brain

brain = Brain()

brain.remember("username", "sam")
brain.remember("editor", "VS Code", category="tools")
brain.remember("language", "Python", category="tools")

print(brain.recall("username"))
print(brain.category("tools"))
print(brain.search("python"))

Development

Clone the repository and install the package in editable mode:

pip install -e ".[dev]"

Run tests:

pytest

Build the package:

python -m build

License

MIT

Metadata

Release files for memobox 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for memobox 0.1.1
File Size Uploaded
memobox-0.1.1.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for memobox 0.1.1
File Interpreter ABI Platform
memobox-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.8 kB

Release files / memobox-0.1.1.tar.gz

Download URL memobox-0.1.1.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a06198adaf66f2ace38096d691a002c234b16aef2dbc5c774fde74a542a4cc7d
BLAKE2b-256 checksum
How to use checksums
6af222d80408f3ff3649eec4356414b1aa944bb38f75250966559ee71d0e3746
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Release files / memobox-0.1.1-py3-none-any.whl

Download URL memobox-0.1.1-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
13d889c921515a56abad2304011bc1e5d82121482be7d6acb9aa098192d67664
BLAKE2b-256 checksum
How to use checksums
68e5c939cb4736fd1c943db600edbacbb8284220a4dd409b0097ae4aa7bb3b9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page