Skip to main content

fsoopify

GitHub Build Status PyPI

Just make file system oopify.

install

pip install fsoopify

usage

import fsoopify

[file|directory] = fsoopify.NodeInfo.from_path(...)

# api for both file and directory
file.rename()
file.get_parent()
file.is_exists()
file.is_directory()
file.is_file()
file.delete()
file.create_hardlink()

# api for file
file.load_context() # load and dump the file in a context.

# api for directory
directory.create() and directory.ensure_created()
directory.create_file()
directory.iter_items()
directory.list_items()
directory.get_fileinfo() and directory.get_dirinfo()
directory.has_file() and directory.has_directory()

Api

File

You can use fsoopify.FileInfo(...) to create a FileInfo object and use file api.

Prop Api

  • size - a int value with override __str__.

Test Api

  • is_exists()
  • is_file()

Open Api

  • open() - alias for builtin open
  • open_for_read_bytes()
  • open_for_read_text()

Read and Write Api

  • write()
  • write_text()
  • write_bytes()
  • write_from_stream()
  • read()
  • read_text()
  • read_bytes()
  • read_into_stream()

And you can use += for append data:

fi = FileInfo(...)
fi += 'data'
fi += b'data'
fi += FileInfo(other_file)
fi += io.BytesIO(b'data')
...

Serialize Api

  • load()
  • dump()
  • load_context()

The easiest way to dump a json:

FileInfo('a.json').dump(the_obj_to_dump)

Or load:

obj = FileInfo('a.json').load()

The format can auto detect by extension name.

Another way to load and dump a file is load_context():

with FileInfo('a.json').load_context() as ctx:
    ctx.data = the_obj_to_dump

With load_context(lock=True), you can lock the file in the context.

Hash Api

To compute hash for a file:

crc32, md5, sha1 = FileInfo('a.json').get_file_hash('crc32', 'md5', 'sha1')

Directory

You can use fsoopify.DirectoryInfo(...) to create a DirectoryInfo object and use directory api.

Tree Api

The easiest way to batch read files:

DirectoryInfo(...).get_tree()
# {
#      filename: b'file content',
#      sub_dirname: {
#           ...
#      }
# }

# to prevent load all file into memory:
DirectoryInfo(...).get_tree(as_stream=True)

Or batch write files:

tree = {
    'a.txt': b'abc',
    'b.txt': b'cde',
    'sub_dir': {
        'e.txt': b'ddd'
    }
}
DirectoryInfo(...).make_tree(tree)

Optional packages

  • json5 - load or dump json5 file
  • pyyaml - load or dump yaml file
  • toml - load or dump toml file
  • pipfile - load pipfile

Metadata

Release files for fsoopify 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fsoopify 0.5.2
File Size Uploaded Provenance
fsoopify-0.5.2.tar.gz 14.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fsoopify 0.5.2
File Interpreter ABI Platform
fsoopify-0.5.2-py3-none-any.whl Python 3 none any Details

Total release size: 31.2 kB

Release files / fsoopify-0.5.2.tar.gz

Download URL fsoopify-0.5.2.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
db06b87c9617dd8c04619542d3cb4dd5e40e5c0f66eea489e6545c6112f5655b
BLAKE2b-256 checksum
How to use checksums
65a64f41722ae258671c18678fbe240bc6d87ed9f40d3702318f0434f9fc9f59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.1

Release files / fsoopify-0.5.2-py3-none-any.whl

Download URL fsoopify-0.5.2-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
54c738f23ba86b8912bbc0524438dc2e30e736922a48a2a5ca61a0a70f772ba5
BLAKE2b-256 checksum
How to use checksums
d7c7995ed5470b5833e16750279a82e502028051ab911a4624cac17231a7efd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.1

Security for fsoopify 0.5.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.5.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page