Skip to content

faker_optional special

Faker provider to create optional data.

model

Define the Fake providers.

OptionalProvider

Faker Provider to simulate Optional data.

__init__(self, generator) special

Declare the other faker providers.

Source code in faker_optional/model.py
def __init__(self, generator: Generator) -> None:
    """Declare the other faker providers."""
    super().__init__(generator)
    self.python = PyProvider(generator)
    self.date = DateProvider(generator)
    self.lorem = LoremProvider(generator)
    self.person = PersonProvider(generator)

optional_bool(self, ratio=0.5)

Return an optional bool.

Source code in faker_optional/model.py
def optional_bool(self, ratio: float = 0.5) -> Optional[bool]:
    """Return an optional bool."""
    return self._optional_value(self.python.pybool(), ratio)

optional_date(self, ratio=0.5, **kwargs)

Return an optional date.

Source code in faker_optional/model.py
def optional_date(self, ratio: float = 0.5, **kwargs: Any) -> Optional[date]:
    """Return an optional date."""
    return self._optional_value(self.date.date(**kwargs), ratio)

optional_datetime(self, ratio=0.5, **kwargs)

Return an optional datetime.

Source code in faker_optional/model.py
def optional_datetime(
    self, ratio: float = 0.5, **kwargs: Any
) -> Optional[datetime]:
    """Return an optional datetime."""
    return self._optional_value(self.date.date_time(**kwargs), ratio)

optional_dict(self, ratio=0.5, **kwargs)

Return an optional dictionary.

Source code in faker_optional/model.py
def optional_dict(
    self, ratio: float = 0.5, **kwargs: Any
) -> Optional[Dict[Any, Any]]:
    """Return an optional dictionary."""
    return self._optional_value(self.python.pydict(**kwargs), ratio)

optional_first_name(self, ratio=0.5)

Return an optional first_name.

Source code in faker_optional/model.py
def optional_first_name(self, ratio: float = 0.5) -> Optional[str]:
    """Return an optional first_name."""
    return self._optional_value(self.person.first_name(), ratio)

optional_first_name_female(self, ratio=0.5)

Return an optional first_name_female.

Source code in faker_optional/model.py
def optional_first_name_female(
    self,
    ratio: float = 0.5,
) -> Optional[str]:
    """Return an optional first_name_female."""
    return self._optional_value(self.person.first_name_female(), ratio)

optional_first_name_male(self, ratio=0.5)

Return an optional first_name_male.

Source code in faker_optional/model.py
def optional_first_name_male(
    self,
    ratio: float = 0.5,
) -> Optional[str]:
    """Return an optional first_name_male."""
    return self._optional_value(self.person.first_name_male(), ratio)

optional_first_name_nonbinary(self, ratio=0.5)

Return an optional first_name_nonbinary.

Source code in faker_optional/model.py
def optional_first_name_nonbinary(
    self,
    ratio: float = 0.5,
) -> Optional[str]:
    """Return an optional first_name_nonbinary."""
    return self._optional_value(self.person.first_name_nonbinary(), ratio)

optional_float(self, ratio=0.5, **kwargs)

Return an optional float number.

Source code in faker_optional/model.py
def optional_float(self, ratio: float = 0.5, **kwargs: Any) -> Optional[float]:
    """Return an optional float number."""
    return self._optional_value(self.python.pyfloat(**kwargs), ratio)

optional_int(self, ratio=0.5, **kwargs)

Return an optional integer.

Source code in faker_optional/model.py
def optional_int(self, ratio: float = 0.5, **kwargs: Any) -> Optional[int]:
    """Return an optional integer."""
    return self._optional_value(self.python.pyint(**kwargs))

optional_last_name(self, ratio=0.5)

Return an optional last_name.

Source code in faker_optional/model.py
def optional_last_name(self, ratio: float = 0.5) -> Optional[str]:
    """Return an optional last_name."""
    return self._optional_value(self.person.last_name(), ratio)

optional_last_name_female(self, ratio=0.5)

Return an optional last_name_female.

Source code in faker_optional/model.py
def optional_last_name_female(
    self,
    ratio: float = 0.5,
) -> Optional[str]:
    """Return an optional last_name_female."""
    return self._optional_value(self.person.last_name_female(), ratio)

optional_last_name_male(self, ratio=0.5)

Return an optional last_name_male.

Source code in faker_optional/model.py
def optional_last_name_male(
    self,
    ratio: float = 0.5,
) -> Optional[str]:
    """Return an optional last_name_male."""
    return self._optional_value(self.person.last_name_male(), ratio)

optional_last_name_nonbinary(self, ratio=0.5)

Return an optional last_name_nonbinary.

Source code in faker_optional/model.py
def optional_last_name_nonbinary(
    self,
    ratio: float = 0.5,
) -> Optional[str]:
    """Return an optional last_name_nonbinary."""
    return self._optional_value(self.person.last_name_nonbinary(), ratio)

optional_list(self, ratio=0.5, **kwargs)

Return an optional list.

Source code in faker_optional/model.py
def optional_list(self, ratio: float = 0.5, **kwargs: Any) -> Optional[List[Any]]:
    """Return an optional list."""
    return self._optional_value(self.python.pylist(**kwargs), ratio)

optional_name(self, ratio=0.5)

Return an optional name.

Source code in faker_optional/model.py
def optional_name(self, ratio: float = 0.5) -> Optional[str]:
    """Return an optional name."""
    return self._optional_value(self.person.name(), ratio)

optional_name_female(self, ratio=0.5)

Return an optional name_female.

Source code in faker_optional/model.py
def optional_name_female(self, ratio: float = 0.5) -> Optional[str]:
    """Return an optional name_female."""
    return self._optional_value(self.person.name_female(), ratio)

optional_name_male(self, ratio=0.5)

Return an optional name_male.

Source code in faker_optional/model.py
def optional_name_male(self, ratio: float = 0.5) -> Optional[str]:
    """Return an optional name_male."""
    return self._optional_value(self.person.name_male(), ratio)

optional_name_nonbinary(self, ratio=0.5)

Return an optional name_nonbinary.

Source code in faker_optional/model.py
def optional_name_nonbinary(
    self,
    ratio: float = 0.5,
) -> Optional[str]:
    """Return an optional name_nonbinary."""
    return self._optional_value(self.person.name_nonbinary(), ratio)

optional_paragraph(self, ratio=0.5, **kwargs)

Return an optional paragraph.

Source code in faker_optional/model.py
def optional_paragraph(self, ratio: float = 0.5, **kwargs: Any) -> Optional[str]:
    """Return an optional paragraph."""
    return self._optional_value(self.lorem.paragraph(**kwargs), ratio)

optional_paragraphs(self, ratio=0.5, **kwargs)

Return an optional paragraph.

Source code in faker_optional/model.py
def optional_paragraphs(self, ratio: float = 0.5, **kwargs: Any) -> Optional[str]:
    """Return an optional paragraph."""
    return self._optional_value(self.lorem.paragraphs(**kwargs), ratio)

optional_sentence(self, ratio=0.5, **kwargs)

Return an optional sentence.

Source code in faker_optional/model.py
def optional_sentence(self, ratio: float = 0.5, **kwargs: Any) -> Optional[str]:
    """Return an optional sentence."""
    return self._optional_value(self.lorem.sentence(**kwargs), ratio)

optional_sentences(self, ratio=0.5, **kwargs)

Return an optional sentence.

Source code in faker_optional/model.py
def optional_sentences(self, ratio: float = 0.5, **kwargs: Any) -> Optional[str]:
    """Return an optional sentence."""
    return self._optional_value(self.lorem.sentences(**kwargs), ratio)

optional_set(self, ratio=0.5, **kwargs)

Return an optional set.

Source code in faker_optional/model.py
def optional_set(self, ratio: float = 0.5, **kwargs: Any) -> Optional[Set[Any]]:
    """Return an optional set."""
    return self._optional_value(self.python.pyset(**kwargs), ratio)

optional_str(self, ratio=0.5, **kwargs)

Return an optional random string of upper and lowercase letters.

Source code in faker_optional/model.py
def optional_str(self, ratio: float = 0.5, **kwargs: Any) -> Optional[str]:
    """Return an optional random string of upper and lowercase letters."""
    return self._optional_value(self.python.pystr(**kwargs), ratio)

optional_text(self, ratio=0.5, **kwargs)

Return an optional text.

Source code in faker_optional/model.py
def optional_text(self, ratio: float = 0.5, **kwargs: Any) -> Optional[str]:
    """Return an optional text."""
    return self._optional_value(self.lorem.text(**kwargs), ratio)

optional_texts(self, ratio=0.5, **kwargs)

Return an optional text.

Source code in faker_optional/model.py
def optional_texts(self, ratio: float = 0.5, **kwargs: Any) -> Optional[str]:
    """Return an optional text."""
    return self._optional_value(self.lorem.texts(**kwargs), ratio)

optional_time(self, ratio=0.5, **kwargs)

Return an optional time.

Source code in faker_optional/model.py
def optional_time(self, ratio: float = 0.5, **kwargs: Any) -> Optional[time]:
    """Return an optional time."""
    return self._optional_value(self.date.time(**kwargs), ratio)

optional_tuple(self, ratio=0.5, **kwargs)

Return an optional tuple.

Source code in faker_optional/model.py
def optional_tuple(self, ratio: float = 0.5, **kwargs: Any) -> Optional[Tuple[Any]]:
    """Return an optional tuple."""
    return self._optional_value(self.python.pytuple(**kwargs), ratio)

optional_word(self, ratio=0.5, **kwargs)

Return an optional word.

Source code in faker_optional/model.py
def optional_word(self, ratio: float = 0.5, **kwargs: Any) -> Optional[str]:
    """Return an optional word."""
    return self._optional_value(self.lorem.word(**kwargs), ratio)

optional_words(self, ratio=0.5, **kwargs)

Return an optional word.

Source code in faker_optional/model.py
def optional_words(self, ratio: float = 0.5, **kwargs: Any) -> Optional[str]:
    """Return an optional word."""
    return self._optional_value(self.lorem.words(**kwargs), ratio)

version

Utilities to retrieve the information of the program version.

version_info()

Display the version of the program, python and the platform.

Source code in faker_optional/version.py
def version_info() -> str:
    """Display the version of the program, python and the platform."""
    info = {
        "faker_optional version": __version__,
        "python version": sys.version.replace("\n", " "),
        "platform": platform.platform(),
    }
    return "\n".join(f"{k + ':' :>30} {v}" for k, v in info.items())

Last update: 2021-04-25