Mimesis is a robust fake data generator for Python that produces realistic fake data across 35 different locales with high performance and multilingual support.
—
Foundation classes and the unified Generic provider that enable consistent data generation patterns across all data types in mimesis.
Abstract base class that provides fundamental functionality for all mimesis providers including random number generation control and enum validation.
class BaseProvider:
"""Base class for all mimesis providers."""
def reseed(self, seed: int = None) -> None:
"""
Reseed the internal random number generator.
Parameters:
- seed (int, optional): Seed value for reproducible results
"""
def validate_enum(self, item: Any, enum: type) -> Any:
"""
Validate that an item is a valid enum value.
Parameters:
- item: Value to validate
- enum: Enum class to validate against
Returns:
Valid enum value
Raises:
NonEnumerableError: If item is not a valid enum value
"""Abstract base class extending BaseProvider with locale-specific functionality for providers that generate locale-dependent data.
class BaseDataProvider(BaseProvider):
"""Base class for locale-dependent data providers."""
def __init__(self, locale: Locale = Locale.DEFAULT):
"""
Initialize provider with locale.
Parameters:
- locale (Locale): Locale for data generation
"""
def get_current_locale(self) -> str:
"""
Get the current locale string.
Returns:
str: Current locale (e.g., 'en', 'de-de')
"""
def override_locale(self, locale: Locale):
"""
Context manager for temporarily overriding locale.
Parameters:
- locale (Locale): Temporary locale to use
Usage:
```python
provider = Person(Locale.EN)
with provider.override_locale(Locale.DE):
name = provider.first_name() # German name
```
"""
def update_dataset(self, data: dict) -> None:
"""
Update the internal dataset with custom data.
Parameters:
- data (dict): Data to merge with existing dataset
"""Unified provider that gives access to all individual providers through a single interface, enabling convenient access to the entire mimesis API.
class Generic:
"""Unified provider for accessing all mimesis functionality."""
def __init__(self, locale: Locale = Locale.DEFAULT):
"""
Initialize Generic provider with locale.
Parameters:
- locale (Locale): Default locale for all providers
"""
def reseed(self, seed: int = None) -> None:
"""
Reseed all internal providers' random number generators.
Parameters:
- seed (int, optional): Seed value for reproducible results
"""
def add_provider(self, cls: type, **kwargs) -> None:
"""
Add a custom provider to the Generic instance.
Parameters:
- cls: Provider class to add
- **kwargs: Arguments to pass to provider constructor
Usage:
```python
from mimesis import Generic
class CustomProvider:
def custom_data(self):
return "custom"
generic = Generic()
generic.add_provider(CustomProvider)
print(generic.custom.custom_data()) # "custom"
```
"""
def add_providers(self, *providers: type) -> None:
"""
Add multiple custom providers to the Generic instance.
Parameters:
- *providers: Provider classes to add
"""
# Provider access attributes
person: Person
address: Address
internet: Internet
datetime: Datetime
finance: Finance
text: Text
numeric: Numeric
development: Development
science: Science
food: Food
hardware: Hardware
transport: Transport
cryptographic: Cryptographic
payment: Payment
choice: Choice
code: Code
binaryfile: BinaryFile
file: File
path: Pathfrom mimesis import Person, Address
from mimesis.locales import Locale
# Create providers with different locales
person_en = Person(Locale.EN)
person_de = Person(Locale.DE)
address = Address(Locale.FR)
# Generate localized data
english_name = person_en.full_name() # "John Smith"
german_name = person_de.full_name() # "Hans Müller"
french_city = address.city() # "Paris"from mimesis import Generic
from mimesis.locales import Locale
# Single Generic instance for all data types
generic = Generic(Locale.EN)
# Access all providers through unified interface
user_data = {
'name': generic.person.full_name(),
'email': generic.internet.email(),
'address': generic.address.address(),
'birthday': generic.datetime.date(),
'salary': generic.finance.price(minimum=50000, maximum=150000)
}from mimesis import Generic
# Set seed for reproducible results
generic = Generic()
generic.reseed(12345)
# These will be the same on every run
name1 = generic.person.full_name()
name2 = generic.person.full_name()
# Reseed with same value to get same sequence again
generic.reseed(12345)
name3 = generic.person.full_name() # Same as name1from mimesis import Person
from mimesis.locales import Locale
person = Person(Locale.EN)
# Default locale
english_name = person.full_name() # "John Smith"
# Temporarily use different locale
with person.override_locale(Locale.JA):
japanese_name = person.full_name() # "田中太郎"
# Back to default locale
english_name2 = person.full_name() # "Jane Doe"Install with Tessl CLI
npx tessl i tessl/pypi-mimesis