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
 
## sub key
f.c = 1
f['c', 'data'] = [1, 2, 3, 4, 5]  # can only access 'sub key' by getitem && .set. Can only use str in this mode.
print(f.list('c'))
del f['c']  
 
## 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
 
## 使用子键
f.c = 1
f['c', 'data'] = [1, 2, 3, 4, 5]  # 子键模式只能使用getitem和.set这两种方式。子键模式只能使用str进行索引
print(f.list('c'))
del f['c']  
 
## 使用其他键不仅仅是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.9.3.tar.gz (33.7 kB view details)

Uploaded Source

Built Distribution

files3-0.9.3-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file files3-0.9.3.tar.gz.

File metadata

  • Download URL: files3-0.9.3.tar.gz
  • Upload date:
  • Size: 33.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for files3-0.9.3.tar.gz
Algorithm Hash digest
SHA256 942296a92394adb1d65f11a53e1c8309031a3121acda80062ded1b2683955e07
MD5 ccf2a1225a3dc1f3fa02044c740fa18e
BLAKE2b-256 dbac39ef47092339f79490f7a0aabc3e58f882b60034bd312b14bb623d3ae8fc

See more details on using hashes here.

File details

Details for the file files3-0.9.3-py3-none-any.whl.

File metadata

  • Download URL: files3-0.9.3-py3-none-any.whl
  • Upload date:
  • Size: 34.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for files3-0.9.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a51b0b9762550c6960889dd7fdec401e47e8a650253e11adb068f1e61e874011
MD5 925fc6b50578fc7e13de7e4ab53c3b12
BLAKE2b-256 fd59977a4675e0dd76967c328231314a4a32e0f2cdcc89c28f18b5b0ca33bcd4

See more details on using hashes here.

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