Giter VIP home page Giter VIP logo

elizabeth's Introduction

Elizabeth

Build Status codecov Documentation Status PyPI version Python Version Codacy Badge


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 eighteen different data providers available, which can produce data related to food, people, computer hardware, transportation, addresses, and more.

Documentation

Elizabeth is simple to use, and the below examples should help you get started. Complete documentation for Elizabeth is available here: http://elizabeth.readthedocs.io/en/latest/

Installation

To install Elizabeth, simply:

~ pip install elizabeth

Basic Usage

>>> from elizabeth import Personal
>>> p = Personal('en')
>>>
>>> p.full_name(gender='female')
'Antonetta Garrison'
>>> p.blood_type()
'O-'
>>> p.occupation()
'Programmer'

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 20 different locales:

Flag Code Name Native name
1 🇨🇿 cs Czech Česky
2 🇩🇰 da Danish Dansk
3 🇩🇪 de German Deutsch
4 🇺🇸 en English English
5 🇬🇧 en-gb British English English
6 🇪🇸 es Spanish Español
7 🇮🇷 fa Farsi فارسی
8 🇫🇮 fi Finnish Suomi
9 🇫🇷 fr French Français
10 🇭🇺 hu Hungarian Magyar
11 🇮🇸 is Icelandic Íslenska
12 🇮🇹 it Italian Italiano
13 🇰🇷 ko Korean 한국어
14 🇳🇱 nl Dutch Nederlands
15 🇳🇴 no Norwegian Norsk
16 🇵🇱 pl Polish Polski
17 🇵🇹 pt Portuguese Português
18 🇧🇷 pt-br Brazilian Portuguese Português Brasileiro
19 🇷🇺 ru Russian Русский
20 🇸🇪 sv Swedish Svenska

Using locales:

>>> from elizabeth import Text
>>> en = Text()  # English is Elizabeth's default locale
>>> de = Text('de')

>>> en.sentence()
'Ports are used to communicate with the external world.'
>>> de.sentence()
'Wir müssen nicht vergessen Zickler.'
>>>
>>> en.color()
'Blue'
>>> de.color()
'Türkis'

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 elizabeth import Generic
>>> g = Generic('es')
>>>
>>> g.datetime.month()
'Agosto'
>>> g.code.imei()
'353918052107063'
>>> g.food.fruit()
'Limón'

Advantages

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

  • Performance. Elizabeth is significantly faster than other similar libraries.
  • Completeness. Elizabeth strives to provide many detailed providers that offer a variety of data generators.
  • Simplicity. Elizabeth 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 Elizabeth 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)
    email = db.Column(db.String(120), unique=True)
    phone_number = db.Column(db.String(25))
    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=2000, locale='en'):
        from elizabeth import Personal

        person = Personal(locale)

        for _ in range(count):
            patient = Patient(
                email=person.email(),
                phone_number=person.telephone(),
                full_name=person.full_name(gender='female'),
                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

(venv) ➜ 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')

Result:

en

Custom Providers

You also can add custom provider to Generic.

>>> from elizabeth import Generic
>>> generic = Generic('en')
>>>
>>> class SomeProvider():
>>>     class Meta:
>>>         name = 'some_provider'
>>>
>>>     def ints(self):
>>>         return [i for i in range(1, 5)]
>>>
>>> class Another():
>>>     def bye(self):
>>>         return "Bye!"
>>>
>>> generic.add_provider(SomeProvider)
>>> generic.add_provider(Another)
>>>
>>> generic.some_provider.ints()
[1, 2, 3, 4]
>>> 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 elizabeth import Generic
>>> from elizabeth.builtins import Brazil
>>>
>>> generic = Generic('pt-br')
>>>
>>> class BrazilProvider(Brazil):
>>>     class Meta:
>>>         name = "brazil_provider"
>>>
>>> generic.add_provider(BrazilProvider)
>>>
>>> generic.brazil_provider.cpf()
'001.137.297-40'

Like It?

You can say thanks!

Contributing

Your contributions are always welcome! Please take a look at the contribution guidelines first. Here you can look a list of our contributors.

Testing

~ git clone https://github.com/lk-geimfari/elizabeth.git
➜  ~ cd elizabeth/
➜  ~ python3 -m unittest discover tests # or ./run_tests.sh

Change Log

See CHANGELOG.md.

License

Elizabeth is licensed under the MIT License. See LICENSE for more information.

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 Elizabeth for illegal purposes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.