GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing pbpython.com — Generating fake data with barnum - Practical Business Python IntroductionSeveral years ago, I developed a very simple program called barnum to generate fake data that could be used to test applications. Over the years, I had forgotten about it. With the recent closing of Google code, I decided to take the opportunity to move the code to github and see if it might be useful to people. MotivationI am moving the code and re-announcing it for a couple of reasons:
Basic UsageBarnum will allow you to create the following types of data which can be used to test your own applications :
Here is the basic usage and some of the unique aspects of barnum. from barnum import gen_data Create some fake names gen_data.create_name() ('Arnoldo', 'Ulmer')
gen_data.create_name() ('Louisa', 'Foy')
gen_data.create_name(full_name=False) 'Gayla' You can also specify the gender gen_data.create_name(gender='female') ('Mandy', 'Pena')
We can also create job titles based on US Census data gen_data.create_job_title() 'Security Coordinator Computer' One of barnum’s unique capabilities is that there is some intelligence to the data creation. We can pass in a US Zip code and barnum will use a valid area code in the fake data. gen_data.create_phone(zip_code="55082") '(612)242-2894' gen_data.create_phone() '(863)265-6706' We can use zip codes for address data. gen_data.create_city_state_zip() ('12136', 'Old Chatham', 'NY')
gen_data.create_city_state_zip(zip_code="55112") ('55112', 'Saint Paul', 'MN')
Barnum can create fake sentences and paragraphs as well as nouns for all your data population needs. gen_data.create_sentence() 'Aliquip vulputate consequat suscipit amet adipiscing molestie dignissim nulla molestie hendrerit.' gen_data.create_paragraphs() 'Illum eros et eu ad ipsum vulputate. Delenit commodoconsequat delenitaugue molestie iustoodio nonummy ut erat duis feugait. Doloremagna Utwisi aliquip molestie erat suscipit. Nonummy exerci eufeugiat illum vel nislut nisl at dolor at. nn' gen_data.create_nouns(max=4) 'rifle giraffe nerve kettle' There is some date creation capability as well. gen_data.create_date() datetime.datetime(2025, 1, 12, 19, 36, 25, 639016) gen_data.create_date(past=True) datetime.datetime(2014, 2, 23, 19, 37, 29, 323165) gen_data.create_date(max_years_future=2) datetime.datetime(2016, 11, 17, 19, 37, 52, 674284) gen_data.create_birthday(min_age=2, max_age=75) datetime.date(2007, 3, 25) Create email and company name info. gen_data.create_email() '[email protected]' gen_data.create_email(tld="net") '[email protected]' gen_data.create_email(name=("Fred","Jones")) '[email protected]' gen_data.create_company_name() 'Application Telecom Inc' gen_data.create_company_name(biz_type="LawFirm") 'Marion, Navarro & Quintero LLP' gen_data.create_company_name(biz_type="Generic") 'Application Data Direct Limited' Finally, you can also create credit card numbers and simple passwords. gen_data.cc_number() ('visa', ['4716823823471406'])
gen_data.cc_number(card_type="mastercard") ('mastercard', ['5531134290292667'])
gen_data.create_pw() 'W7jWw4kn' gen_data.create_pw(length=10) '4KvqFS8Znu' CustomizationOne final component available to you is that you can customize the data used to
create your “random” results. Within the source-data directory, there are several
text files. If you choose to customize the files, you can update them and use the
Next StepsI know there are a lot of areas where this code can be improved. I’m hopeful that placing it on github will breathe some new life into it. However, if there’s no real interest in it, I’ll be able to rest easier knowing that it is being hosted somewhere where others can use it. Enjoy!
Tags
barnum
Comments |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |