sqlite-dic 0.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,97 @@
1
+ Metadata-Version: 2.1
2
+ Name: sqlite_dic
3
+ Version: 0.0.0
4
+ Summary: A lightweight SQLite-backed database that can be used like a Python dictionary.
5
+ Home-page: https://github.co.jp/
6
+ Author: bib_inf
7
+ Author-email: contact.bibinf@gmail.com
8
+ License: CC0 v1.0
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Topic :: Software Development :: Libraries
11
+ Classifier: License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
12
+ Description-Content-Type: text/markdown
13
+
14
+ English description follows Japanese.
15
+
16
+ ---
17
+
18
+ Pythonの辞書のように使える、SQLiteバックエンドの軽量キーバリューストアです。
19
+
20
+ ## 概要
21
+ - `sqlite-dic` は、SQLiteデータベースをPythonの辞書と同じ感覚で操作できるライブラリです。値にはJSONシリアライズ可能な任意の型(文字列、数値、真偽値、リスト、辞書、`None`)を格納できます。
22
+ - 内部ではSQLiteのWAL(Write-Ahead Logging)モードを使用しており、読み書きの並列アクセスが可能です。すべての操作はスレッドセーフです。
23
+ - AIでのコーディングにおいてこのツールを使用するときは、そのままこのドキュメントをプロンプトに含めることで、AIにこのDBを使ってコーディングしてもらうことが可能です。
24
+
25
+ ## インストール
26
+
27
+ ```bash
28
+ pip install sqlite-dic
29
+ ```
30
+
31
+ ## 使い方
32
+
33
+ ```python
34
+ import sqlite_dic
35
+
36
+ # データベースを開く(存在しなければ自動作成)
37
+ db = sqlite_dic("./sample.db")
38
+
39
+ # 値の追加・更新 — 辞書と同じ書き方
40
+ db["count"] = 33
41
+ db["config"] = {"theme": "dark", "lang": "ja"}
42
+
43
+ # 値の取得
44
+ print(db["count"]) # 33
45
+ print(db["config"]) # {'theme': 'dark', 'lang': 'ja'}
46
+
47
+ # エントリの削除
48
+ del db["count"]
49
+
50
+ # 格納数の確認
51
+ print(len(db)) # 1
52
+ ```
53
+
54
+ ## 制約
55
+ - **キー** は文字列のみ使用可能です。
56
+ - **値** はJSONシリアライズ可能な型(`dict`、`list`、`str`、`int`、`float`、`bool`、`None`)に限ります。
57
+ - 同時書き込みはSQLiteのファイルロックにより直列化されます(busy timeout: 30秒)。
58
+
59
+ ---
60
+
61
+ A lightweight key-value store backed by SQLite, with a Python `dict`-like interface.
62
+
63
+ ## Overview
64
+ - `sqlite-dic` lets 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, and `None` without any extra setup.
65
+ - Under the hood, SQLite's WAL (Write-Ahead Logging) mode provides concurrent read/write access, and all operations are thread-safe.
66
+
67
+ ## Installation
68
+ ```bash
69
+ pip install sqlite-dic
70
+ ```
71
+
72
+ ## Quick Start
73
+ ```python
74
+ import sqlite_dic
75
+
76
+ # Open (or create) a database
77
+ db = sqlite_dic("./sample.db")
78
+
79
+ # Set values — just like a dict
80
+ db["count"] = 33
81
+ db["config"] = {"theme": "dark", "lang": "en"}
82
+
83
+ # Get values
84
+ print(db["count"]) # 33
85
+ print(db["config"]) # {'theme': 'dark', 'lang': 'en'}
86
+
87
+ # Delete an entry
88
+ del db["count"]
89
+
90
+ # Check the number of stored entries
91
+ print(len(db)) # 1
92
+ ```
93
+
94
+ ## Constraints
95
+ - **Keys** must be strings.
96
+ - **Values** must be JSON-serializable (`dict`, `list`, `str`, `int`, `float`, `bool`, or `None`).
97
+ - Concurrent writes are serialized by SQLite's file lock (busy timeout: 30 seconds).
@@ -0,0 +1,84 @@
1
+ English description follows Japanese.
2
+
3
+ ---
4
+
5
+ Pythonの辞書のように使える、SQLiteバックエンドの軽量キーバリューストアです。
6
+
7
+ ## 概要
8
+ - `sqlite-dic` は、SQLiteデータベースをPythonの辞書と同じ感覚で操作できるライブラリです。値にはJSONシリアライズ可能な任意の型(文字列、数値、真偽値、リスト、辞書、`None`)を格納できます。
9
+ - 内部ではSQLiteのWAL(Write-Ahead Logging)モードを使用しており、読み書きの並列アクセスが可能です。すべての操作はスレッドセーフです。
10
+ - AIでのコーディングにおいてこのツールを使用するときは、そのままこのドキュメントをプロンプトに含めることで、AIにこのDBを使ってコーディングしてもらうことが可能です。
11
+
12
+ ## インストール
13
+
14
+ ```bash
15
+ pip install sqlite-dic
16
+ ```
17
+
18
+ ## 使い方
19
+
20
+ ```python
21
+ import sqlite_dic
22
+
23
+ # データベースを開く(存在しなければ自動作成)
24
+ db = sqlite_dic("./sample.db")
25
+
26
+ # 値の追加・更新 — 辞書と同じ書き方
27
+ db["count"] = 33
28
+ db["config"] = {"theme": "dark", "lang": "ja"}
29
+
30
+ # 値の取得
31
+ print(db["count"]) # 33
32
+ print(db["config"]) # {'theme': 'dark', 'lang': 'ja'}
33
+
34
+ # エントリの削除
35
+ del db["count"]
36
+
37
+ # 格納数の確認
38
+ print(len(db)) # 1
39
+ ```
40
+
41
+ ## 制約
42
+ - **キー** は文字列のみ使用可能です。
43
+ - **値** はJSONシリアライズ可能な型(`dict`、`list`、`str`、`int`、`float`、`bool`、`None`)に限ります。
44
+ - 同時書き込みはSQLiteのファイルロックにより直列化されます(busy timeout: 30秒)。
45
+
46
+ ---
47
+
48
+ A lightweight key-value store backed by SQLite, with a Python `dict`-like interface.
49
+
50
+ ## Overview
51
+ - `sqlite-dic` lets 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, and `None` without any extra setup.
52
+ - Under the hood, SQLite's WAL (Write-Ahead Logging) mode provides concurrent read/write access, and all operations are thread-safe.
53
+
54
+ ## Installation
55
+ ```bash
56
+ pip install sqlite-dic
57
+ ```
58
+
59
+ ## Quick Start
60
+ ```python
61
+ import sqlite_dic
62
+
63
+ # Open (or create) a database
64
+ db = sqlite_dic("./sample.db")
65
+
66
+ # Set values — just like a dict
67
+ db["count"] = 33
68
+ db["config"] = {"theme": "dark", "lang": "en"}
69
+
70
+ # Get values
71
+ print(db["count"]) # 33
72
+ print(db["config"]) # {'theme': 'dark', 'lang': 'en'}
73
+
74
+ # Delete an entry
75
+ del db["count"]
76
+
77
+ # Check the number of stored entries
78
+ print(len(db)) # 1
79
+ ```
80
+
81
+ ## Constraints
82
+ - **Keys** must be strings.
83
+ - **Values** must be JSON-serializable (`dict`, `list`, `str`, `int`, `float`, `bool`, or `None`).
84
+ - Concurrent writes are serialized by SQLite's file lock (busy timeout: 30 seconds).
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,29 @@
1
+
2
+ from setuptools import setup
3
+ # 公開用パッケージの作成 [ezpip]
4
+ import ezpip
5
+
6
+ # 公開用パッケージの作成 [ezpip]
7
+ with ezpip.packager(develop_dir = "./_develop_sqlite_dic/") as p:
8
+ setup(
9
+ name = "sqlite_dic",
10
+ version = "0.0.0",
11
+ description = "A lightweight SQLite-backed database that can be used like a Python dictionary.",
12
+ author = "bib_inf",
13
+ author_email = "contact.bibinf@gmail.com",
14
+ url = "https://github.co.jp/",
15
+ packages = p.packages,
16
+ install_requires = ["ezpip"],
17
+ long_description = p.long_description,
18
+ long_description_content_type = "text/markdown",
19
+ license = "CC0 v1.0",
20
+ classifiers = [
21
+ "Programming Language :: Python :: 3",
22
+ "Topic :: Software Development :: Libraries",
23
+ "License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication"
24
+ ],
25
+ # entry_points = """
26
+ # [console_scripts]
27
+ # py6 = py6:console_command
28
+ # """
29
+ )
@@ -0,0 +1,60 @@
1
+ # SQLite辞書DB [sqlite-dic]
2
+
3
+ import sys
4
+ import json
5
+ import sqlite3
6
+ import threading
7
+ from collections.abc import MutableMapping
8
+
9
+ # テーブル定義式
10
+ SCHEMA = "CREATE TABLE IF NOT EXISTS main (key TEXT PRIMARY KEY, value TEXT)"
11
+
12
+ # SQLite辞書DB [sqlite-dic]
13
+ class SQLite_Dic(MutableMapping): # 辞書ライクオブジェクトを継承することで辞書的インターフェースを自動的に実現
14
+ # 初期化処理
15
+ def __init__(self, path):
16
+ self._path = path
17
+ self._local = threading.local() # スレッドごとに接続を保持するためのストレージ
18
+ self.exe_and_com(SCHEMA) # 初期テーブル作成
19
+ # execute と commit を実行
20
+ def exe_and_com(self, *args):
21
+ cur = self.conn.execute(*args)
22
+ self.conn.commit()
23
+ return cur
24
+ # DBへの接続obj取得
25
+ @property
26
+ def conn(self):
27
+ if getattr(self._local, "conn", None) is None: # 存在しない場合新規作成
28
+ conn = sqlite3.connect(self._path)
29
+ conn.execute("PRAGMA journal_mode=WAL") # WALモード (高速)
30
+ conn.execute("PRAGMA busy_timeout=30000") # 30秒タイムアウト
31
+ self._local.conn = conn
32
+ return self._local.conn
33
+ # MutableMapping の必須実装メソッド5つ
34
+ def __getitem__(self, key):
35
+ row = self.conn.execute("SELECT value FROM main WHERE key=?", [key]).fetchone()
36
+ if row is None: raise KeyError(key)
37
+ return json.loads(row[0])
38
+ def __setitem__(self, key, value):
39
+ encoded = json.dumps(value, ensure_ascii=False) # JSON化
40
+ self.exe_and_com("INSERT OR REPLACE INTO main (key, value) VALUES (?, ?)", [key, encoded]) # execute と commit を実行
41
+ def __delitem__(self, key):
42
+ cur = self.exe_and_com("DELETE FROM main WHERE key=?", [key]) # execute と commit を実行
43
+ if cur.rowcount == 0: raise KeyError(key)
44
+ def __iter__(self):
45
+ rows = self.conn.execute("SELECT key FROM main").fetchall()
46
+ return (r[0] for r in rows)
47
+ def __len__(self):
48
+ return self.conn.execute("SELECT COUNT(*) FROM main").fetchone()[0]
49
+ # 第一・第二文字列化
50
+ def __str__(self): return f"<sqlite-dic len={len(self)}>"
51
+ def __repr__(self): return str(self)
52
+ # DB接続を閉じる (複数回呼んでも安全; atexit登録はしなくても安全と考えられるので今回は略)
53
+ def __del__(self):
54
+ conn = getattr(self._local, "conn", None)
55
+ if conn is None: return None
56
+ conn.close()
57
+ self._local.conn = None
58
+
59
+ # モジュールオブジェクトとクラスオブジェクトを同一視
60
+ sys.modules[__name__] = SQLite_Dic
@@ -0,0 +1,14 @@
1
+ # SQLite辞書DB [sqlite-dic]
2
+ # 【動作確認 / 使用例】
3
+
4
+ import ezpip
5
+ # SQLite辞書DB [sqlite-dic]
6
+ sqlite_dic = ezpip.load_develop("sqlite_dic", "../", develop_flag = True)
7
+
8
+ db = sqlite_dic("./sample.db") # DB接続
9
+
10
+ db["hoge"] = 33 # DBへの値の追加/更新
11
+ db["fuga"] = {"k": "value"} # 値はJSON化可能な任意の値が使える
12
+ print(db["hoge"]) # 値の取得
13
+ del db["hoge"] # エントリの削除
14
+ print(len(db)) # -> 1
@@ -0,0 +1,97 @@
1
+ Metadata-Version: 2.1
2
+ Name: sqlite-dic
3
+ Version: 0.0.0
4
+ Summary: A lightweight SQLite-backed database that can be used like a Python dictionary.
5
+ Home-page: https://github.co.jp/
6
+ Author: bib_inf
7
+ Author-email: contact.bibinf@gmail.com
8
+ License: CC0 v1.0
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Topic :: Software Development :: Libraries
11
+ Classifier: License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
12
+ Description-Content-Type: text/markdown
13
+
14
+ English description follows Japanese.
15
+
16
+ ---
17
+
18
+ Pythonの辞書のように使える、SQLiteバックエンドの軽量キーバリューストアです。
19
+
20
+ ## 概要
21
+ - `sqlite-dic` は、SQLiteデータベースをPythonの辞書と同じ感覚で操作できるライブラリです。値にはJSONシリアライズ可能な任意の型(文字列、数値、真偽値、リスト、辞書、`None`)を格納できます。
22
+ - 内部ではSQLiteのWAL(Write-Ahead Logging)モードを使用しており、読み書きの並列アクセスが可能です。すべての操作はスレッドセーフです。
23
+ - AIでのコーディングにおいてこのツールを使用するときは、そのままこのドキュメントをプロンプトに含めることで、AIにこのDBを使ってコーディングしてもらうことが可能です。
24
+
25
+ ## インストール
26
+
27
+ ```bash
28
+ pip install sqlite-dic
29
+ ```
30
+
31
+ ## 使い方
32
+
33
+ ```python
34
+ import sqlite_dic
35
+
36
+ # データベースを開く(存在しなければ自動作成)
37
+ db = sqlite_dic("./sample.db")
38
+
39
+ # 値の追加・更新 — 辞書と同じ書き方
40
+ db["count"] = 33
41
+ db["config"] = {"theme": "dark", "lang": "ja"}
42
+
43
+ # 値の取得
44
+ print(db["count"]) # 33
45
+ print(db["config"]) # {'theme': 'dark', 'lang': 'ja'}
46
+
47
+ # エントリの削除
48
+ del db["count"]
49
+
50
+ # 格納数の確認
51
+ print(len(db)) # 1
52
+ ```
53
+
54
+ ## 制約
55
+ - **キー** は文字列のみ使用可能です。
56
+ - **値** はJSONシリアライズ可能な型(`dict`、`list`、`str`、`int`、`float`、`bool`、`None`)に限ります。
57
+ - 同時書き込みはSQLiteのファイルロックにより直列化されます(busy timeout: 30秒)。
58
+
59
+ ---
60
+
61
+ A lightweight key-value store backed by SQLite, with a Python `dict`-like interface.
62
+
63
+ ## Overview
64
+ - `sqlite-dic` lets 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, and `None` without any extra setup.
65
+ - Under the hood, SQLite's WAL (Write-Ahead Logging) mode provides concurrent read/write access, and all operations are thread-safe.
66
+
67
+ ## Installation
68
+ ```bash
69
+ pip install sqlite-dic
70
+ ```
71
+
72
+ ## Quick Start
73
+ ```python
74
+ import sqlite_dic
75
+
76
+ # Open (or create) a database
77
+ db = sqlite_dic("./sample.db")
78
+
79
+ # Set values — just like a dict
80
+ db["count"] = 33
81
+ db["config"] = {"theme": "dark", "lang": "en"}
82
+
83
+ # Get values
84
+ print(db["count"]) # 33
85
+ print(db["config"]) # {'theme': 'dark', 'lang': 'en'}
86
+
87
+ # Delete an entry
88
+ del db["count"]
89
+
90
+ # Check the number of stored entries
91
+ print(len(db)) # 1
92
+ ```
93
+
94
+ ## Constraints
95
+ - **Keys** must be strings.
96
+ - **Values** must be JSON-serializable (`dict`, `list`, `str`, `int`, `float`, `bool`, or `None`).
97
+ - Concurrent writes are serialized by SQLite's file lock (busy timeout: 30 seconds).
@@ -0,0 +1,9 @@
1
+ README.md
2
+ setup.py
3
+ sqlite_dic/__init__.py
4
+ sqlite_dic/test.py
5
+ sqlite_dic.egg-info/PKG-INFO
6
+ sqlite_dic.egg-info/SOURCES.txt
7
+ sqlite_dic.egg-info/dependency_links.txt
8
+ sqlite_dic.egg-info/requires.txt
9
+ sqlite_dic.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ ezpip
@@ -0,0 +1 @@
1
+ sqlite_dic