Skip to main content

(pickle+lz4 based) save Python objects in binary to the file system and manage them.

Project description

Files3 Python Object Management

  1. English Version
    1. Intallation
    2. Quick Start
    3. Advanced
    4. Notice
    5. Cmd Command
    6. Last
  2. Chinese Version
    1. Intallation
    2. Quick Start
    3. Advanced
    4. Cmd Command
    5. Last

Installation

pip install files3

# After installation, you can use the command in cmd:

f3assoc .inst
to associate the '.inst' file with the 'f3open' program.

Quick Start

from files3 import files
f = files()  # save pyfile in current directory with default suffix '.inst'
 
## save python object (modify is also like save)
f.set('a', 1)
 
## check if file exist
f.has('a')  # True
 
## load python object
print(f.get('a'))  # 1
 
## delete file
f.delete('a')

files(dir:str="", type:str=".inst")

Advanced

from files3 import files
f = files()
 
## Save
f.a = 1
# f['a'] = 1
 
## load
print(f.a)  # 1
# print(f['a'])  # 1
 
## delete
del f.a
# del f['a']
 
## check if file exist
'a' in f  # False
 
 
## Use other key not only str:
# 1. tuple or list
f[('a', 'b')] = [1, 2]
print(f.a, f.b, f['a'], f['b'])  # 1, 2, [1, 2]
 
# 2. slice
print(f[:])  # [1, 2]
# print(f[...])  # [1, 2]
 
# 3. function
print(f[lambda x: x == 'a'])  # 1
 
# 4. re
print(f[re.compile('a')])  # 1
 
del f[...]
# hash: get hash of the file
fhash = f.hash('a')
 
# retype: adjust the ftype of exists files
f.retytpe('.newtype', 'a', 'b', ...)  # f.retype('.newtype')  # all files
 
# relink: manual adjust the scp(Source Code Path) of exists files 
f.retytpe('C:/mycode/code.py', 'a', 'b', ...)  # f.retype('C:/mycode/code.py')  # all files

Notice

There are some special case that you can't save:

  1. f3bool object and files object (alias Files, F3Shell)
  2. Actively refuse to serialize objects (such objects will actively throw errors when attempting to serialize)
  3. cases not supported by pickle (such as module, lambda, local function/class (that is nested inside other functions and classes))

Cmd Command


f3 [name] [type] -d [dir]  # open a files3 object
f3open [fpath]  # open a files3 object
f3assoc [type]  # associate the '.type' file with the 'f3open' program

Last

It's really convinent but, because pickle is not safe, so mayn't use it to load the file you don't trust. However, if you do not care about it like me, you can use it to bring you a good programming experience.

安装files3

pip install files3

# 安装后,可以在cmd中使用命令:

f3assoc .inst
将'.inst'文件关联到'f3open'程序。

快速开始

from files3 import files
f = files()  # 保存py文件在当前目录,后缀为'.inst'
 
## 保存python对象(修改也是这样)
f.set('a', 1)
 
## 检查文件是否存在
f.has('a')  # True
 
## 加载python对象
print(f.get('a'))  # 1
 
## 删除文件
f.delete('a')

files(dir:str="", type:str=".inst")

高级用法

from files3 import files
f = files()
 
## 保存
f.a = 1
# f['a'] = 1
 
## 加载
print(f.a)  # 1
# print(f['a'])  # 1
 
## 删除
del f.a
# del f['a']
 
## 检查文件是否存在
'a' in f  # False
 
 
## 使用其他键不仅仅是str:
# 1. tuple or list
f[('a', 'b')] = [1, 2]
print(f.a, f.b, f['a'], f['b'])  # 1, 2, [1, 2]
 
# 2. slice
print(f[:])  # [1, 2]
# print(f[...])  # [1, 2]
 
# 3. function
print(f[lambda x: x == 'a'])  # 1
 
# 4. re
print(f[re.compile('a')])  # 1
 
del f[...]
# hash:获取目标的文件指纹
fhash = f.hash('a')
 
# retype: 调整已有文件的后缀
f.retytpe('.newtype', 'a', 'b', ...)  # f.retype('.newtype')  # 全部文件
 
# relink: 手动调整已有文件的源代码后位置
f.retytpe('C:/mycode/code.py', 'a', 'b', ...)  # f.retype('C:/mycode/code.py')  # 全部文件

注意

有一些特殊情况不能保存:

  1. f3bool对象和files对象(别名Files, F3Shell)
  2. 主动拒绝序列化的对象(例如此类对象在试图序列化时会主动抛出error)
  3. pickle不支持的情况(例如 module,lambda,local function/class (那种嵌套在其他函数和class内部的))

Cmd命令


f3 [name] [type] -d [dir]  # 打开一个files3对象
f3open [fpath]  # 打开一个files3对象
f3assoc [type]  # 将'.type'文件关联到'f3open'程序

最后

这确实很方便,但是由于pickle不安全,因此可能不要使用它来加载您不信任的文件。 但是,如果您不像我一样不怎么关心它,那么可以使用它为您带来良好的编程体验。

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

files3-0.6.0.1.tar.gz (25.9 kB view hashes)

Uploaded Source

Built Distribution

files3-0.6.0.1-py3-none-any.whl (26.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page