How to use the mimesis.providers.base.BaseProvider function in mimesis

To help you get started, we’ve selected a few mimesis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lk-geimfari / mimesis / mimesis / providers / units.py View on Github external
# -*- coding: utf-8 -*-

"""Provides data related to units."""

from typing import Optional

from mimesis.data import SI_PREFIXES, SI_PREFIXES_SYM
from mimesis.enums import PrefixSign, UnitName
from mimesis.providers.base import BaseProvider

__all__ = ['UnitSystem']


class UnitSystem(BaseProvider):
    """Class for generating data related to units."""

    class Meta:
        """Class for metadata."""

        name = 'unit_system'

    def unit(self, name: Optional[UnitName] = None, symbol=False):
        """Get unit name.

        :param name: Enum object UnitName.
        :param symbol: Return only symbol
        :return: Unit.
        """
        result = self._validate_enum(item=name, enum=UnitName)
github lk-geimfari / mimesis / mimesis / providers / generic.py View on Github external
def add_provider(self, cls: Type[BaseProvider]) -> None:
        """Add a custom provider to Generic() object.

        :param cls: Custom provider.
        :return: None
        :raises TypeError: if cls is not class or is not a subclass
            of BaseProvider.
        """
        if inspect.isclass(cls):
            if not issubclass(cls, BaseProvider):
                raise TypeError('The provider must be a '
                                'subclass of BaseProvider')
            try:
                meta = getattr(cls, 'Meta')
                name = getattr(meta, 'name')
            except AttributeError:
                name = cls.__name__.lower()
            setattr(self, name, cls(seed=self.seed))
        else:
            raise TypeError('The provider must be a class')
github lk-geimfari / mimesis / mimesis / providers / games.py View on Github external
"""Provides data related to gaming and games."""

from mimesis.data import GAMES, GAMING_PLATFORMS, GENRES, SCORE_PHRASES
from mimesis.providers.base import BaseProvider

__all__ = ['Games']


class Games(BaseProvider):
    """Class for generating data related to the games."""

    def gaming_platform(self) -> str:
        """Get random gaming platform.

        :return: Gaming platform

        :Example:
            PlayStation 4 Pro
        """
        return self.random.choice(GAMING_PLATFORMS)

    def score(self, minimum: int = 1, maximum: int = 10) -> float:
        """Score of game.

        :param minimum: Maximum value.
github lk-geimfari / mimesis / mimesis / providers / numbers.py View on Github external
# -*- coding: utf-8 -*-

"""Provides data related to numbers."""

from typing import Callable, List, Union

from mimesis.enums import NumTypes
from mimesis.providers.base import BaseProvider

__all__ = ['Numbers']


class Numbers(BaseProvider):
    """Class for generating numbers."""

    class Meta:
        """Class for metadata."""

        name = 'numbers'

    def floats(self, start: float = 0, end: float = 1, n: int = 10,
               rounding: int = 15) -> List[float]:
        """Generate a list of random float numbers.

        :param start: Start range.
        :param end: End range.
        :param n: Length of the list.
        :param rounding: Max number of decimal digits.
        :return: The list of floating-point numbers.
github lk-geimfari / mimesis / mimesis / providers / development.py View on Github external
# -*- coding: utf-8 -*-

"""Data related to the development."""

from mimesis.data import LICENSES, OS, PROGRAMMING_LANGS
from mimesis.providers.base import BaseProvider

__all__ = ['Development']


class Development(BaseProvider):
    """Class for getting fake data for Developers."""

    class Meta:
        """Class for metadata."""

        name = 'development'

    def software_license(self) -> str:
        """Get a random software license.

        :return: License name.

        :Example:
            The BSD 3-Clause License.
        """
        return self.random.choice(LICENSES)
github lk-geimfari / mimesis / mimesis / providers / hardware.py View on Github external
GENERATION,
    GRAPHICS,
    HDD_SSD,
    MANUFACTURERS,
    PHONE_MODELS,
    RAM_SIZES,
    RAM_TYPES,
    RESOLUTIONS,
    SCREEN_SIZES,
)
from mimesis.providers.base import BaseProvider

__all__ = ['Hardware']


class Hardware(BaseProvider):
    """Class for generate data related to hardware."""

    class Meta:
        """Class for metadata."""

        name = 'hardware'

    def resolution(self) -> str:
        """Get a random screen resolution.

        :return: Resolution of screen.

        :Example:
            1280x720.
        """
        return self.random.choice(RESOLUTIONS)
github lk-geimfari / mimesis / mimesis / providers / payment.py View on Github external
import re
import string
from typing import Optional

from mimesis.data import CREDIT_CARD_NETWORKS
from mimesis.enums import CardType, Gender
from mimesis.exceptions import NonEnumerableError
from mimesis.providers.base import BaseProvider
from mimesis.providers.person import Person
from mimesis.random import get_random_item
from mimesis.shortcuts import luhn_checksum

__all__ = ['Payment']


class Payment(BaseProvider):
    """Class that provides data related to payments."""

    def __init__(self, *args, **kwargs) -> None:
        """Initialize attributes.

        :param args: Arguments.
        :param kwargs: Keyword arguments.
        """
        super().__init__(*args, **kwargs)
        self.__person = Person('en', seed=self.seed)

    class Meta:
        """Class for metadata."""

        name = 'payment'
github lk-geimfari / mimesis / mimesis / providers / cryptographic.py View on Github external
# -*- coding: utf-8 -*-

"""Cryptographic data provider."""

import hashlib
import secrets
import uuid

from mimesis.enums import Algorithm
from mimesis.providers.base import BaseProvider
from mimesis.providers.text import Text

__all__ = ['Cryptographic']


class Cryptographic(BaseProvider):
    """Class that provides cryptographic data."""

    def __init__(self, *args, **kwargs) -> None:
        """Initialize attributes.

        :param seed: Seed.
        """
        super().__init__(*args, **kwargs)
        self.__words = Text('en')._data.get('words', {})

    class Meta:
        """Class for metadata."""

        name = 'cryptographic'

    def uuid(self, version: int = None) -> str:
github lk-geimfari / mimesis / mimesis / providers / clothing.py View on Github external
# -*- coding: utf-8 -*-

"""Clothing data provider."""

from mimesis.providers.base import BaseProvider

__all__ = ['Clothing']


class Clothing(BaseProvider):
    """Class for generate data related to clothing."""

    class Meta:
        """Class for metadata."""

        name = 'clothing'

    def international_size(self) -> str:
        """Get a random size in international format.

        :return: Clothing size.
        """
        return self.random.choice(['L', 'M', 'S', 'XL',
                                   'XS', 'XXL', 'XXS', 'XXXL'])

    def european_size(self) -> int:
github lk-geimfari / mimesis / mimesis / providers / code.py View on Github external
from mimesis.data import (
    EAN_MASKS,
    IMEI_TACS,
    ISBN_GROUPS,
    ISBN_MASKS,
    LOCALE_CODES,
)
from mimesis.enums import EANFormat, ISBNFormat
from mimesis.providers.base import BaseProvider
from mimesis.shortcuts import luhn_checksum

__all__ = ['Code']


class Code(BaseProvider):
    """Class that provides methods for generating codes."""

    def __init__(self, *args, **kwargs):
        """Initialize attributes.

        :param locale: Current locale.
        """
        super().__init__(*args, **kwargs)

    class Meta:
        """Class for metadata."""

        name = 'code'

    def locale_code(self) -> str:
        """Get a random locale code (MS-LCID).