未加星标

Generate random data for your applications with Elizabeth

字体大小 | |
[开发(python) 所属分类 开发(python) | 发布者 店小二04 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏
Generate random data for your applications with Elizabeth Posted 15 Feb 2017 D Ruth Bavousett Feed

1

up
Generate random data for your applications with Elizabeth

Image by :

Opensource.com

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.

No, I've not had my article hijacked by a Lorem ipsum generator. For this month's Nooks & Crannies column, I found an interesting little python library to help developers generate random data for their applications. It's called Elizabeth .

Written by Líki Geimfari, and licensed under the MIT license, Elizabeth has a set of 18 data providers in 21 different locales that you can use to generate random information, including names and personal characteristics, addresses, text data, transportation information, networking and Internet social media data, numbers, and much more. Installation requires Python3.2 or higher, and you can either install it using pip , or from the git repository.

For my test drive, I installed with pip, on a fresh Debian Jessie box. You'll need to apt-get installpython3-pip , which will install Python and needed dependencies. Then pip install elizabeth , and you're ready to use it.

Just for giggles, let's generate some random data on a person in the Python interactive interpreter:

>>> from elizabeth import Personal >>> p=Personal('en') >>> p.full_name(gender="male") 'Elvis Herring' >>> p.blood_type() 'B+' >>> p.credit_card_expiration_date() '09/17' >>> p.email(gender='male') [email protected]' >>> p.favorite_music_genre() 'Ambient' >>> p.identifier(mask='13064########') '1306420450944' >>> p.sexual_orientation() 'Heterosexual' >>> p.work_experience() 39 >>> p.occupation() 'Senior System Designer' >>>

Using it in your code works just the same way―create an object, and then call the methods you want to fill in your data.

There are 18 different generator tools built into Elizabeth, and adding a new one is not at all difficult; you just have to define the routines that get the data from a JSON collection of values. Here's some random text string generation, again in the interpreter:

>>> from elizabeth import Text >>> t=Text('en') >>> t.swear_word() 'Rat-fink' >>> t.quote() 'Let them eat cake.' >>> t.words(quantity=20) ['securities', 'keeps', 'accessibility', 'barbara', 'represent', 'hentai', 'flower', 'keys', 'rpm', 'queen', 'kingdom', 'posted', 'wearing', 'attend', 'stack', 'interface', 'quite', 'elementary', 'broadcast', 'holland'] >>> t.sentence() 'She spent her earliest years reading classic literature, and writing poetry.'

It's not a difficult exercise to use Elizabeth to populate a SQLite or other database you might need for development or testing. The introductory documentation gives an example for a medical application using the Flask lightweight web framework.

I'm very impressed with Elizabeth―it's super-fast, lightweight, easily extensible, and the community, while small, is active and engaged. As of this writing, there have been 25 committers to the project, and issues are being handled swiftly. The full documentation for Elizabeth is easy to read and follow, and provides an extensive API reference, at least for US English.

I tried tinkering with the links to find if documentation was available in other languages, but I didn't have any success. Because the APIs are different in non-English locales, documenting those variations would be extremely helpful for users. To be fair, it's not terribly hard to read the code and find out what methods are available, even if your Python-fu is not strong. Another glaring lack, for me, was the lack of Arabic or Hebrew locale test data. These are notable right-to-left languages, and for developers who are trying to internationalize their application, proper handling of these languages is a major hurdle. Tools like Elizabeth that can assist with that effort are great to have.

For developers needing sample data for their applications, Elizabeth is a valuable tool, andfor those trying to create truly multilingual, localizable applications, it could be a treasure.


Generate random data for your applications with Elizabeth
Tags

Nooks and Crannies column ,

Python

About the author
Generate random data for your applications with Elizabeth
D Ruth Bavousett

D Ruth Bavousett has been a system administrator and software developer for a long, long time, getting her professional start on a VAX 11/780, way back when. She spent a lot of her career (so far) serving the technology needs of libraries, and has been a contributor since 2008 to the Koha open source library automation suite.Ruth is currently a Perl Developer at cPanel in Houston, and also serves as chief of staff for two cats.

More about me

Learn how you can contribute

本文开发(python)相关术语:python基础教程 python多线程 web开发工程师 软件开发工程师 软件开发流程

主题: DebianSQLPerlPython
分页:12
转载请注明
本文标题:Generate random data for your applications with Elizabeth
本站链接:http://www.codesec.net/view/534349.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(python) | 评论(0) | 阅读(41)