faker.providers.file
¶
-
class
faker.providers.file.
Provider
(generator: Any)¶ Bases:
faker.providers.BaseProvider
Implement default file provider for Faker.
-
file_extension
(category: Optional[str] = None) → str¶ Generate a file extension under the specified
category
.If
category
isNone
, a random category will be used. The list of valid categories include:'audio'
,'image'
,'office'
,'text'
, and'video'
.Examples: >>> Faker.seed(0) >>> for _ in range(5): ... fake.file_extension() ... 'js' 'mp3' 'webm' 'html' 'html'
>>> Faker.seed(0) >>> for _ in range(5): ... fake.file_extension(category='image') ... 'jpg' 'jpg' 'bmp' 'jpeg' 'png'
-
file_name
(category: Optional[str] = None, extension: Optional[str] = None) → str¶ Generate a random file name with extension.
If
extension
isNone
, a random extension will be created under the hood usingfile_extension()
with the specifiedcategory
. If a value forextension
is provided, the value will be used instead, andcategory
will be ignored. The actual name part itself is generated usingword()
.Examples: >>> Faker.seed(0) >>> for _ in range(5): ... fake.file_name(category='audio') ... 'son.mp3' 'amount.mp3' 'much.mp3' 'interview.mp3' 'me.mp3'
>>> Faker.seed(0) >>> for _ in range(5): ... fake.file_name(extension='abcdef') ... 'three.abcdef' 'image.abcdef' 'son.abcdef' 'voice.abcdef' 'kitchen.abcdef'
>>> Faker.seed(0) >>> for _ in range(5): ... fake.file_name(category='audio', extension='abcdef') ... 'three.abcdef' 'image.abcdef' 'son.abcdef' 'voice.abcdef' 'kitchen.abcdef'
-
file_path
(depth: int = 1, category: Optional[str] = None, extension: Optional[str] = None, absolute: Optional[bool] = True) → str¶ Generate an pathname to a file.
This method uses
file_name()
under the hood to generate the file name itself, anddepth
controls the depth of the directory path, andword()
is used under the hood to generate the different directory names.If
absolute
isTrue
(default), the generated path starts with/
and is absolute. Otherwise, the generated path is relative.Examples: >>> Faker.seed(0) >>> for _ in range(5): ... fake.file_path(depth=3) ... '/mention/much/event/amount.js' '/wait/past/help/me.html' '/someone/challenge/father/chair.png' '/no/where/enough/successful.wav' '/back/show/bit/force.avi'
>>> Faker.seed(0) >>> for _ in range(5): ... fake.file_path(depth=5, category='video') ... '/much/event/amount/kitchen/voice/son.webm' '/me/floor/themselves/step/why/interview.webm' '/chair/mother/discover/whatever/wait/past.mov' '/enough/successful/present/beyond/someone/challenge.mov' '/to/way/back/show/bit/force.avi'
>>> Faker.seed(0) >>> for _ in range(5): ... fake.file_path(depth=5, category='video', extension='abcdef') ... '/amount/kitchen/voice/son/image/three.abcdef' '/step/why/interview/mention/much/event.abcdef' '/wait/past/help/me/floor/themselves.abcdef' '/challenge/father/chair/mother/discover/whatever.abcdef' '/where/enough/successful/present/beyond/someone.abcdef'
-
mime_type
(category: Optional[str] = None) → str¶ Generate a mime type under the specified
category
.If
category
isNone
, a random category will be used. The list of valid categories include'application'
,'audio'
,'image'
,'message'
,'model'
,'multipart'
,'text'
, and'video'
.Examples: >>> Faker.seed(0) >>> for _ in range(5): ... fake.mime_type() ... 'text/vcard' 'application/pdf' 'video/x-ms-wmv' 'model/vrml' 'multipart/signed'
>>> Faker.seed(0) >>> for _ in range(5): ... fake.mime_type(category='application') ... 'application/soap+xml' 'application/font-woff' 'application/ecmascript' 'application/pdf' 'application/xop+xml'
-
unix_device
(prefix: Optional[str] = None) → str¶ Generate a Unix device file name.
If
prefix
isNone
, a random prefix will be used. The list of valid prefixes include:'sd'
,'vd'
, and'xvd'
.Examples: >>> Faker.seed(0) >>> for _ in range(5): ... fake.unix_device() ... '/dev/vdy' '/dev/vdb' '/dev/vdq' '/dev/vdm' '/dev/vdp'
>>> Faker.seed(0) >>> for _ in range(5): ... fake.unix_device(prefix='mmcblk') ... '/dev/mmcblkm' '/dev/mmcblky' '/dev/mmcblkn' '/dev/mmcblkb' '/dev/mmcblki'
-
unix_partition
(prefix: Optional[str] = None) → str¶ Generate a Unix partition name.
This method uses
unix_device()
under the hood to create a device file name with the specifiedprefix
.Examples: >>> Faker.seed(0) >>> for _ in range(5): ... fake.unix_partition() ... '/dev/vdy6' '/dev/sdi8' '/dev/vdm4' '/dev/vdl9' '/dev/sdq2'
>>> Faker.seed(0) >>> for _ in range(5): ... fake.unix_partition(prefix='mmcblk') ... '/dev/mmcblkm6' '/dev/mmcblkb4' '/dev/mmcblkq7' '/dev/mmcblkm4' '/dev/mmcblkp5'
-