Skip to main content

(cloudpickle+lz4 based) save Python objects in binary to both the `file system` and `virtual disk in ram` 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.10.0a0.tar.gz (63.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

files3-0.10.0a0-py3-none-any.whl (68.9 kB view details)

Uploaded Python 3

File details

Details for the file files3-0.10.0a0.tar.gz.

File metadata

  • Download URL: files3-0.10.0a0.tar.gz
  • Upload date:
  • Size: 63.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for files3-0.10.0a0.tar.gz
Algorithm Hash digest
SHA256 a94400d97402a05611532176064a135cfd9fe3b16498cd5076e67d1639c42410
MD5 0d9f5d2cf5a04ce5d8314fe38726e395
BLAKE2b-256 e47c9f543d97aa9a549a682b1d9d02f25e7a5b2cc7bd09552977e5a1c120b825

See more details on using hashes here.

File details

Details for the file files3-0.10.0a0-py3-none-any.whl.

File metadata

  • Download URL: files3-0.10.0a0-py3-none-any.whl
  • Upload date:
  • Size: 68.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for files3-0.10.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb86f05921e8b4e64455b6a8d23afc571f9632c835639ab02896256cba627be4
MD5 da86dffcfe25824bfa57430e570fb7e4
BLAKE2b-256 ebefc0e03b5f69f9cb5919ad413739e8588d9a2fefffae5c5ce78a27f0ac300b

See more details on using hashes here.

Supported by

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