Python data mocking package that can be used for:
- Unit testing
- Data quality testing
- Mocking data for API responses
- Generating seed data for databases
This package lets you define data models in a way similar to Django or Pydantic models and generate data that conforms to those models.
Warning
When I started preparing to publish this package to PyPi, I found out the name was already taken, so I’ll be renaming it soon. I’m still searching for a good name—if you have any ideas, please share them in #4
See the playground.ipynb for up to date examples.
Generates a random integer value within a specified range using random.randint
function by default.
Arguments:
min_value
(int): Minimum value of the field (inclusive)max_value
(int): Maximum value of the field (inclusive)provider
(Provider): Custom provider class. It must conform to themocktail.providers.Provider
protocol.generator
(Callable[[int, int], int]): Custom generator function. It israndom.randint
by default.
Generates a random string value within a specified length range.
Arguments:
min_length
(int): Minimum length of the field (inclusive)max_length
(int): Maximum length of the field (inclusive)provider
(Provider): Custom provider class. It must conform to themocktail.providers.Provider
protocol.generator
(Callable[[int, int], int]): Custom generator function. It israndom.randint
by default.
Generates a random boolean.
Arguments:
true_percentage
(int): Percentage of True value. Default is 50%.provider
(Provider): Custom provider class. It must conform to themocktail.providers.Provider
protocol.
Generates a random datetime.date
object.
Arguments:
provider
(Provider): Custom provider class. It must conform to themocktail.providers.Provider
protocol.- ?
serializer
(Serializer): Custom serializer class. It must conform to themocktail.serializers.Serializer
protocol. Can be used to serialize in the custom format. Default implementation usesdatetime.date.isoformat()
by default.
Generates a random datetime.time
object.
Arguments:
provider
(Provider): Custom provider class. It must conform to themocktail.providers.Provider
protocol.- ?
serializer
(Serializer): Custom serializer class. It must conform to themocktail.serializers.Serializer
protocol. Can be used to serialize in the custom format. Default implementation usesdatetime.time.isoformat()
by default.
Generates a random datetime.datetime
object.
Arguments:
provider
(Provider): Custom provider class. It must conform to themocktail.providers.Provider
protocol.- ?
serializer
(Serializer): Custom serializer class. It must conform to themocktail.serializers.Serializer
protocol. Can be used to serialize in the custom format. Default implementation usesdatetime.datetime.isoformat()
by default.
A protocol that should be used to create any custom providers
This is generic with generic type T
that indicates type if generated values.
Methods:
Provider.provide(*args, **kwargs) -> T
: generate a single value of typeT
Provider that generates first names.
Provider that generates last names.
Provider that generates emails.
Provider that generates color names.
Provider that generates color as hex number like #F342E1.
Provider that generates a random UUID v4.