Package: faker-file
Create files with fake data. In many formats. With no efforts.PrerequisitesAll of core dependencies of this package areMITlicensed.
Most of optional dependencies of this package areMITlicensed, while
a few areBSD-,Apache 2-,GPLorHPNDlicensed.All licenses are mentioned below between the brackets.Core package requires Python 3.7, 3.8, 3.9, 3.10 or 3.11.Faker(MIT) is the only required dependency.Django(BSD) integration withfactory_boy(MIT) has
been tested withDjangostarting from version 2.2 to 4.2 (although only
maintained versions of Django are currently being tested against).BMP,GIFandTIFFfile support requires either justPillow(HPND), or a combination ofWeasyPrint(BSD),pdf2image(MIT),Pillow(HPND) andpoppler(GPLv2).DOCXfile support requirespython-docx(MIT).EPUBfile support requiresxml2epub(MIT) andJinja2(BSD).ICO,JPEG,PNG,SVGandWEBPfiles support
requires either justPillow(HPND), or a combination ofimgkit(MIT) andwkhtmltopdf(LGPLv3).MP3file support requiresgTTS(MIT) oredge-tts(GPLv3).PDFfile support requires eitherPillow(HPND), or a combination ofpdfkit(MIT) andwkhtmltopdf(LGPLv3), orreportlab(BSD).PPTXfile support requirespython-pptx(MIT).ODPandODTfile support requiresodfpy(Apache 2).ODSfile support requirestablib(MIT) andodfpy(Apache 2).XLSXfile support requirestablib(MIT) andopenpyxl(MIT).PathyFileSystemStoragestorage support requirespathy(Apache 2).AWSS3Storagestorage support requirespathy(Apache 2)
andboto3(Apache 2).AzureCloudStoragestorage support requirespathy(Apache 2)
andazure-storage-blob(MIT).GoogleCloudStoragestorage support requirespathy(Apache 2)
andgoogle-cloud-storage(Apache 2).SFTPStoragestorage support requiresparamiko(LGLPv2.1).AugmentFileFromDirProviderprovider requires either a combination oftextaugment(MIT) andnltk(Apache 2) or a combination ofnlpaug(MIT),PyTorch(BSD),transformers(Apache 2),numpy(BSD),pandas(BSD),tika(Apache 2) andApache Tika(Apache 2).DocumentationDocumentation is available onRead the Docs.For bootstrapping check theQuick start.For various ready to use code examples see theRecipes.For tips onPDFcreation seeCreating PDF.For tips onDOCXcreation seeCreating DOCX.For tips onODTcreation seeCreating ODT.For tips on images creation seeCreating images.For CLI options see theCLI.Read theMethodology.For guidelines on contributing check theContributor guidelines.Online demos and related projectsCheck the demo(s) and related projects below:REST API demo(based onfaker-file-apiREST API)UI frontend demo(based onfaker-file-uiUI frontend)WASM frontend demo(based onfaker-file-wasmWASM frontend)faker-file-qtGUI application (based onPyQT5).InstallationLatest stable version from PyPIWIth all dependenciespipinstallfaker-file[all]Only corepipinstallfaker-fileWith most common dependenciesEverything, except ML libraries which are required for data augmentation onlypipinstallfaker-file[common]With DOCX supportpipinstallfaker-file[docx]With EPUB supportpipinstallfaker-file[epub]With images supportpipinstallfaker-file[images]With PDF supportpipinstallfaker-file[pdf]With MP3 supportpipinstallfaker-file[mp3]With XLSX supportpipinstallfaker-file[xlsx]With ODS supportpipinstallfaker-file[ods]With ODT supportpipinstallfaker-file[odt]With data augmentation supportpipinstallfaker-file[data-augmentation]With GoogleCloudStorage supportpipinstallfaker-file[gcs]With AzureCloudStorage supportpipinstallfaker-file[azure]With AWSS3Storage supportpipinstallfaker-file[s3]Or development version from GitHubpipinstallhttps://github.com/barseghyanartur/faker-file/archive/main.tar.gzFeaturesSupported file typesBINBMPCSVDOCXEMLEPUBICOGIFJPEGJSONMP3ODSODTODPPDFPNGRTFPPTXSVGTARTIFFTXTWEBPXLSXXMLZIPFor all image formats (BMP,ICO,GIF,JPEG,PNG,SVG,TIFFandWEBP) andPDF, there are both graphic-only and
mixed-content file providers (that also have text-to-image capabilities).Additional providersAugmentFileFromDirProvider: Make an augmented copy of randomly picked
file from given directory. The following types are supported :DOCX,EML,EPUB,ODT,PDF,RTFandTXT.AugmentRandomImageFromDirProvider: Augment a random image file from
given directory. The following types are supported :BMP,GIF,JPEG,PNG,TIFFandWEBP.AugmentImageFromPathProvider: Augment an image file from given path.
Supported file types are the same as forAugmentRandomImageFromDirProviderprovider.GenericFileProvider: Create files in any format from raw bytes or a
predefined template.RandomFileFromDirProvider: Pick a random file from given directory.FileFromPathProvider: File from given path.Supported file storagesNative file system storageAWS S3 storageAzure Cloud StorageGoogle Cloud StorageSFTP storageUsage examplesWithFakerRecommended wayfromfakerimportFaker# Import the file provider we want to usefromfaker_file.providers.txt_fileimportTxtFileProviderFAKER=Faker()# Initialise Faker instanceFAKER.add_provider(TxtFileProvider)# Register the TXT file providerfile=FAKER.txt_file()# Generate a TXT file# Meta-data is stored inside a ``data`` attribute (``dict``).# The following line would produce something like /tmp/tmp/tmphzzb8mot.txtprint(file.data["filename"])# The following line would produce a text generated by Faker, used as# the content of the generated file.print(file.data["content"])NoteNote, that in this casefilevalue is aStringValueinstance,
which inherits fromstrbut contains meta-data such as absolute
path to the generated file, and text used to generate the file, stored
infilenameandcontentkeys of thedataattribute
respectively. SeeMeta-datafor more information.If you just needbytesback (instead of creating the file), provide
theraw=Trueargument (works with all provider classes and inner
functions):fromfakerimportFakerfromfaker_file.providers.txt_fileimportTxtFileProviderFAKER=Faker()FAKER.add_provider(TxtFileProvider)raw=FAKER.txt_file(raw=True)NoteNote, that in this casefilevalue is aBytesValueinstance,
which inherits frombytesbut contains meta-data such as absolute
path to the generated file, and text used to generate the file, stored
infilenameandcontentkeys of thedataattribute
respectively. SeeMeta-datafor more information.But this works toofromfakerimportFakerfromfaker_file.providers.txt_fileimportTxtFileProviderFAKER=Faker()file=TxtFileProvider(FAKER).txt_file()If you just needbytesback:fromfakerimportFakerfromfaker_file.providers.txt_fileimportTxtFileProviderFAKER=Faker()raw=TxtFileProvider(FAKER).txt_file(raw=True)Withfactory_boyupload/models.pyfromdjango.dbimportmodelsclassUpload(models.Model):# ...file=models.FileField()upload/factories.pyNote, that when usingfaker-filewithDjangoand native file system
storages, you need to pass yourMEDIA_ROOTsetting asroot_pathvalue
to the chosen file storage as show below.importfactoryfromdjango.confimportsettingsfromfactoryimportFakerfromfactory.djangoimportDjangoModelFactoryfromfaker_file.providers.docx_fileimportDocxFileProviderfromfaker_file.storages.filesystemimportFileSystemStoragefromupload.modelsimportUploadFS_STORAGE=FileSystemStorage(root_path=settings.MEDIA_ROOT,rel_path="tmp")factory.Faker.add_provider(DocxFileProvider)classUploadFactory(DjangoModelFactory):# ...file=Faker("docx_file",storage=FS_STORAGE)classMeta:model=UploadMeta-dataThe return value of any file provider file generator function is eitherStringValueorBytesValue, which inherit fromstrandbytesrespectively.BothStringValueandBytesValueinstances have a meta data attribute
nameddata(typedict). Various file providers usedatato
store meta-data, such asfilename(absolute path to the generated file;
valid for all file providers), orcontent(text used when generating the
file; valid for most file providers, exceptFileFromPathProvider,RandomFileFromDirProvider,TarFileProviderandZipFileProvider).All file providers store an absolute path to the generated file infilenamekey of thedataattribute and instance of the storage used instoragekey. See the table below.Key nameFile providerfilenameallstorageallcontentall except FileFromPathProvider, RandomFileFromDirProvider,
TarFileProvider, ZipFileProvider and all graphic file providers
such as GraphicBmpFileProvider, GraphicGifFileProvider,
GraphicIcoFileProvider, GraphicJpegFileProvider,
GraphicPdfFileProvider, GraphicPngFileProvider,
GraphicTiffFileProvider and GraphicWebpFileProviderinneronly EmlFileProvider, TarFileProvider and ZipFileProviderFile storagesAll file operations are delegated to a separate abstraction layer of storages.The following storages are implemented:FileSystemStorage: Does not have additional requirements.PathyFileSystemStorage: Requirespathy.AzureCloudStorage: RequirespathyandAzurerelated dependencies.GoogleCloudStorage: RequirespathyandGoogle Cloudrelated
dependencies.AWSS3Storage: RequirespathyandAWS S3related dependencies.SFTPStorage: Requiresparamikoand related dependencies.Usage example with storagesFileSystemStorageexampleNative file system storage. Does not have dependencies.root_path: Path to the root directory. Given the example of Django,
this would be the path to theMEDIA_ROOTdirectory. It’s important
to know, thatroot_pathwill not be embedded into the string
representation of the file. Onlyrel_pathwill.rel_path: Relative path from the root directory. Given the example of
Django, this would be the rest of the path to the file.importtempfilefromfakerimportFakerfromfaker_file.providers.txt_fileimportTxtFileProviderfromfaker_file.storages.filesystemimportFileSystemStorageFS_STORAGE=FileSystemStorage(root_path=tempfile.gettempdir(),# Use settings.MEDIA_ROOT for Djangorel_path="tmp",)FAKER=Faker()file=TxtFileProvider(FAKER).txt_file(storage=FS_STORAGE)FS_STORAGE.exists(file)PathyFileSystemStorageexampleNative file system storage. Requirespathy.importtempfilefrompathyimportuse_fsfromfakerimportFakerfromfaker_file.providers.txt_fileimportTxtFileProviderfromfaker_file.storages.cloudimportPathyFileSystemStorageuse_fs(tempfile.gettempdir())PATHY_FS_STORAGE=PathyFileSystemStorage(bucket_name="bucket_name",root_path="tmp",rel_path="sub-tmp",)FAKER=Faker()file=TxtFileProvider(FAKER).txt_file(storage=PATHY_FS_STORAGE)PATHY_FS_STORAGE.exists(file)AWSS3StorageexampleAWS S3 storage. Requirespathyandboto3.fromfakerimportFakerfromfaker_file.providers.txt_fileimportTxtFileProviderfromfaker_file.storages.aws_s3importAWSS3StorageS3_STORAGE=AWSS3Storage(bucket_name="bucket_name",root_path="tmp",# Optionalrel_path="sub-tmp",# Optional# Credentials are optional too. If your AWS credentials are properly# set in the ~/.aws/credentials, you don't need to send them# explicitly.credentials={"key_id":"YOUR KEY ID","key_secret":"YOUR KEY SECRET"},)FAKER=Faker()file=TxtFileProvider(FAKER).txt_file(storage=S3_STORAGE)S3_STORAGE.exists(file)TestingSimply type:pytest-vrxOr use tox:toxOr use tox to check specific env:tox-epy310-django41Writing documentationKeep the following hierarchy.=====
title
=====

header
======

sub-header
----------

sub-sub-header
~~~~~~~~~~~~~~

sub-sub-sub-header
^^^^^^^^^^^^^^^^^^

sub-sub-sub-sub-header
++++++++++++++++++++++

sub-sub-sub-sub-sub-header
**************************LicenseMITSupportFor security issues contact me at the e-mail given in theAuthorsection.For overall issues, go toGitHub.AuthorArtur Barseghyan <artur.barseghyan@gmail.com>CitationPlease, use the following entry when citingfaker-filein your research:@software{faker-file,
  author ={Artur Barseghyan},
  title ={faker-file: Create files with fake data. In many formats. With no efforts.},
  year ={2023},
  publisher ={GitHub},
  journal ={GitHub repository},
  howpublished ={https://github.com/barseghyanartur/faker-file},}