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).
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/
At this moment a library has 17 supported locales:
№ | Flag | Code | Name | Native name |
---|---|---|---|---|
1 | 🇩🇰 | da |
Danish | Dansk |
2 | 🇩🇪 | de |
German | Deutsch |
3 | 🇺🇸 | en |
English | English |
4 | 🇬🇧 | en-gb |
British English | English |
5 | 🇪🇸 | es |
Spanish | Español |
6 | 🇮🇷 | fa |
Farsi | فارسی |
7 | 🇫🇮 | fi |
Finnish | Suomi |
8 | 🇫🇷 | fr |
French | Français |
9 | 🇮🇸 | is |
Icelandic | Íslenska |
10 | 🇮🇹 | it |
Italian | Italiano |
11 | 🇳🇱 | nl |
Dutch | Nederlands |
12 | 🇳🇴 | no |
Norwegian | Norsk |
13 | 🇵🇱 | pl |
Polish | Polski |
14 | 🇵🇹 | pt |
Portuguese | Português |
15 | 🇧🇷 | pt-br |
Brazilian Portuguese | Português Brasileiro |
16 | 🇷🇺 | ru |
Russian | Русский |
17 | 🇸🇪 | sv |
Swedish | Svenska |
➜ ~ pip install elizabeth
➜ ~ git clone https://github.com/lk-geimfari/elizabeth.git
➜ ~ cd elizabeth/
➜ ~ python3 -m unittest discover tests
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:
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'
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!'
Elizabeth support more than 18 data providers, such as Personal, Datetime, Internet and another.
Here you can find very small comparison with Faker. Screenshot here
You can say thanks!
Your contributions are always welcome! Please take a look at the contribution guidelines first. Here you can look a list of contributors
See CHANGELOG.md.
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.
Elizabeth is licensed under the MIT License. See LICENSE for the full license text.