GithubHelp home page GithubHelp logo

modulexcite / elizabeth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lk-geimfari/mimesis

0.0 1.0 0.0 4.03 MB

Elizabeth is a fast and easier to use Python library for generating dummy data, which are very useful when you need to bootstrap the database in the testing phase of your software.

Home Page: http://lk-geimfari.github.io/elizabeth/

License: MIT License

Python 99.85% Shell 0.15%

elizabeth's Introduction

Elizabeth

Build Status codecov Documentation Status PyPI version Python Version Codacy Badge


Elizabeth is a fast and easier to use Python library for generating dummy data. These data are very useful when you need to bootstrap the database in the testing phase of your software. A great example of how you can use the library are web applications on Flask or Django which need a data, such as users (email, username, name, surname etc.), posts (tags, text, title, publishing date and etc.) and so forth. The library uses the JSON files as a datastore and doesn’t have any dependencies. The library offers more than 18 different data providers (from personal ones to transport and more).

Documentation

Elizabeth is a pretty simple library and all you need to start is the small documentation. See Elizabeth's Sphinx-generated documentation here: http://elizabeth.readthedocs.io/en/latest/

Locales

At this moment a library has 16 supported locales:

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

Installation

~ pip install elizabeth

Testing

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

Using with Flask

You can use Elizabeth with your Flask-application (with any other frameworks in a similar manner).

# Some logic
# ...
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

A common use

Import a provider that you need

>>>> from elizabeth import Personal

and create instance of provider that was be imported:

>>> personal = Personal('en')

and call the one from methods:

>>> for _ in range(0, 5):
       personal.full_name(gender='female')

Output:

'Antonetta Garrison'
'Taneka Dickerson'
'Jackelyn Stafford'
'Tashia Olsen'
'Rachal Hartman'

For other locales, exactly the same way (Icelandic) :

>>> personal = Personal('is')

>>> for _ in range(0, 5):
        personal.full_name(gender='male')

Output:

'Þórgrímur Garibaldason'
'Zóphanías Bergfinnsson'
'Vésteinn Ríkharðsson'
'Hallvarður Valgarðsson'
'Baltasar Hlégestsson'

When you use only one locale you can use the Generic , that provides all providers at one class.

>>> from elizabeth import Generic

>>> g = Generic('en')

>>> for _ in range(0, 5):
        name = g.personal.name()
        b_day = g.datetime.birthday()
        "%s - %s" % (name, b_day)

Output:

'Sharda - November 4, 2000'
'Nevada - January 16, 1980'
'Dreama - August 10, 1987'
'Jani - July 30, 1989'
'Chin - September 24, 1994'

Custom provider

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(0, 5)]

>>> class Another():
        def bye(self):
            return "Bye!"

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

>>> generic.some_provider.ints()
[0, 1, 2, 3, 4]

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

Data providers

Elizabeth support more than 18 data providers, such as Personal, Datetime, Internet and another.

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 contributors

Changelog

See CHANGELOG.md.

Disclaimer

The author does not assume any responsibility for how you will use this library and how you will use data generated with this library. This library is designed only for developers and only with good intentions. Do not use the data generated with Elizabeth for illegal purposes.

Licence

Elizabeth is licensed under the MIT License. See LICENSE for the full license text.

elizabeth's People

Watchers

 avatar

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.