Python 简洁快速的保存和读取变量, 方便的版本控制!
Project description
CellDict
基于 Pickle
的高效便捷变量保存读取!
简洁快速的保存和读取变量, 方便的版本控制.
安装
pip install -U celldict
简介
celldict
由 CellDict
和 CellTable
两个类构成.
CellDict
是文件型的 Key-value 数据结构, 支持版本控制, 支持多线程读写并发, 支持多进程读写与只读模式.
CellTable
是文件型的表数据结构, 支持不规整数据, 支持修改删除操作记录, 支持多线程读写并发, 支持多进程读写与只读模式.
CellDict
from celldict import CellDict
# 数据集名称为 "dataname", 修改记录保存三次
cdict = CellDict("dataname", version_record=3, root_path=".CellDict")
# 保存数据
cdict.set("key", "value")
cdict.set("Hello", "world")
cdict["test"] = "any data"
# 读取数据
cdict.get("key")
cdict["test"]
# 删除数据 成功返回 True
cdict.delete("test")
del cdict["test"]
# 获取 keys
cdict.keys()
# 多版本控制
# version_record=3 修改记录保存三次
cdict.set("test", 1) # 最旧版本 被覆盖
cdict.set("test", 2) # 覆盖后的最旧记录
cdict.set("test", 3)
cdict.set("test", 4) # 最新版本记录
# 读取最新记录 4
cdict.get("test", "last")
# 读取最旧记录 2
cdict.get("test", "former")
# 按索引读取
cdict.get("test", 0) # 4
cdict.get("test", 1) # 3
cdict.get("test", 2) # 2
cdict.get("test", -1) # 2
cdict.get("test", -2) # 3
cdict.get("test", -3) # 4
# 读取所有版本数据
cdict.getall("test")
CellTable
from celldict import CellTable
ctable = CellTable("dataname", root_path=".CellTable")
# 增加一条记录, 返回保存的主键
ctable.add("Hello World!") # 0
ctable.add([1, 2, 3, 4]) # 1
..
ctable.add("any data") # n
# 读取对应键值的数据
ctable.get(0) # "Hello World!"
ctable[1] # [1, 2, 3, 4]
ctable[2] # "any data"
# 读取指定键值的数据返回列表
ctable[0, 2] # ["Hello World!", "any data"]
# 通过切片获取值, 索引为键值
ctable[1:] # [[1, 2, 3, 4], 'any data']
# 通过时间取值
from datetime import datetime
# 获取 datetime 日期内插入的数据, 时分秒为零
key = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
ctable[key] # ['Hello World!', [1, 2, 3, 4], 'any data']
# 获取时间间隔内插入的数据
start = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
end = datetime.now().replace(hour=10, minute=0, second=0, microsecond=0)
ctable[start : end]
# 修改值, 修改记录保存在 modify 文件夹中
ctable.set(2, "modify data")
ctable[2] = "modify data"
# 删除值, 删除记录保存在 delete 文件夹中
ctable.delete(2)
del ctable[2]
CellTable
优势在于对数据结构没有限制, 可以方便的拓展和去除数据, 且不需要写sql语句, 效率也比 sqlite 高, 使用起来也很方便.
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
celldict-2.0.1.tar.gz
(14.8 kB
view details)
Built Distribution
celldict-2.0.1-py3-none-any.whl
(14.0 kB
view details)
File details
Details for the file celldict-2.0.1.tar.gz
.
File metadata
- Download URL: celldict-2.0.1.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54142bb0816861fafdb9a7cc2ac7d15b33c69ec7bd183c0d725fc63a5d84b230 |
|
MD5 | a3ee6a0eeee93faa43945adc22c0d116 |
|
BLAKE2b-256 | 2dd8d120543b2d6dbd4a077dd309d5fd4f79fd51cbe0fee7e015ff5c618dd2a6 |
File details
Details for the file celldict-2.0.1-py3-none-any.whl
.
File metadata
- Download URL: celldict-2.0.1-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c3510bc221cbd3ca6bba04a8f4dbd58abd3a4b80eab9a3793f347c06f7cb339 |
|
MD5 | 4d86cbca3d7373e0863a4d46e9d1822d |
|
BLAKE2b-256 | 54445d94c3980d062a8effc37a32a091483dc3bf9b57b054a7e2ab5f1ae86946 |