faker.generator
¶
Module Contents¶
Classes¶
Attributes¶
- faker.generator._re_token¶
- faker.generator.random¶
- faker.generator.mod_random¶
- faker.generator.Sentinel¶
- class faker.generator.Generator(**config: Dict)¶
- property random: random.Random¶
- _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.
- format(formatter: str, *args: Any, **kwargs: Any) str ¶
This is a secure way to make a fake from another Provider.
- 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)¶