faker_file.providers.augment_file_from_dir package

Subpackages

Module contents

class faker_file.providers.augment_file_from_dir.AugmentFileFromDirProvider(generator: Any)[source]

Bases: BaseProvider, FileMixin

Augment file from given directory provider.

Usage example:

from faker import Faker
from faker_file.providers.augment_file_from_dir import (
    AugmentFileFromDirProvider,
)

FAKER = Faker()
FAKER.add_provider(AugmentFileFromDirProvider)

file = FAKER.augment_file_from_dir(
    source_dir_path="/tmp/tmp/",
)

Usage example with options:


file = FAKER.augment_file_from_dir(

source_dir_path=”/tmp/tmp/”, prefix=”zzz”, extensions={“docx”, “pdf”}

)

augment_file_from_dir(source_dir_path: str, extensions: Optional[Iterable[str]] = None, storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, wrap_chars_after: Optional[int] = None, text_extractor_cls: Optional[Union[str, Type[BaseTextExtractor]]] = DEFAULT_EXTRACTOR, text_extractor_kwargs: Optional[Dict[str, Any]] = None, text_augmenter_cls: Optional[Union[str, Type[BaseTextAugmenter]]] = DEFAULT_AUGMENTER, text_augmenter_kwargs: Optional[Dict[str, Any]] = None, raw: bool = True, **kwargs) BytesValue[source]
augment_file_from_dir(source_dir_path: str, extensions: Optional[Iterable[str]] = None, storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, wrap_chars_after: Optional[int] = None, text_extractor_cls: Optional[Union[str, Type[BaseTextExtractor]]] = DEFAULT_EXTRACTOR, text_extractor_kwargs: Optional[Dict[str, Any]] = None, text_augmenter_cls: Optional[Union[str, Type[BaseTextAugmenter]]] = DEFAULT_AUGMENTER, text_augmenter_kwargs: Optional[Dict[str, Any]] = None, **kwargs) StringValue

Augment a random file from given directory.

Parameters:
  • source_dir_path – Source files directory.

  • extensions – Allowed extensions.

  • storage – Storage. Defaults to FileSystemStorage.

  • basename – File basename (without extension).

  • prefix – File name prefix.

  • wrap_chars_after – If given, the output string would be separated by line breaks after the given position.

  • text_extractor_cls – Text extractor class.

  • text_extractor_kwargs – Text extractor kwargs.

  • text_augmenter_cls – Text augmenter class.

  • text_augmenter_kwargs – Text augmenter kwargs.

  • raw – If set to True, return BytesValue (binary content of the file). Otherwise, return StringValue (path to the saved file).

Returns:

Relative path (from root directory) of the generated file or raw content of the file.

extension: str = ''