Mimesis · realistic, locale-aware fake data in one line

4 months ago

Your tests and seed scripts need believable data, not foo and bar. Mimesis gives you realistic, locale-aware fake data in one line of Python.

Ask about this presentation

Chapters

  1. 0:00Mimesis
  2. 0:08The fastest fake-data generator in Python
  3. 0:21The first win
  4. 0:33One object, every provider
  5. 0:43Locale is a first-class knob
  6. 0:57Seed a whole table
  7. 1:07Realistic data, in one line
Show transcript
  1. Your tests and seed scripts need believable data, not foo and bar. Mimesis gives you realistic, locale-aware fake data in one line of Python.

    Slide text
    mimesis logo

    Realistic, locale-aware fake data in one line of Python.

    import → one call → real data
  2. Mimesis is a fast, dependency-free generator for names, emails, addresses, dates, and more. It is fully typed, so your editor autocompletes every provider, and it supports forty six locales out of the box. Install it with pip.

    Slide text

    One dependency-free library for names, emails, addresses, dates, and more. It is fully typed, so your editor autocompletes every provider, and it ships 46 locales out of the box.

    pip install mimesis
  3. Here is the first win. Import a provider, pick a locale, and call a method. One line gives you a believable full name, an email, or a phone number in the exact format you ask for. No setup, and no fixtures to hand write.

    Slide text
    from mimesis import Person
    from mimesis.locales import Locale
    
    person = Person(Locale.EN)
    person.full_name()   # 'Alphonso Burton'
    person.email()       # 'express2040@protonmail.com'
    person.telephone(mask='1-4##-8##-5##3')
    # -> '1-446-838-5173'

    Example output · every call returns fresh random data.

  4. Need more than one kind of value? Generic gives you every provider through a single object. From one variable you reach person, address, finance, and dates, all sharing the same locale.

    Slide text
    from mimesis import Generic
    from mimesis.locales import Locale
    
    g = Generic(Locale.EN)
    g.person.username()   # 'employ_2019'
    g.address.city()      # 'Paramus'
    g.finance.company()   # 'Dover Corporation'
    g.datetime.date()     # 2018-10-06

    Person, address, finance, dates · all sharing one locale.

  5. Locale is a first-class knob, and this is what sets Mimesis apart. Ask for a full name in English, Russian, or Japanese, and you get names in the right script and style, not English text relabeled. Forty six locales cover addresses, text, and more.

    Slide text
    Person(Locale.EN).full_name()
    Person(Locale.RU).full_name()
    Person(Locale.JA).full_name()
    EN Alphonso Burton
    RU Александр Родивонов
    JA 悪太郎 勝亦

    Real names in the right script · 46 locales, not English relabeled.

  6. To seed a whole table, use Fieldset. Give it a field name and a count, and one call returns a column of realistic values. Raise the count to fill as many rows as your database needs.

    Slide text
    from mimesis.schema import Fieldset
    
    fs = Fieldset(Locale.EN, i=3)
    fs('name')    # ['Alphonso', 'Nolan', 'Jerold']
    fs('email')   # 3 emails, one call

    One call · a column of N values. Raise i to fill as many rows as you need.

  7. That is the whole idea. One import, one call, realistic data, in any of forty six locales. It is fully typed and has no dependencies, so it drops straight into your tests and seed scripts. Install it with pip, and start from the docs.

    Slide text
    • One call · names, emails, addresses, dates, and more.
    • 46 locales · real names in the right script.
    • Generic · every provider through one object.
    • Fieldset · a whole column in a single call.
    • Fully typed · autocomplete for every field.
    • Zero deps · drops into any test or seed script.

    pip install mimesis  ·  mimesis.name

What happened in AI today, in your inbox

One short email each evening. Read it and you’re caught up.

Built with ❤️ in New York