
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
simple-kvdb
Advanced tools
一个轻量级的键值存储数据库,使用JSON文件格式存储数据。
pip install simple-kvdb
from simple_kvdb import KVDB
# 创建数据库实例
db = KVDB("my_database.json")
# 存储数据
db.set("user:1", {"name": "张三", "age": 25})
db.set("user:2", {"name": "李四", "age": 30})
# 获取数据
user = db.get("user:1")
print(user) # {'name': '张三', 'age': 25}
# 检查键是否存在
if db.exists("user:1"):
print("用户存在")
# 删除数据
db.delete("user:2")
# 获取所有键
all_keys = db.keys()
print(all_keys) # ['user:1']
# 获取数据库大小
size = db.size()
print(f"数据库包含 {size} 个键值对")
from simple_kvdb import KVDB
db = KVDB("advanced_db.json")
# 批量操作
db.set_many({
"config:theme": "dark",
"config:language": "zh-CN",
"stats:visits": 1000
})
# 获取多个值
values = db.get_many(["config:theme", "config:language"])
print(values) # {'config:theme': 'dark', 'config:language': 'zh-CN'}
# 条件查询
theme = db.get("config:theme", default="light")
print(theme) # dark
# 原子操作
db.atomic_update("stats:visits", lambda x: x + 1)
# 清空数据库
db.clear()
# 导出数据
data = db.export()
print(data) # {}
# 从字典导入数据
db.import_data({"key1": "value1", "key2": "value2"})
from simple_kvdb import KVDB
# 使用上下文管理器确保数据安全保存
with KVDB("temp_db.json") as db:
db.set("temp_key", "temp_value")
# 退出时自动保存
file_path (str): 数据库文件路径auto_save (bool): 是否自动保存,默认为 Truebackup_count (int): 备份文件数量,默认为 3set(key, value): 设置键值对get(key, default=None): 获取值delete(key): 删除键值对exists(key): 检查键是否存在keys(): 获取所有键values(): 获取所有值items(): 获取所有键值对size(): 获取数据库大小clear(): 清空数据库save(): 手动保存数据load(): 重新加载数据backup(): 创建备份set_many(data): 批量设置get_many(keys): 批量获取atomic_update(key, func): 原子更新export(): 导出数据import_data(data): 导入数据from simple_kvdb import KVDB, KVDBError
try:
db = KVDB("test.json")
db.set("key", "value")
except KVDBError as e:
print(f"数据库错误: {e}")
save() 方法auto_save=False 可以提高写入性能MIT License
欢迎提交 Issue 和 Pull Request!
FAQs
一个轻量级的键值存储数据库,使用JSON文件格式
We found that simple-kvdb demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.