Skip to main content

Democritus functions for working with files and directories.

Project description

Democritus File System (Files and Directories)

PyPI CI Lint codecov The Democritus Project uses semver version 2.0.0 The Democritus Project uses ruff to format and lint code License: LGPL v3

Democritus functions[1] for working with files and directories.

[1] Democritus functions are simple, effective, modular, well-tested, and well-documented Python functions.

We use d8s (pronounced "dee-eights") as an abbreviation for democritus (you can read more about this here).

Installation

pip install d8s-file-system

Usage

You import the library like:

from d8s_file_system import *

Once imported, you can use any of the functions listed below.

Functions

  • def is_file(path: str) -> bool:
        """Determine if the given path is a file."""
    
  • def file_read(file_path: str) -> str:
        """Read the file at the given file_path as a string."""
    
  • def file_read_bytes(file_path: str) -> bytes:
        """Read the file at the given file_path as bytes."""
    
  • def file_write(file_path: str, file_contents: Any) -> bool:
        """Write the given content to the file at the given path (including a file name)."""
    
  • def file_append(file_path: str, file_contents: Any) -> bool:
        """Append the given content to the file at the given path (including a file name)."""
    
  • def file_move(starting_path: str, destination_path: str):
        """Move the file from the starting path to the destination path."""
    
  • def file_copy(starting_path: str, destination_path: str, *, preserve_metadata: bool = False):
        """Copy the file from the starting_path to the destination path."""
    
  • def file_delete(file_path: str):
        """Delete the given file."""
    
  • def file_owner_name(file_path: str) -> str:
        """Find the owner of the file at the given path."""
    
  • def file_change_owner(file_path: str):
        """Change the ownership of the given file."""
    
  • def file_ssdeep(file_path: str) -> str:
        """Find the ssdeep fuzzy hash of the file."""
    
  • def file_md5(file_path: str) -> str:
        """Find the md5 hash of the given file."""
    
  • def file_sha1(file_path: str) -> str:
        """Find the sha1 hash of the given file."""
    
  • def file_sha256(file_path: str) -> str:
        """Find the sha256 hash of the given file."""
    
  • def file_sha512(file_path: str) -> str:
        """Find the sha512 hash of the given file."""
    
  • def file_name_escape(file_name_arg: str) -> str:
        """Escape the name of a file so that it can be used as a file name in a file path."""
    
  • def file_name(file_path: str) -> str:
        """Find the file name from the given file path."""
    
  • def file_name_windows(windows_file_path: str) -> str:
        """Find the file name from the given windows_file_path."""
    
  • def file_name_unix(unix_file_path: str) -> str:
        """Find the file name from the given unix_file_path."""
    
  • def file_size(file_path: str) -> int:
        """Find the file size."""
    
  • def file_directory(file_path: str) -> str:
        """Return the directory in which the given file resides."""
    
  • def file_details(file_path: str) -> Dict[str, Union[str, int]]:
        """Get file hashes and file size for the given file."""
    
  • def file_exists(file_path: str) -> bool:
        """Check if the file exists."""
    
  • def file_is_readable(file_path: str) -> bool:
        """Check if the file is readable."""
    
  • def file_is_writable(file_path: str) -> bool:
        """Check if the file is writable."""
    
  • def file_is_executable(file_path: str) -> bool:
        """Check if the file is executable."""
    
  • def file_contains(file_path: str, pattern: str, *, pattern_is_regex: bool = False) -> bool:
        """Return whether or not the file contains the given pattern."""
    
  • def file_search(file_path: str, pattern: str, *, pattern_is_regex: bool = False) -> List[str]:
        """Search for the given pattern in the file."""
    
  • def file_name_matches(file_path: str, pattern: str) -> bool:
        """Return whether or not the file name contains the given pattern."""
    
  • def is_directory(path: str) -> bool:
        """Determine if the given path is a directory."""
    
  • def directory_exists(directory_path: str) -> bool:
        """Check if the directory exists."""
    
  • def directory_file_names(directory_path: str, *, recursive: bool = False) -> List[str]:
        """List files at the given directory_path."""
    
  • def directory_file_paths(directory_path: str, *, recursive: bool = False) -> List[str]:
        """List the file paths at the given directory_path."""
    
  • def directory_copy(src_path: str, dst_path: str):
        """Copy the directory from the src_path to the destination path."""
    
  • def directory_delete(directory_path: str):
        """Delete the given directory."""
    
  • def directory_create(directory_path: str, mode=0o777):
        """Create a directory."""
    
  • def directory_disk_usage(directory_path: str):
        """Return the disk usage for the given directory."""
    
  • def directory_disk_free_space(directory_path: str):
        """Return the free space in the given directory."""
    
  • def directory_disk_used_space(directory_path: str):
        """Return the used space in the given directory."""
    
  • def directory_disk_total_space(directory_path: str):
        """Return the total space in the given directory."""
    
  • def home_directory() -> str:
        """Return the home directory."""
    
  • def home_directory_join(path: str) -> str:
        """Join the given path with the home directory."""
    
  • def directory_move(src_path: str, dst_path: str):
        """Move the directory from the src_path to the dst_path."""
    
  • def directory_files_details(directory_path: str, *, recursive: bool = False) -> Dict[str, Dict[str, Union[str, int]]]:
        """Return the file details for each file in the directory at the given path."""
    
  • def directory_files_read(directory_path: str, *, recursive: bool = False) -> Iterable[Tuple[str, str]]:
        """Read all files in the directory_path."""
    
  • def directory_subdirectory_names(directory_path: str, *, recursive: bool = False) -> List[str]:
        """List the names of all subdirectories in the given directory."""
    
  • def directory_files_containing(
        directory_path: str, pattern: str, *, pattern_is_regex: bool = False, recursive: bool = False
    ) -> Dict[str, List[str]]:
        """Search for the given pattern in all files in the given directory_path."""
    
  • def directory_file_paths_matching(directory_path: str, pattern: str, *, recursive: bool = False) -> List[str]:
        """Return the paths of all of the files in the given directory which match the pattern."""
    
  • def directory_file_names_matching(directory_path: str, pattern: str, *, recursive: bool = False) -> List[str]:
        """Return the names of all of the files in the given directory which match the pattern."""
    
  • def directory_read_files_with_path_matching(
        directory_path: str, pattern: str, *, recursive: bool = False
    ) -> Iterable[Tuple[str, str]]:
        """Read all of the files in the given directory whose paths match the given pattern."""
    
  • def atomic_write(fpath, *, overwrite: bool = True, **cls_kwargs):
        """Create a context manager to write atomically using the AtomicWriterPerms class to update file permissions."""
    

Development

👋  If you want to get involved in this project, we have some short, helpful guides below:

If you have any questions or there is anything we did not cover, please raise an issue and we'll be happy to help.

Credits

This package was created with Cookiecutter and Floyd Hightower's Python project template.

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

d8s_file_system-0.11.0.tar.gz (96.6 kB view details)

Uploaded Source

Built Distribution

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

d8s_file_system-0.11.0-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file d8s_file_system-0.11.0.tar.gz.

File metadata

  • Download URL: d8s_file_system-0.11.0.tar.gz
  • Upload date:
  • Size: 96.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for d8s_file_system-0.11.0.tar.gz
Algorithm Hash digest
SHA256 3a07df280e88f7bdb8458cddec4455bb57886be049feee3a1e992f3aeddc386b
MD5 7e44e6635282177fa35411046822e236
BLAKE2b-256 864186e397a2260d007ade927e006dfb8433b4f14552e33707d915407eb6942b

See more details on using hashes here.

Provenance

The following attestation bundles were made for d8s_file_system-0.11.0.tar.gz:

Publisher: release-please.yml on democritus-project/d8s-file-system

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file d8s_file_system-0.11.0-py3-none-any.whl.

File metadata

File hashes

Hashes for d8s_file_system-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf4015452880cc6c75022b56b8087090b574c332a88795904a57f72b8728e0af
MD5 335510eb9268b2874f7c4e59d47fa9ea
BLAKE2b-256 7cf9009fc30da0092c0608551e7afbdfca14c196ee76b1495f031d51188435c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for d8s_file_system-0.11.0-py3-none-any.whl:

Publisher: release-please.yml on democritus-project/d8s-file-system

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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