faker_file.providers package¶
Subpackages¶
- faker_file.providers.augment_file_from_dir package
- faker_file.providers.base package
- faker_file.providers.helpers package
- Submodules
- faker_file.providers.helpers.inner module
create_inner_bin_file()
create_inner_csv_file()
create_inner_docx_file()
create_inner_eml_file()
create_inner_epub_file()
create_inner_file_from_path()
create_inner_generic_file()
create_inner_ico_file()
create_inner_jpeg_file()
create_inner_mp3_file()
create_inner_odp_file()
create_inner_ods_file()
create_inner_odt_file()
create_inner_pdf_file()
create_inner_png_file()
create_inner_pptx_file()
create_inner_random_file_from_dir()
create_inner_rtf_file()
create_inner_svg_file()
create_inner_tar_file()
create_inner_txt_file()
create_inner_webp_file()
create_inner_xlsx_file()
create_inner_xml_file()
create_inner_zip_file()
fuzzy_choice_create_inner_file()
list_create_inner_file()
- Module contents
- faker_file.providers.mixins package
- faker_file.providers.mp3_file package
- faker_file.providers.pdf_file package
Submodules¶
faker_file.providers.bin_file module¶
- class faker_file.providers.bin_file.BinFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
BIN file provider.
Usage example:
from faker import Faker from faker_file.providers.bin_file import BinFileProvider
file = BinFileProvider(Faker()).bin_file()
Usage example with options:
- file = BinFileProvider(Faker()).bin_file(
prefix=”zzz”, length=1024**2,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = BinFileProvider(Faker()).bin_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, length=1024**2,
)
Usage example with AWS S3 storage:
from faker_file.storages.aws_s3 import AWSS3Storage
- file = BinFileProvider(Faker()).bin_file(
storage=AWSS3Storage(bucket_name=”My-test-bucket”), prefix=”zzz”, length=1024**2,
)
- bin_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, length: int = 1 * 1024 * 1024, content: Optional[bytes] = None, raw: bool = True, **kwargs) BytesValue [source]¶
- bin_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, length: int = 1 * 1024 * 1024, content: Optional[bytes] = None, **kwargs) StringValue
Generate a BIN file with random bytes.
- Parameters:
storage – Storage class. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
length –
content – File content. If given, used as is.
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 = 'bin'¶
faker_file.providers.csv_file module¶
- class faker_file.providers.csv_file.CsvFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
CSV file provider.
Usage example:
from faker import Faker from faker_file.providers.csv_file import CsvFileProvider
file = CsvFileProvider(Faker()).csv_file()
Usage example with options:
from faker_file.providers.csv_file import CsvFileProvider
- file = CsvFileProvider(Faker()).csv_file(
prefix=”zzz”, num_rows=100, data_columns=(‘{{name}}’, ‘{{sentence}}’, ‘{{address}}’), include_row_ids=True,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = CsvFileProvider(Faker()).csv_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, num_rows=100,
)
- csv_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, header: Optional[Sequence[str]] = None, data_columns: Tuple[str, ...] = ('{{name}}', '{{address}}'), num_rows: int = 10, include_row_ids: bool = False, content: Optional[str] = None, encoding: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- csv_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, header: Optional[Sequence[str]] = None, data_columns: Tuple[str, ...] = ('{{name}}', '{{address}}'), num_rows: int = 10, include_row_ids: bool = False, content: Optional[str] = None, encoding: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate a CSV file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
header – The
header
argument expects a list or a tuple of strings that will serve as the header row if supplied.data_columns – The
data_columns
argument expects a list or a tuple of string tokens, and these string tokens will be passed toparse()
for data generation. Argument Groups are used to pass arguments to the provider methods. Bothheader
anddata_columns
must be of the same length.num_rows – The
num_rows
argument controls how many rows of data to generate, and theinclude_row_ids
argument may be set toTrue
to include a sequential row ID column.include_row_ids –
content – File content. If given, used as is.
encoding – Encoding.
format_func – Callable responsible for formatting template strings.
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 = 'csv'¶
faker_file.providers.docx_file module¶
- class faker_file.providers.docx_file.DocxFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
DOCX file provider.
Usage example:
from faker import Faker from faker_file.providers.docx_file import DocxFileProvider
file = DocxFileProvider(Faker()).docx_file()
Usage example with options:
- file = DocxFileProvider(Faker()).docx_file(
prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = DocxFileProvider(Faker()).docx_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
Usage example with content modifiers:
from io import BytesIO from faker_file.base import DynamicTemplate from faker_file.providers.jpeg_file import JpegFileProvider
- def add_table(provider, document, data, counter, **kwargs):
- table = document.add_table(
kwargs.get(“rows”, 3), kwargs.get(“cols”, 4),
) data.setdefault(“content_modifiers”, {}) data[“content_modifiers”].setdefault(“add_table”, {}) data[“content_modifiers”][“add_table”].setdefault(counter, [])
- for row in table.rows:
- for cell in row.cells:
text = provider.generator.paragraph() cell.text = text data[“content_modifiers”][“add_table”][counter].append(
text
) data[“content”] += (”
“ + text)
- def add_picture(provider, document, data, counter, **kwargs):
- jpeg_file = JpegFileProvider(provider.generator).jpeg_file(
raw=True
) picture = document.add_picture(BytesIO(jpeg_file))
data.setdefault(“content_modifiers”, {}) data[“content_modifiers”].setdefault(“add_picture”, {}) data[“content_modifiers”][“add_picture”].setdefault(counter, [])
- data[“content_modifiers”][“add_picture”][counter].append(
jpeg_file.data[“content”]
) data[“content”] += (”
“ + jpeg_file.data[“content”])
- file = DocxFileProvider(Faker()).docx_file(
content=DynamicTemplate([(add_table, {}), (add_picture, {})])
)
- docx_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[Union[str, DynamicTemplate]] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- docx_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[Union[str, DynamicTemplate]] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate a DOCX file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
max_nb_chars – Max number of chars for the content.
wrap_chars_after – If given, the output string would be separated by line breaks after the given position.
content – File content. Might contain dynamic elements (still being a string), which are then replaced by correspondent fixtures. Can alternatively be a DynamicTemplate - list of content modifiers (callables to call after the document instance has been created). Each callable should accept the following arguments: provider, document, data, counter and **kwargs.
format_func – Callable responsible for formatting template strings.
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 = 'docx'¶
faker_file.providers.eml_file module¶
- class faker_file.providers.eml_file.EmlFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
EML file provider.
Usage example:
from faker import Faker from faker_file.providers.eml_file import EmlFileProvider
FAKER = Faker()
file = EmlFileProvider(FAKER).eml_file()
Usage example with attachments:
from faker_file.providers.helpers.inner import create_inner_docx_file from faker_file.providers.eml_file import EmlFileProvider
- file = EmlFileProvider(FAKER).eml_file(
prefix=”zzz_email_”, options={
“count”: 5, “create_inner_file_func”: create_inner_docx_file, “create_inner_file_args”: {
“prefix”: “zzz_docx_file_”, “max_nb_chars”: 1_024,
},
}
)
Usage example of nested EMLs attachments:
from faker_file.providers.helpers.inner import create_inner_eml_file
- file = EmlFileProvider(FAKER).eml_file(
- options={
“create_inner_file_func”: create_inner_eml_file, “create_inner_file_args”: {
- “options”: {
“create_inner_file_func”: create_inner_docx_file,
}
}
}
)
If you want to see, which files were included inside the EML, check the
file.data["files"]
.- eml_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, options: Optional[Dict[str, Any]] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, subject: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- eml_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, options: Optional[Dict[str, Any]] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, subject: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate an EML file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
options – Options (non-structured) for complex types, such as ZIP.
max_nb_chars – Max number of chars for the content.
wrap_chars_after – If given, the output string would be separated by line breaks after the given position.
content – File content. Might contain dynamic elements, which are then replaced by correspondent fixtures.
subject – Email subject. Might contain dynamic elements, which are then replaced by correspondent fixtures.
format_func – Callable responsible for formatting template strings.
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 = 'eml'¶
faker_file.providers.epub_file module¶
- class faker_file.providers.epub_file.EpubFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
EPUB file provider.
Usage example:
from faker import Faker from faker_file.providers.epub_file import EpubFileProvider
file = EpubFileProvider(Faker()).epub_file()
Usage example with options:
- file = EpubFileProvider(Faker()).epub_file(
prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = EpubFileProvider(Faker()).epub_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
- epub_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, title: Optional[str] = None, chapter_title: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- epub_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, title: Optional[str] = None, chapter_title: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate a EPUB file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
max_nb_chars – Max number of chars for the content.
wrap_chars_after – If given, the output string would be separated by line breaks after the given position.
content – File content. Might contain dynamic elements, which are then replaced by correspondent fixtures.
title – E-book title. Might contain dynamic elements, which are then replaced by correspondent fixtures.
chapter_title – Chapter title. Might contain dynamic elements, which are then replaced by correspondent fixtures.
format_func – Callable responsible for formatting template strings.
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 = 'epub'¶
faker_file.providers.file_from_path module¶
- class faker_file.providers.file_from_path.FileFromPathProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
File from given path provider.
Usage example:
- from faker_file.providers.file_from_path import (
FileFromPathProvider,
)
- file = FileFromPathProvider(None).file_from_path(
path=”/path/to/file.pdf”,
)
Usage example with options:
- from faker_file.providers.file_from_path import (
FileFromPathProvider,
)
- file = FileFromPathProvider(None).file_from_path(
path=”/path/to/file.pdf”, prefix=”zzz”,
)
- extension: str = ''¶
- file_from_path(path: str, storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, raw: bool = True, **kwargs) BytesValue [source]¶
- file_from_path(path: str, storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, **kwargs) StringValue
File from given path.
- Parameters:
path – Path to source file.
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
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.
faker_file.providers.generic_file module¶
- class faker_file.providers.generic_file.GenericFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
Generic file provider.
Usage example:
from faker import Faker from faker_file.providers.generic_file import GenericFileProvider
- file = GenericFileProvider(Faker()).generic_file(
content=”<html><body><p>{{text}}</p></body></html>”, extension=”html”,
)
Usage example with options:
- file = GenericFileProvider(Faker()).generic_file(
content=”<html><body><p>{{text}}</p></body></html>”, extension=”html”, prefix=”zzz”,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = GenericFileProvider(Faker()).generic_file(
content=”<html><body><p>{{text}}</p></body></html>”, extension=”html”, basename=”index”, storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
),
)
Usage example with AWS S3 storage:
from faker_file.storages.aws_s3 import AWSS3Storage
- file = GenericFileProvider(Faker()).generic_file(
storage=AWSS3Storage(bucket_name=”My-test-bucket”), content=”<html><body><p>{{text}}</p></body></html>”, extension=”html”,
)
- extension: str = None¶
- generic_file(content: Union[bytes, str], extension: str, storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- generic_file(content: Union[bytes, str], extension: str, storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate a generic file with given content.
- Parameters:
content – File content. If given, used as is.
extension – File extension.
storage – Storage class. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
format_func – Callable responsible for formatting template strings.
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.
faker_file.providers.ico_file module¶
- class faker_file.providers.ico_file.IcoFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,ImageMixin
ICO file provider.
Usage example:
from faker import Faker from faker_file.providers.png_file import IcoFileProvider
file = IcoFileProvider(Faker()).ico_file()
Usage example with options:
- file = IcoFileProvider(Faker()).ico_file(
prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = IcoFileProvider(Faker()).ico_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
- extension: str = 'ico'¶
- ico_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_IMAGE_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- ico_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_IMAGE_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate an ICO file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
max_nb_chars – Max number of chars for the content.
wrap_chars_after – If given, the output string would be separated by line breaks after the given position.
content – File content. Might contain dynamic elements, which are then replaced by correspondent fixtures.
format_func – Callable responsible for formatting template strings.
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.
faker_file.providers.jpeg_file module¶
- class faker_file.providers.jpeg_file.JpegFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,ImageMixin
JPEG file provider.
Usage example:
from faker import Faker from faker_file.providers.jpeg_file import JpegFileProvider
file = JpegFileProvider(None).jpeg_file()
Usage example with options:
- file = JpegFileProvider(None).jpeg_file(
prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = JpegFileProvider(Faker()).jpeg_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
- extension: str = 'jpg'¶
- jpeg_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_IMAGE_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- jpeg_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_IMAGE_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate a JPEG file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
max_nb_chars – Max number of chars for the content.
wrap_chars_after – If given, the output string would be separated by line breaks after the given position.
content – File content. Might contain dynamic elements, which are then replaced by correspondent fixtures.
format_func – Callable responsible for formatting template strings.
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.
faker_file.providers.odp_file module¶
- class faker_file.providers.odp_file.OdpFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
ODP file provider.
Usage example:
from faker import Faker from faker_file.providers.odp_file import OdpFileProvider
FAKER = Faker()
file = OdpFileProvider(FAKER).odp_file()
Usage example with options:
- file = OdpFileProvider(FAKER).odp_file(
prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = OdpFileProvider(FAKER).odp_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
- extension: str = 'odp'¶
- odp_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- odp_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate an ODP file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
max_nb_chars – Max number of chars for the content.
wrap_chars_after – If given, the output string would be separated by line breaks after the given position.
content – File content. Might contain dynamic elements, which are then replaced by correspondent fixtures.
format_func – Callable responsible for formatting template strings.
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.
faker_file.providers.ods_file module¶
- class faker_file.providers.ods_file.OdsFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,TabularDataMixin
ODS file provider.
Usage example:
from faker import Faker from faker_file.providers.ods_file import OdsFileProvider
file = OdsFileProvider(Faker()).ods_file()
Usage example with options:
from faker import Faker from faker_file.providers.ods_file import OdsFileProvider
- file = OdsFileProvider(Faker()).ods_file(
prefix=”zzz”, num_rows=100, data_columns={
“name”: “{{name}}”, “residency”: “{{address}}”,
}, include_row_ids=True,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = OdsFileProvider(Faker()).ods_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, num_rows=100, data_columns={
“name”: “{{name}}”, “residency”: “{{address}}”,
}, include_row_ids=True,
)
- extension: str = 'ods'¶
- ods_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, data_columns: Optional[Dict[str, str]] = None, num_rows: int = 10, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- ods_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, data_columns: Optional[Dict[str, str]] = None, num_rows: int = 10, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate an ODS file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
data_columns – The
data_columns
argument expects a list or a tuple of string tokens, and these string tokens will be passed topystr_format()
for data generation. Argument Groups are used to pass arguments to the provider methods. Bothheader
anddata_columns
must be of the same length.num_rows – The
num_rows
argument controls how many rows of data to generate, and theinclude_row_ids
argument may be set toTrue
to include a sequential row ID column.content – List of dicts with content (JSON-like format). If given, used as is.
format_func – Callable responsible for formatting template strings.
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.
faker_file.providers.odt_file module¶
- class faker_file.providers.odt_file.OdtFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
ODT file provider.
Usage example:
from faker import Faker from faker_file.providers.odt_file import OdtFileProvider
FAKER = Faker()
file = OdtFileProvider(FAKER).odt_file()
Usage example with options:
- file = OdtFileProvider(FAKER).odt_file(
prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = OdtFileProvider(FAKER).odt_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
Usage example with content modifiers:
from faker_file.base import DynamicTemplate from faker_file.providers.jpeg_file import JpegFileProvider from odf.draw import Frame, Image from odf.style import (
Style, TextProperties, TableColumnProperties, TableRowProperties, TableCellProperties, GraphicProperties,
) from odf.table import Table, TableRow, TableCell, TableColumn from odf.text import P
- def add_table(provider, document, data, counter, **kwargs):
table = Table() rows = kwargs.get(“rows”, 3) cols = kwargs.get(“cols”, 4) table_col_style = Style(name=”TableColumn”, family=”table-column”) table_col_style.addElement(
TableColumnProperties(columnwidth=”2cm”)
) document.automaticstyles.addElement(table_col_style)
table_row_style = Style(name=”TableRow”, family=”table-row”) table_row_style.addElement(TableRowProperties(rowheight=”1cm”)) document.automaticstyles.addElement(table_row_style)
data.setdefault(“content_modifiers”, {}) data[“content_modifiers”].setdefault(“add_table”, {}) data[“content_modifiers”][“add_table”].setdefault(counter, [])
table_cell_style = Style(name=”TableCell”, family=”table-cell”) table_cell_style.addElement(
- TableCellProperties(
padding=”0.1cm”, border=”0.05cm solid #000000”
)
) document.automaticstyles.addElement(table_cell_style)
# Create table table = Table() for i in range(rows):
table.addElement(TableColumn(stylename=table_col_style))
- for row in range(cols):
tr = TableRow(stylename=table_row_style) table.addElement(tr) for col in range(4):
tc = TableCell(stylename=table_cell_style) tr.addElement(tc) text = provider.generator.paragraph() p = P(text=text) tc.addElement(p) data[“content_modifiers”][“add_table”][counter].append(text) data[“content”] += “
“ + text
document.text.addElement(table)
- def add_picture(
provider, document, data, counter, width=”10cm”, height=”5cm”, **kwargs,
- ):
paragraph = P() document.text.addElement(paragraph) jpeg_file = JpegFileProvider(provider.generator).jpeg_file() image_data = jpeg_file.data[“content”] image_frame = Frame(
width=width, height=height, x=”56pt”, y=”56pt”, anchortype=”paragraph”,
) href = document.addPicture(jpeg_file.data[“filename”]) image_frame.addElement(Image(href=href)) paragraph.addElement(image_frame)
data[“content”] += “
- “ + jpeg_file.data[“content”]
data.setdefault(“content_modifiers”, {}) data[“content_modifiers”].setdefault(“add_picture”, {}) data[“content_modifiers”][“add_picture”].setdefault(counter, [])
- data[“content_modifiers”][“add_picture”][counter].append(
jpeg_file.data[“content”]
)
- file = OdtFileProvider(FAKER).odt_file(
content=DynamicTemplate([(add_table, {}), (add_picture, {})])
)
- extension: str = 'odt'¶
- odt_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[Union[str, DynamicTemplate]] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- odt_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[Union[str, DynamicTemplate]] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate an ODT file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
max_nb_chars – Max number of chars for the content.
wrap_chars_after – If given, the output string would be separated by line breaks after the given position.
content – File content. Might contain dynamic elements, which are then replaced by correspondent fixtures.
format_func – Callable responsible for formatting template strings.
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.
faker_file.providers.png_file module¶
- class faker_file.providers.png_file.PngFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,ImageMixin
PNG file provider.
Usage example:
from faker import Faker from faker_file.providers.png_file import PngFileProvider
file = PngFileProvider(Faker()).png_file()
Usage example with options:
- file = PngFileProvider(Faker()).png_file(
prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = PngFileProvider(Faker()).png_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
- extension: str = 'png'¶
- png_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_IMAGE_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- png_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_IMAGE_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate a PNG file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
max_nb_chars – Max number of chars for the content.
wrap_chars_after – If given, the output string would be separated by line breaks after the given position.
content – File content. Might contain dynamic elements, which are then replaced by correspondent fixtures.
format_func – Callable responsible for formatting template strings.
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.
faker_file.providers.pptx_file module¶
- class faker_file.providers.pptx_file.PptxFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
PPTX file provider.
Usage example:
from faker_file.providers.pptx_file import PptxFileProvider
file = PptxFileProvider(None).pptx_file()
Usage example with options:
from faker_file.providers.pptx_file import PptxFileProvider
- file = PptxFileProvider(None).pptx_file(
prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = PptxFileProvider(Faker()).pptx_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
- extension: str = 'pptx'¶
- pptx_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- pptx_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate a file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
max_nb_chars – Max number of chars for the content.
wrap_chars_after – If given, the output string would be separated by line breaks after the given position.
content – File content. Might contain dynamic elements, which are then replaced by correspondent fixtures.
format_func – Callable responsible for formatting template strings.
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.
faker_file.providers.random_file_from_dir module¶
- class faker_file.providers.random_file_from_dir.RandomFileFromDirProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
Random file from given directory provider.
Usage example:
- from faker_file.providers.random_file_from_dir import (
RandomFileFromDirProvider,
)
- file = RandomFileFromDirProvider(None).random_file_from_dir(
source_dir_path=”/tmp/tmp/”,
)
Usage example with options:
- from faker_file.providers.random_file_from_dir import (
RandomFileFromDirProvider,
)
- file = RandomFileFromDirProvider(None).random_file_from_dir(
source_dir_path=”/tmp/tmp/”, prefix=”zzz”,
)
- extension: str = ''¶
- random_file_from_dir(source_dir_path: str, storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, raw: bool = True, **kwargs) BytesValue [source]¶
- random_file_from_dir(source_dir_path: str, storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, **kwargs) StringValue
Pick a random file from given directory.
- Parameters:
source_dir_path – Source files directory.
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
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.
faker_file.providers.rtf_file module¶
- class faker_file.providers.rtf_file.RtfFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
RTF file provider.
Usage example:
from faker_file.providers.rtf_file import RtfFileProvider
file = RtfFileProvider(None).rtf_file()
Usage example with options:
from faker_file.providers.rtf_file import RtfFileProvider
- file = RtfFileProvider(None).rtf_file(
prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = RtfFileProvider(Faker()).rtf_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
- extension: str = 'rtf'¶
- rtf_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- rtf_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate a RTF file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
max_nb_chars – Max number of chars for the content.
wrap_chars_after – If given, the output string would be separated by line breaks after the given position.
content – File content. Might contain dynamic elements, which are then replaced by correspondent fixtures.
format_func – Callable responsible for formatting template strings.
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.
faker_file.providers.svg_file module¶
- class faker_file.providers.svg_file.SvgFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,ImageMixin
SVG file provider.
Usage example:
from faker import Faker from faker_file.providers.svg_file import SvgFileProvider
file = SvgFileProvider(Faker()).svg_file()
Usage example with options:
- file = SvgFileProvider(Faker()).svg_file(
prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = SvgFileProvider(Faker()).svg_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
- extension: str = 'svg'¶
- svg_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_IMAGE_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- svg_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_IMAGE_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate an SVG file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
max_nb_chars – Max number of chars for the content.
wrap_chars_after – If given, the output string would be separated by line breaks after the given position.
content – File content. Might contain dynamic elements, which are then replaced by correspondent fixtures.
format_func – Callable responsible for formatting template strings.
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.
faker_file.providers.tar_file module¶
- class faker_file.providers.tar_file.TarFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
TAR file provider.
Usage example:
from faker import Faker from faker_file.providers.tar_file import TarFileProvider
FAKER = Faker()
file = TarFileProvider(FAKER).tar_file()
Usage example with options:
from faker_file.providers.helpers.inner import create_inner_docx_file from faker_file.providers.tar_file import TarFileProvider
- file = TarFileProvider(FAKER).tar_file(
prefix=”ttt_archive_”, options={
“count”: 5, “create_inner_file_func”: create_inner_docx_file, “create_inner_file_args”: {
“prefix”: “ttt_docx_file_”, “max_nb_chars”: 1_024,
}, “directory”: “ttt”,
},
)
Usage example of nested TARs:
from faker_file.providers.helpers.inner import create_inner_tar_file
- file = TarFileProvider(FAKER).tar_file(
- options={
“create_inner_file_func”: create_inner_tar_file, “create_inner_file_args”: {
- “options”: {
“create_inner_file_func”: create_inner_docx_file,
}
}
},
)
If you want to see, which files were included inside the TAR, check the
file.data["files"]
.- extension: str = 'tar'¶
- tar_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, options: Optional[Dict[str, Any]] = None, compression: Optional[str] = None, raw: bool = True, **kwargs) BytesValue [source]¶
- tar_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, options: Optional[Dict[str, Any]] = None, compression: Optional[str] = None, **kwargs) StringValue
Generate a TAR file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
options – Options (non-structured) for complex types, such as ZIP.
compression – Desired compression. Can be None or gz, bz2 or xz.
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.
faker_file.providers.txt_file module¶
- class faker_file.providers.txt_file.TxtFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
TXT file provider.
Usage example:
from faker import Faker from faker_file.providers.txt_file import TxtFileProvider
file = TxtFileProvider(Faker()).txt_file()
Usage example with options:
- file = TxtFileProvider(Faker()).txt_file(
prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = TxtFileProvider(Faker()).txt_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
- extension: str = 'txt'¶
- txt_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- txt_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_TEXT_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate a TXT file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
max_nb_chars – Max number of chars for the content.
wrap_chars_after – If given, the output string would be separated by line breaks after the given position.
content – File content. Might contain dynamic elements, which are then replaced by correspondent fixtures.
format_func – Callable responsible for formatting template strings.
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.
faker_file.providers.webp_file module¶
- class faker_file.providers.webp_file.WebpFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,ImageMixin
WEBP file provider.
Usage example:
from faker import Faker from faker_file.providers.webp_file import WebpFileProvider
file = WebpFileProvider(Faker()).webp_file()
Usage example with options:
- file = WebpFileProvider(Faker()).webp_file(
prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = WebpFileProvider(Faker()).webp_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, max_nb_chars=100_000, wrap_chars_after=80,
)
- extension: str = 'webp'¶
- webp_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_IMAGE_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- webp_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, max_nb_chars: int = DEFAULT_IMAGE_MAX_NB_CHARS, wrap_chars_after: Optional[int] = None, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate a WEBP file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
max_nb_chars – Max number of chars for the content.
wrap_chars_after – If given, the output string would be separated by line breaks after the given position.
content – File content. Might contain dynamic elements, which are then replaced by correspondent fixtures.
format_func – Callable responsible for formatting template strings.
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.
faker_file.providers.xlsx_file module¶
- class faker_file.providers.xlsx_file.XlsxFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,TabularDataMixin
XLSX file provider.
Usage example:
from faker import Faker from faker_file.providers.xlsx_file import XlsxFileProvider
file = XlsxFileProvider(Faker()).xlsx_file()
Usage example with options:
from faker import Faker from faker_file.providers.xlsx_file import XlsxFileProvider
- file = XlsxFileProvider(Faker()).xlsx_file(
prefix=”zzz”, num_rows=100, data_columns={
“name”: “{{name}}”, “residency”: “{{address}}”,
}, include_row_ids=True,
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = XlsxFileProvider(Faker()).xlsx_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, num_rows=100, data_columns={
“name”: “{{name}}”, “residency”: “{{address}}”,
}, include_row_ids=True,
)
- extension: str = 'xlsx'¶
- xlsx_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, data_columns: Optional[Dict[str, str]] = None, num_rows: int = 10, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- xlsx_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, data_columns: Optional[Dict[str, str]] = None, num_rows: int = 10, content: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate a XLSX file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
data_columns – The
data_columns
argument expects a list or a tuple of string tokens, and these string tokens will be passed topystr_format()
for data generation. Argument Groups are used to pass arguments to the provider methods. Bothheader
anddata_columns
must be of the same length.num_rows – The
num_rows
argument controls how many rows of data to generate, and theinclude_row_ids
argument may be set toTrue
to include a sequential row ID column.content – List of dicts with content (JSON-like format). If given, used as is.
format_func – Callable responsible for formatting template strings.
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.
faker_file.providers.xml_file module¶
- class faker_file.providers.xml_file.XmlFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
XML file provider.
Usage example:
from faker import Faker from faker_file.providers.xml_file import XmlFileProvider
file = XmlFileProvider(Faker()).xml_file()
Usage example with options:
from faker_file.providers.xml_file import XmlFileProvider
- file = XmlFileProvider(Faker()).xml_file(
prefix=”zzz”, num_rows=100, data_columns={
“name”: “{{name}}”, “sentence”: “{{sentence}}”, “address”: “{{address}}”,
},
)
Usage example with FileSystemStorage storage (for Django):
from django.conf import settings from faker_file.storages.filesystem import FileSystemStorage
- file = XmlFileProvider(Faker()).xml_file(
- storage=FileSystemStorage(
root_path=settings.MEDIA_ROOT, rel_path=”tmp”,
), prefix=”zzz”, num_rows=100,
)
Usage example with template:
XML_TEMPLATE = ‘’’ <books>
- <book>
<name>{{sentence}}</name> <description>{{paragraph}}</description> <isbn>{{isbn13}}</isbn>
</book> <book>
<name>{{sentence}}</name> <description>{{paragraph}}</description> <isbn>{{isbn13}}</isbn>
</book> <book>
<name>{{sentence}}</name> <description>{{paragraph}}</description> <isbn>{{isbn13}}</isbn>
</book>
</books> ‘’’
file = XmlFileProvider(Faker()).xml_file(content=XML_TEMPLATE)
- extension: str = 'xml'¶
- xml_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, root_element: str = 'root', row_element: str = 'row', data_columns: Optional[Dict[str, str]] = None, num_rows: int = 10, content: Optional[str] = None, encoding: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, raw: bool = True, **kwargs) BytesValue [source]¶
- xml_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, root_element: str = 'root', row_element: str = 'row', data_columns: Optional[Dict[str, str]] = None, num_rows: int = 10, content: Optional[str] = None, encoding: Optional[str] = None, format_func: Callable[[Union[Faker, Generator, Provider], str], str] = DEFAULT_FORMAT_FUNC, **kwargs) StringValue
Generate an XML file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
root_element – Root XML element.
row_element – Row XML element.
data_columns – The
data_columns
argument expects a list or a tuple of string tokens, and these string tokens will be passed topystr_format()
for data generation. Argument Groups are used to pass arguments to the provider methods. Bothheader
anddata_columns
must be of the same length.num_rows – The
num_rows
argument controls how many rows of data to generate, and theinclude_row_ids
argument may be set toTrue
to include a sequential row ID column.content – File content. Might contain dynamic elements, which are then replaced by correspondent fixtures.
encoding – Encoding.
format_func – Callable responsible for formatting template strings.
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.
faker_file.providers.zip_file module¶
- class faker_file.providers.zip_file.ZipFileProvider(generator: Any)[source]¶
Bases:
BaseProvider
,FileMixin
ZIP file provider.
Usage example:
from faker import Faker from faker_file.providers.zip_file import ZipFileProvider
FAKER = Faker()
file = ZipFileProvider(FAKER).zip_file()
Usage example with options:
from faker_file.providers.helpers.inner import create_inner_docx_file from faker_file.providers.zip_file import ZipFileProvider
- file = ZipFileProvider(FAKER).zip_file(
prefix=”zzz_archive_”, options={
“count”: 5, “create_inner_file_func”: create_inner_docx_file, “create_inner_file_args”: {
“prefix”: “zzz_docx_file_”, “max_nb_chars”: 1_024,
}, “directory”: “zzz”,
},
)
Usage example of nested ZIPs:
from faker_file.providers.helpers.inner import create_inner_zip_file
- file = ZipFileProvider(FAKER).zip_file(
- options={
“create_inner_file_func”: create_inner_zip_file, “create_inner_file_args”: {
- “options”: {
“create_inner_file_func”: create_inner_docx_file,
},
},
},
)
If you want to see, which files were included inside the ZIP, check the
file.data["files"]
.- extension: str = 'zip'¶
- zip_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, options: Optional[Dict[str, Any]] = None, raw: bool = True, **kwargs) BytesValue [source]¶
- zip_file(storage: Optional[BaseStorage] = None, basename: Optional[str] = None, prefix: Optional[str] = None, options: Optional[Dict[str, Any]] = None, **kwargs) Union[BytesValue, StringValue]
Generate a ZIP file with random text.
- Parameters:
storage – Storage. Defaults to FileSystemStorage.
basename – File basename (without extension).
prefix – File name prefix.
options – Options (non-structured) for complex types, such as ZIP.
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.