> Every page of the ganymede website is listed in https://eugo.io/docs/ganymede/llms.txt.

# Faker File

> Faker File: Work with fake file data. A Python demo notebook from ganymede.

Web page: https://eugo.io/docs/ganymede/demo_notebooks/testing/faker/faker_file/
Notebook: https://eugo.io/docs/ganymede/demo_notebooks/testing/faker/faker_file/faker_file.ipynb (source: https://github.com/eugo-inc/ganymede/blob/main/demo_notebooks/testing/faker/faker_file.ipynb)

Description:
- Work with fake file data

Resources:
- https://github.com/barseghyanartur/faker-file/
- https://faker-file.readthedocs.io/en/latest/
- https://faker-file.readthedocs.io/en/latest/recipes.html
- https://github.com/barseghyanartur/faker-file-api
- https://github.com/barseghyanartur/faker-file/tree/main/examples

## Environment variables

This notebook reads these environment variables. Set them before you start Jupyter:

- `SFTP_HOST`: host name of an SFTP server you can write to.
- `SFTP_PORT`: SFTP port (optional, defaults to 22).
- `SFTP_USERNAME`: SFTP user name.
- `SFTP_PASSWORD`: SFTP password.

Only Example 22 (SFTPStorage) needs these; skip that cell otherwise.

## Example 1: TxtFileProvider (Text Files)

Create a text file with fake data

```python
from faker import Faker
from faker_file.providers.txt_file import TxtFileProvider

faker = Faker()
faker.add_provider(TxtFileProvider)

# Usage example
txt_file = faker.txt_file(content="Lorem ipsum")

print(txt_file.data["filename"])
# The following line would produce a text generated by Faker, used as
# the content of the generated txt_file.
print(txt_file.data["content"])
```

## Example 2: DocxFileProvider (DocX Files)

Create a docx file with fake data

```python
from faker import Faker
from faker_file import providers
from faker_file.providers.docx_file import DocxFileProvider

faker = Faker()
faker.add_provider(DocxFileProvider)

docx_file = faker.docx_file(
    prefix="zzz",
    max_nb_chars=1_024,
    wrap_chars_after=80,
)
print(docx_file.data["filename"])
```

## Example 3: ZipFileProvider (Zip Files)

Create a zip file with fake data

```python
from faker import Faker
from faker_file.providers.zip_file import ZipFileProvider
from faker_file.providers.helpers.inner import create_inner_zip_file, create_inner_docx_file

faker = Faker()
faker.add_provider(ZipFileProvider)

zip_file = faker.zip_file(
    options={"create_inner_file_args": {"content": "Lorem ipsum"}}
)
print(zip_file.data["filename"])

zip_inner_file = faker.zip_file(
    prefix="nested_level_0_",
    options={
        "create_inner_file_func": create_inner_zip_file,
        "create_inner_file_args": {
            "prefix": "nested_level_1_",
            "options": {
                "create_inner_file_func": create_inner_zip_file,
                "create_inner_file_args": {
                    "prefix": "nested_level_2_",
                    "options": {
                        "count": 2,
                        "create_inner_file_func": create_inner_docx_file,
                        "create_inner_file_args": {
                            "content": "HELLO" + "\n\n{{date}}",
                        }
                    }
                },
            }
        },
    }
)

print(zip_inner_file.data["filename"])
```

## Example 4: BinFileProvider (Bin Files)

Import the bin file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(BinFileProvider)`) and call `faker.bin_file()`.

```python
from faker_file.providers.bin_file import BinFileProvider
```

## Example 5: CsvFileProvider (CSV Files)

Import the CSV file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(CsvFileProvider)`) and call `faker.csv_file()`.

```python
from faker_file.providers.csv_file import CsvFileProvider
```

## Example 6: EmlFileProvider (EML Files)

Import the EML file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(EmlFileProvider)`) and call `faker.eml_file()`.

```python
from faker_file.providers.eml_file import EmlFileProvider
```

## Example 7: EpubFileProvider (Epub Files)

Import the EPUB file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(EpubFileProvider)`) and call `faker.epub_file()`.

```python
from faker_file.providers.epub_file import EpubFileProvider
```

## Example 8: IcoFileProvider (Ico Files)

Import the ICO file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(IcoFileProvider)`) and call `faker.ico_file()`.

```python
from faker_file.providers.ico_file import IcoFileProvider
```

## Example 9: JpegFileProvider (Jpeg Files)

Import the JPEG file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(JpegFileProvider)`) and call `faker.jpeg_file()`.

```python
from faker_file.providers.jpeg_file import JpegFileProvider
```

## Example 10: Mp3FileProvider (Mp3 Files)

Import the MP3 file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(Mp3FileProvider)`) and call `faker.mp3_file()`.

```python
from faker_file.providers.mp3_file import Mp3FileProvider
```

## Example 11: OdsFileProvider (Ods Files)

Import the ODS file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(OdsFileProvider)`) and call `faker.ods_file()`.

```python
from faker_file.providers.ods_file import OdsFileProvider
```

## Example 12: OdtFileProvider (Odt Files)

Import the ODT file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(OdtFileProvider)`) and call `faker.odt_file()`.

```python
from faker_file.providers.odt_file import OdtFileProvider
```

## Example 13: PdfFileProvider (PDF Files)

Import the PDF file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(PdfFileProvider)`) and call `faker.pdf_file()`.

```python
from faker_file.providers.pdf_file import PdfFileProvider
```

## Example 14: PngFileProvider (PNG Files)

Import the PNG file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(PngFileProvider)`) and call `faker.png_file()`.

```python
from faker_file.providers.png_file import PngFileProvider
```

## Example 15: PptxFileProvider (PPTX Files)

Import the PPTX file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(PptxFileProvider)`) and call `faker.pptx_file()`.

```python
from faker_file.providers.pptx_file import PptxFileProvider
```

## Example 16: RtfFileProvider (RTF Files)

Import the RTF file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(RtfFileProvider)`) and call `faker.rtf_file()`.

```python
from faker_file.providers.rtf_file import RtfFileProvider
```

## Example 17: SvgFileProvider (SVG Files)

Import the SVG file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(SvgFileProvider)`) and call `faker.svg_file()`.

```python
from faker_file.providers.svg_file import SvgFileProvider
```

## Example 18: WebpFileProvider (WEBP Files)

Import the WEBP file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(WebpFileProvider)`) and call `faker.webp_file()`.

```python
from faker_file.providers.webp_file import WebpFileProvider
```

## Example 19: XlsxFileProvider (xlsx Files)

Import the XLSX file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(XlsxFileProvider)`) and call `faker.xlsx_file()`.

```python
from faker_file.providers.xlsx_file import XlsxFileProvider
```

## Example 20: GoogleCloudStorage (Google Cloud Files)

Import the Google Cloud Storage backend. Pass an instance as `storage=` to any provider method to write the file to a bucket instead of the local disk.

```python
from faker_file.storages.google_cloud_storage import GoogleCloudStorage
```

## Example 21: AWSS3Storage (S3 Files)

Import the AWS S3 storage backend. Pass an instance as `storage=` to any provider method to write the file to a bucket instead of the local disk.

```python
from faker_file.storages.aws_s3 import AWSS3Storage
```

## Example 22: SFTPStorage (sftp Files)

Create a sftp file with fake data

```python
import os
from faker import Faker
from faker_file.providers.txt_file import TxtFileProvider
from faker_file.storages.sftp_storage import SFTPStorage

SFTP_STORAGE = SFTPStorage(
    host=os.environ["SFTP_HOST"],
    port=int(os.environ.get("SFTP_PORT", "22")),
    username=os.environ["SFTP_USERNAME"],
    password=os.environ["SFTP_PASSWORD"],
    root_path="/dir-name",  # an existing directory on the server
)

faker = Faker()
faker.add_provider(TxtFileProvider)

txt_file = faker.txt_file(storage=SFTP_STORAGE)
print(txt_file.data["filename"])
```

## Example 23: FileSystemStorage

Import the local file-system storage backend (the default storage of every provider). Pass an instance as `storage=` to choose where files are written.

```python
from faker_file.storages.filesystem import FileSystemStorage
```

## Example 24: GenericFileProvider

Import the generic file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(GenericFileProvider)`) and call `faker.generic_file()`.

```python
from faker_file.providers.generic_file import GenericFileProvider
```

## Example 25: GraphicIcoFileProvider

Import the graphic ICO file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(GraphicIcoFileProvider)`) and call `faker.graphic_ico_file()`.

```python
from faker_file.providers.ico_file import GraphicIcoFileProvider
```

## Example 26: GraphicJpegFileProvider

Import the graphic JPEG file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(GraphicJpegFileProvider)`) and call `faker.graphic_jpeg_file()`.

```python
from faker_file.providers.jpeg_file import GraphicJpegFileProvider
```

## Example 27: GraphicPngFileProvider

Import the graphic PNG file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(GraphicPngFileProvider)`) and call `faker.graphic_png_file()`.

```python
from faker_file.providers.png_file import GraphicPngFileProvider
```

## Example 28: GraphicWebpFileProvider

Import the graphic WEBP file provider. To create a file, add it as in Examples 1-3 (`faker.add_provider(GraphicWebpFileProvider)`) and call `faker.graphic_webp_file()`.

```python
from faker_file.providers.webp_file import GraphicWebpFileProvider
```

## Example 29: GttsMp3Generator

Import the gTTS MP3 generator. Use it with `faker.mp3_file(mp3_generator_cls=GttsMp3Generator)`.

```python
from faker_file.providers.mp3_file.generators.gtts_generator import (
    GttsMp3Generator,
)
```

## Example 30: BaseMp3Generator

Import the base class for writing your own MP3 generator.

```python
from faker_file.providers.base.mp3_generator import BaseMp3Generator
```

## Example 31: EdgeTtsMp3Generator

Import the Edge TTS MP3 generator. Use it with `faker.mp3_file(mp3_generator_cls=EdgeTtsMp3Generator)`.

```python
from faker_file.providers.mp3_file.generators.edge_tts_generator import (
    EdgeTtsMp3Generator,
)
```

## Example 32: textaugment_augmenter

Import the TextAugment-based text augmenter, which `AugmentFileFromDirProvider` can use to vary the text of existing files.

```python
from faker_file.providers.augment_file_from_dir.augmenters import (
    textaugment_augmenter,
)
```

## Example 33: nlpaug_augmenter

Import the nlpaug-based text augmenter, which `AugmentFileFromDirProvider` can use to vary the text of existing files.

```python
from faker_file.providers.augment_file_from_dir.augmenters import (
    nlpaug_augmenter,
)
```
