faker

Subpackages

Submodules

Package Contents

Classes

Factory

Generator

Faker

Proxy class capable of supporting multiple locales

class faker.Factory
classmethod create(locale: Optional[str] = None, providers: Optional[List[str]] = None, generator: Optional[faker.generator.Generator] = None, includes: Optional[List[str]] = None, use_weighting: bool = True, **config: Any) faker.generator.Generator
classmethod _find_provider_class(provider_path: str, locale: Optional[str] = None) Tuple[Any, Optional[str], Optional[str]]
class faker.Generator(**config: Dict)
property random: random.Random
__config: Dict[str, Dict[Hashable, Any]]
_is_seeded = False
_global_seed
add_provider(provider: Union[faker.providers.BaseProvider, Type[faker.providers.BaseProvider]]) None
provider(name: str) Optional[faker.providers.BaseProvider]
get_providers() List[faker.providers.BaseProvider]

Returns added providers.

seed_instance(seed: Optional[faker.typing.SeedType] = None) Generator

Calls random.seed

classmethod seed(seed: Optional[faker.typing.SeedType] = None) None
format(formatter: str, *args: Any, **kwargs: Any) str

This is a secure way to make a fake from another Provider.

get_formatter(formatter: str) Callable
set_formatter(name: str, formatter: Callable) None

This method adds a provider method to generator. Override this method to add some decoration or logging stuff.

set_arguments(group: str, argument: str, value: Optional[Any] = None) None

Creates an argument group, with an individual argument or a dictionary of arguments. The argument groups is used to apply arguments to tokens, when using the generator.parse() method. To further manage argument groups, use get_arguments() and del_arguments() methods.

generator.set_arguments(‘small’, ‘max_value’, 10) generator.set_arguments(‘small’, {‘min_value’: 5, ‘max_value’: 10})

get_arguments(group: str, argument: Optional[str] = None) Any

Get the value of an argument configured within a argument group, or the entire group as a dictionary. Used in conjunction with the set_arguments() method.

generator.get_arguments(‘small’, ‘max_value’) generator.get_arguments(‘small’)

del_arguments(group: str, argument: Optional[str] = None) Any

Delete an argument from an argument group or the entire argument group. Used in conjunction with the set_arguments() method.

generator.del_arguments(‘small’) generator.del_arguments(‘small’, ‘max_value’)

parse(text: str) str

Replaces tokens like ‘{{ tokenName }}’ or ‘{{tokenName}}’ in a string with the result from the token method call. Arguments can be parsed by using an argument group. For more information on the use of argument groups, please refer to the set_arguments() method.

Example:

generator.set_arguments(‘red_rgb’, {‘hue’: ‘red’, ‘color_format’: ‘rgb’}) generator.set_arguments(‘small’, ‘max_value’, 10)

generator.parse(‘{{ color:red_rgb }} - {{ pyint:small }}’)

__format_token(matches)
class faker.Faker(locale: Optional[Union[str, Sequence[str], Dict[str, Union[int, float]]]] = None, providers: Optional[List[str]] = None, generator: Optional[faker.generator.Generator] = None, includes: Optional[List[str]] = None, use_weighting: bool = True, **config: Any)

Proxy class capable of supporting multiple locales

property unique: UniqueProxy
property optional: OptionalProxy
property random: random.Random

Proxies random getter calls

In single locale mode, this will be proxied to the random getter of the only internal Generator object. Subclasses will have to implement desired behavior in multiple locale mode.

property locales: List[str]
property weights: Optional[List[Union[int, float]]]
property factories: List[faker.generator.Generator]
cache_pattern: Pattern
generator_attrs
__dir__()

Default dir() implementation.

__getitem__(locale: str) faker.generator.Generator
__getattribute__(attr: str) Any

Handles the “attribute resolution” behavior for declared members of this proxy class

The class method seed cannot be called from an instance.

Parameters

attr – attribute name

Returns

the appropriate attribute

__getattr__(attr: str) Any

Handles cache access and proxying behavior

Parameters

attr – attribute name

Returns

the appropriate attribute

__deepcopy__(memodict: Dict = {}) Faker
__setstate__(state: Any) None
_select_factory(method_name: str) faker.factory.Factory

Returns a random factory that supports the provider method

Parameters

method_name – Name of provider method

Returns

A factory that supports the provider method

_select_factory_distribution(factories, weights)
_select_factory_choice(factories)
_map_provider_method(method_name: str) Tuple[List[faker.factory.Factory], Optional[List[float]]]

Creates a 2-tuple of factories and weights for the given provider method name

The first element of the tuple contains a list of compatible factories. The second element of the tuple contains a list of distribution weights.

Parameters

method_name – Name of provider method

Returns

2-tuple (factories, weights)

classmethod seed(seed: Optional[faker.typing.SeedType] = None) None

Hashables the shared random.Random object across all factories

Parameters

seed – seed value

seed_instance(seed: Optional[faker.typing.SeedType] = None) None

Creates and seeds a new random.Random object for each factory

Parameters

seed – seed value

seed_locale(locale: str, seed: Optional[faker.typing.SeedType] = None) None

Creates and seeds a new random.Random object for the factory of the specified locale

Parameters
  • locale – locale string

  • seed – seed value

items() List[Tuple[str, faker.generator.Generator]]