faker.providers.file

class faker.providers.file.Provider(generator: Any)

Bases: BaseProvider

Implement default file provider for Faker.

file_extension(category: str | None = None) str

Generate a file extension under the specified category.

If category is None, 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: str | None = None, extension: str | None = None) str

Generate a random file name with extension.

If extension is None, a random extension will be created under the hood using file_extension() with the specified category. If a value for extension is provided, the value will be used instead, and category will be ignored. The actual name part itself is generated using word(). If extension is an empty string then no extension will be added, and file_name will be the same as word().

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'
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.file_name(extension='')
...
'three'
'image'
'son'
'voice'
'kitchen'
file_path(depth: int = 1, category: str | None = None, extension: str | Sequence[str] | None = None, absolute: bool | None = True, file_system_rule: Literal['linux', 'windows'] = 'linux') str

Generate an pathname to a file.

This method uses file_name() under the hood to generate the file name itself, and depth controls the depth of the directory path, and word() is used under the hood to generate the different directory names.

If absolute is True (default), the generated path starts with / and is absolute. Otherwise, the generated path is relative.

If used, extension can be either a string, forcing that extension, a sequence of strings (one will be picked at random), or an empty sequence (the path will have no extension). Default behaviour is the same as file_name()

if file_system is set (default=”linux”), the generated path uses specified file system path standard, the list of valid file systems include: 'windows', 'linux'.

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'
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.file_path(extension=[])
...
'/image/three'
'/voice/son'
'/amount/kitchen'
'/much/event'
'/interview/mention'
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.file_path(extension='')
...
'/image/three'
'/voice/son'
'/amount/kitchen'
'/much/event'
'/interview/mention'
>>> Faker.seed(0)
>>> for _ in range(5):
...     fake.file_path(extension=["a", "bc", "def"])
...
'/voice/son.bc'
'/event/amount.bc'
'/interview/mention.def'
'/help/me.bc'
'/whatever/wait.def'
mime_type(category: str | None = None) str

Generate a mime type under the specified category.

If category is None, 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: str | None = None) str

Generate a Unix device file name.

If prefix is None, 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: str | None = None) str

Generate a Unix partition name.

This method uses unix_device() under the hood to create a device file name with the specified prefix.

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'