mimesis Test data creation library. It's an unfamiliar word, but it seems to have a meaning like "mimicry". Faker is also famous, but it seems to be faster than faker.
install
pip install mimesis
usage Basically, test data is created from the provider. There are quite a few types of providers, such as those related to people (Personal), those related to addresses (Address), and those related to food (Food).
from mimesis import Personal
#Create an instance by specifying the locale for the provider
personal = Personal(locale='ja')
#Get data from your provider
print(personal.full_name(gender='male'))
Generic can be used when it is troublesome to specify the locale for each provider and create an instance when using multiple providers.
from mimesis import Generic
generic = Generic(locale='ja')
#Create test data from your provider through Generic
print(generic.personal.full_name())
If you use Schema, test data will be created as an object of list. Specify the format of the data you want in the Schema.load method and use it.
from mimesis.schema import Schema
schema = Schema('ja')
data = schema.load(schema={
"name": "personal.full_name",
"email": "personal.email"
}).create(itertions=2)
result
[{'name': 'Takagi Akiba', 'email': '[email protected]'}, {'name': 'Chiharu Ichikawa', 'email': '[email protected]'}]
In addition, since there are various providers, is it sufficient as a function to create ordinary test data? However, the documentation on the original site is poor, so if you want to use the full functionality, you may have to read the code. Text provider Text.sentence, for some reason, it is interesting to return historical sentences ...
Recommended Posts