A lightweight SQLite-backed database that can be used like a Python dictionary.
Project description
English description follows Japanese.
Pythonの辞書のように使える、SQLiteバックエンドの軽量キーバリューストアです。
概要
sqlite-dicは、SQLiteデータベースをPythonの辞書と同じ感覚で操作できるライブラリです。値にはJSONシリアライズ可能な任意の型(文字列、数値、真偽値、リスト、辞書、None)を格納できます。- 内部ではSQLiteのWAL(Write-Ahead Logging)モードを使用しており、読み書きの並列アクセスが可能です。すべての操作はスレッドセーフです。
- AIでのコーディングにおいてこのツールを使用するときは、そのままこのドキュメントをプロンプトに含めることで、AIにこのDBを使ってコーディングしてもらうことが可能です。
インストール
pip install sqlite-dic
使い方
import sqlite_dic
# データベースを開く(存在しなければ自動作成)
db = sqlite_dic("./sample.db")
# 値の追加・更新 — 辞書と同じ書き方
db["count"] = 33
db["config"] = {"theme": "dark", "lang": "ja"}
# 値の取得
print(db["count"]) # 33
print(db["config"]) # {'theme': 'dark', 'lang': 'ja'}
# エントリの削除
del db["count"]
# 格納数の確認
print(len(db)) # 1
制約
- キー は文字列のみ使用可能です。
- 値 はJSONシリアライズ可能な型(
dict、list、str、int、float、bool、None)に限ります。 - 同時書き込みはSQLiteのファイルロックにより直列化されます(busy timeout: 30秒)。
A lightweight key-value store backed by SQLite, with a Python dict-like interface.
Overview
sqlite-diclets you use an SQLite database as if it were a regular Python dictionary. Values can be any JSON-serializable type, so you can store strings, numbers, booleans, lists, dicts, andNonewithout any extra setup.- Under the hood, SQLite's WAL (Write-Ahead Logging) mode provides concurrent read/write access, and all operations are thread-safe.
Installation
pip install sqlite-dic
Quick Start
import sqlite_dic
# Open (or create) a database
db = sqlite_dic("./sample.db")
# Set values — just like a dict
db["count"] = 33
db["config"] = {"theme": "dark", "lang": "en"}
# Get values
print(db["count"]) # 33
print(db["config"]) # {'theme': 'dark', 'lang': 'en'}
# Delete an entry
del db["count"]
# Check the number of stored entries
print(len(db)) # 1
Constraints
- Keys must be strings.
- Values must be JSON-serializable (
dict,list,str,int,float,bool, orNone). - Concurrent writes are serialized by SQLite's file lock (busy timeout: 30 seconds).
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
sqlite_dic-0.0.0.tar.gz
(4.3 kB
view details)
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 sqlite_dic-0.0.0.tar.gz.
File metadata
- Download URL: sqlite_dic-0.0.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cfa72d4f2f48cbfd99d38792d9f6694b8b087524d8b6b8469c1605cbca127df
|
|
| MD5 |
cd313ccaaa9bf883634465b36ed34a35
|
|
| BLAKE2b-256 |
373715eab987b518d0c9bbe925916bcfadf3acd781b7fd5e82f86a4290d5cd53
|
File details
Details for the file sqlite_dic-0.0.0-py3-none-any.whl.
File metadata
- Download URL: sqlite_dic-0.0.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccbeb47102f33c9dfed7897ad19638d4ac7390b0440186a2b5087c276e6c7a4e
|
|
| MD5 |
b7d2deb9c49ae5cc25735ef71e85d122
|
|
| BLAKE2b-256 |
b3699fa541e189b3628103cb7514e826e9a5659c7b2f11ea613881e7b733e9f5
|