Skip to main content

Mimesis: dummy data for developers.

Project description

https://raw.githubusercontent.com/lk-geimfari/mimesis/master/media/logo.png
https://travis-ci.org/lk-geimfari/elizabeth.svg?branch=master https://readthedocs.org/projects/elizabeth/badge/?version=latest https://badge.fury.io/py/elizabeth.svg https://img.shields.io/badge/python-v3.3%2C%20v3.4%2C%20v3.5%2C%20v3.6-brightgreen.svg

Elizabeth is a fast and easy to use Python library for generating dummy data for a variety of purposes. This data can be particularly useful during software development and testing. For example, it could be used to populate a testing database for a web application with user information such as email addresses, usernames, first names, last names, etc.

Elizabeth uses a JSON-based datastore and does not require any modules that are not in the Python standard library. There are over nineteen different data providers available, which can produce data related to food, people, computer hardware, transportation, addresses, and more.

Documentation

Complete documentation for Elizabeth is available here: http://elizabeth.readthedocs.io/

Installation

To install Elizabeth, simply:

  ~ pip install mimesis

Basic Usage:

>>> from mimesis import Personal, Address
>>> person = Personal('en')
>>> address = Address('en')

>>> person.full_name(gender='female')
'Antonetta Garrison'

>>> person.email(gender='male')
'oren5936@live.com'

>>> person.occupation()
'Programmer'

>>> address.address()
'713 Rock Stravenue'

>>> address.city()
'Dumont'

>>> address.country()
'Switzerland'

>>> address.country_iso(fmt='iso2')
'WF'

>>> address.country_iso(fmt='iso3')
'BFA'

>>> address.country_iso(fmt='numeric')
'744'

>>> address.continent()
'South America'

Locales

You can specify a locale when creating providers and they will return data that is appropriate for the language or country associated with that locale. Elizabeth currently includes support for 32 different locales.

Using locales:

>>> from mimesis import Personal

>>> en = Personal('en')
>>> de = Personal('de')
>>> ic = Personal('is')

>>> en.full_name()
'Carolin Brady'

>>> de.full_name()
'Sabrina Gutermuth'

>>> ic.full_name()
'Rósa Þórlindsdóttir'

When you only need to generate data for a single locale, use the Generic provider, and you can access all Elizabeth providers from one object.

>>> from mimesis import Generic
>>> g = Generic('es')

>>> g.datetime.month()
'Agosto'

>>> g.code.imei()
'353918052107063'

>>> g.food.fruit()
'Limón'




>>> from mimesis import Generic
>>> g = Generic('es')

>>> g.datetime.month()
'Agosto'

>>> g.code.imei()
'353918052107063'

>>> g.food.fruit()
'Limón'




>>> from mimesis import Generic
>>> g = Generic('es')

>>> g.datetime.month()
'Agosto'

>>> g.code.imei()
'353918052107063'

>>> g.food.fruit()
'Limón'

Advantages

Mimesis offers a number of advantages over other similar libraries, such as Faker:

  • Performance. Mimesis is significantly faster than other similar libraries.

  • Completeness. Mimesis strives to provide many detailed providers that offer a variety of data generators.

  • Simplicity. Mimesis does not require any modules other than the Python standard library.

See here for an example of how we compare performance with other libraries.

Integration with Web Application Frameworks

You can use Mimesis during development and testing of applications built on a variety of frameworks. Here is an example of integration with a Flask application:

class Patient(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    full_name = db.Column(db.String(100))
    weight = db.Column(db.String(64))
    height = db.Column(db.String(64))
    blood_type = db.Column(db.String(64))
    age = db.Column(db.Integer)

    def __init__(self, **kwargs):
        super(Patient, self).__init__(**kwargs)

    @staticmethod
    def _bootstrap(count=500, locale='en', gender):
        from mimesis import Personal

        person = Personal(locale)

        for _ in range(count):
            patient = Patient(
                full_name=person.full_name(gender=gender),
                age=person.age(minimum=18, maximum=45),
                weight=person.weight(),
                height=person.height(),
                blood_type=person.blood_type(),
            )

            db.session.add(patient)
            try:
                db.session.commit()
            except IntegrityError:
                db.session.rollback()

Just run shell mode

(env) ➜ python3 manage.py shell

and do following:

>>> db
<SQLAlchemy engine='sqlite:///db_dev.sqlite'>

>>> Patient
<class 'app.models.Patient'>

>>> Patient()._bootstrap(count=1000, locale='en', gender='female')

Custom Providers

You also can add custom provider to Generic.

>>> class SomeProvider():
...
...     class Meta:
...         name = "some_provider"
...
...     @staticmethod
...     def one():
...         return 1

>>> class Another():
...
...     @staticmethod
...     def bye():
...         return "Bye!"

>>> generic.add_provider(SomeProvider)
>>> generic.add_provider(Another)

>>> generic.some_provider.one()
1

>>> generic.another.bye()
'Bye!'

Builtins specific data providers

Some countries have data types specific to that country. For example social security numbers in the United States (en locale), and cadastro de pessoas físicas (CPF) in Brazil (pt-br locale).

If you would like to use these country-specific providers, then you must import them explicitly:

>>> from mimesis import Generic
>>> from mimesis.builtins.pt_br import BrazilSpecProvider

>>> generic = Generic('pt-br')

>>> class BrazilProvider(BrazilSpecProvider):
...
...     class Meta:
...         name = "brazil_provider"
...
>>> generic.add_provider(BrazilProvider)
>>> generic.brazil_provider.cpf()
'696.441.186-00'




>>> from mimesis import Generic
>>> from mimesis.builtins.pt_br import BrazilSpecProvider

>>> generic = Generic('pt-br')

>>> class BrazilProvider(BrazilSpecProvider):
...
...     class Meta:
...         name = "brazil_provider"
...
>>> generic.add_provider(BrazilProvider)
>>> generic.brazil_provider.cpf()
'696.441.186-00'




>>> from mimesis import Generic
>>> from mimesis.builtins.pt_br import BrazilSpecProvider

>>> generic = Generic('pt-br')

>>> class BrazilProvider(BrazilSpecProvider):
...
...     class Meta:
...         name = "brazil_provider"
...
>>> generic.add_provider(BrazilProvider)
>>> generic.brazil_provider.cpf()
'696.441.186-00'




>>> from mimesis import Generic
>>> from mimesis.builtins.pt_br import BrazilSpecProvider

>>> generic = Generic('pt-br')

>>> class BrazilProvider(BrazilSpecProvider):
...
...     class Meta:
...         name = "brazil_provider"
...
>>> generic.add_provider(BrazilProvider)
>>> generic.brazil_provider.cpf()
'696.441.186-00'




>>> from mimesis import Generic
>>> from mimesis.builtins.pt_br import BrazilSpecProvider

>>> generic = Generic('pt-br')

>>> class BrazilProvider(BrazilSpecProvider):
...
...     class Meta:
...         name = "brazil_provider"
...
>>> generic.add_provider(BrazilProvider)
>>> generic.brazil_provider.cpf()
'696.441.186-00'

Decorators

If your locale is cyrillic, but you need latinized locale-specific data, then you can use special decorator. At this moment it’s work only for Russian:

>>> from mimesis import Personal
>>> from mimesis.decorators import romanized

>>> pr = Personal('ru')

>>> @romanized('ru')
... def get_name_ro():
...     return pr.full_name()
...

>>> def get_name_ru():
...     return pr.full_name()
...

>>> get_name_ru()
'Вида Панова'

>>> get_name_ro()
'Veronika Denisova'




>>> from mimesis import Personal
>>> from mimesis.decorators import romanized

>>> pr = Personal('ru')

>>> @romanized('ru')
... def get_name_ro():
...     return pr.full_name()
...

>>> def get_name_ru():
...     return pr.full_name()
...

>>> get_name_ru()
'Вида Панова'

>>> get_name_ro()
'Veronika Denisova'




>>> from mimesis import Personal
>>> from mimesis.decorators import romanized

>>> pr = Personal('ru')

>>> @romanized('ru')
... def get_name_ro():
...     return pr.full_name()
...

>>> def get_name_ru():
...     return pr.full_name()
...

>>> get_name_ru()
'Вида Панова'

>>> get_name_ro()
'Veronika Denisova'




>>> from mimesis import Personal
>>> from mimesis.decorators import romanized

>>> pr = Personal('ru')

>>> @romanized('ru')
... def get_name_ro():
...     return pr.full_name()
...

>>> def get_name_ru():
...     return pr.full_name()
...

>>> get_name_ru()
'Вида Панова'

>>> get_name_ro()
'Veronika Denisova'




>>> from mimesis import Personal
>>> from mimesis.decorators import romanized

>>> pr = Personal('ru')

>>> @romanized('ru')
... def get_name_ro():
...     return pr.full_name()
...

>>> def get_name_ru():
...     return pr.full_name()
...

>>> get_name_ru()
'Вида Панова'

>>> get_name_ro()
'Veronika Denisova'

Disclaimer

The authors assume no responsibility for how you use this library data generated by it. This library is designed only for developers with good intentions. Do not use the data generated with Mimesis for illegal purposes.

Author

Likid Geimfari (likid.geimfari@gmail.com)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mimesis-0.0.3.tar.gz (1.8 MB view details)

Uploaded Source

File details

Details for the file mimesis-0.0.3.tar.gz.

File metadata

  • Download URL: mimesis-0.0.3.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mimesis-0.0.3.tar.gz
Algorithm Hash digest
SHA256 6245b280485f46c62c5bc58d6f27e1afcd27672547d14c090da3424a1096b13d
MD5 3fad94885a68bdb20163332821583b9a
BLAKE2b-256 48b55ced1e502098ce2dc994c60bd924fe808df6d4de0c46ad512b0a718c5955

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page