数据生成 faker
faker是一个用来生成随机数据的一个第三方模块
1. 安装
pip install faker
2. 使用
from faker import Faker #本地化,生成的数据都是中文 #默认的话是英文 faker = Faker('zh_CN') name = faker.name()
上面的代码就可以随机成生一个中文名字了
Faker初始化的时候可以传入本地化的语言,其实支持很多,这里只列几个常用的
- 简体中文:zh_CN
- 繁体中文:zh_TW
- 英文:en_US
- 德文:de_DE
- 日文:ja_JP
- 韩文:ko_KR
- 法文:fr_FR
拿到faker对象,就可以随意的生成数据了,可以写一段脚本来测试,他能生成哪些数据
from faker import Faker faker = Faker('zh_CN') method_list = [item for item in dir(faker) if not item.startswith('_')] print(method_list) with open('out.txt', 'w') as f: for item in method_list: try: func = getattr(faker, item) ret = func() f.write('>>>faker.%s\n%s\ntype:%s\n' % (item, str(ret)[:200], type(ret))) except: pass
脚本测试结果如下
>>>faker.address 北京市嘉禾市华龙王街m座 541019 type:<class 'str'> >>>faker.am_pm AM type:<class 'str'> >>>faker.android_platform_token Android 5.0.1 type:<class 'str'> >>>faker.ascii_company_email xia42@tangdu.org type:<class 'str'> >>>faker.ascii_email yuanxiuying@yahoo.com type:<class 'str'> >>>faker.ascii_free_email jun94@yahoo.com type:<class 'str'> >>>faker.ascii_safe_email gang87@example.com type:<class 'str'> >>>faker.bank_country GB type:<class 'str'> >>>faker.bban UHNL95736701772025 type:<class 'str'> >>>faker.binary b'&\xc5\x9d\xfb\x9a\xf0\xef\xd2\xf5\x815`\xbd3\xa0\xecVV&\x97\xb4jf\xb3\xb2\x9a]\xe9R\xde,q&\xa1~P4\x1f\xaa}\x9c?\xa8\xe5\xb3!\xb2\x14\xae\xb1^1\xbe\xbb+\x96@\x8en_&?L3z\xb5wY\x00d2n\xb0\xe7\xf9\x06\x type:<class 'bytes'> >>>faker.boolean False type:<class 'bool'> >>>faker.bothify 89 xg type:<class 'str'> >>>faker.bs enable dynamic interfaces type:<class 'str'> >>>faker.building_number l座 type:<class 'str'> >>>faker.catch_phrase Switchable disintermediate collaboration type:<class 'str'> >>>faker.century X type:<class 'str'> >>>faker.chrome Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.1 (KHTML, like Gecko) Chrome/59.0.883.0 Safari/536.1 type:<class 'str'> >>>faker.city 台北市 type:<class 'str'> >>>faker.city_name 合山 type:<class 'str'> >>>faker.city_suffix 县 type:<class 'str'> >>>faker.color #8ae1f7 type:<class 'str'> >>>faker.color_name Azure type:<class 'str'> >>>faker.company 晖来计算机网络有限公司 type:<class 'str'> >>>faker.company_email yong06@juanguiying.cn type:<class 'str'> >>>faker.company_prefix 菊风公司 type:<class 'str'> >>>faker.company_suffix 科技有限公司 type:<class 'str'> >>>faker.coordinate 124.736326 type:<class 'decimal.Decimal'> >>>faker.country 洪都拉斯 type:<class 'str'> >>>faker.country_calling_code +93 type:<class 'str'> >>>faker.country_code IE type:<class 'str'> >>>faker.credit_card_expire 04/29 type:<class 'str'> >>>faker.credit_card_full VISA 13 digit 强 马 4088764586450 04/27 CVC: 938 type:<class 'str'> >>>faker.credit_card_number 4964597059370214 type:<class 'str'> >>>faker.credit_card_provider Mastercard type:<class 'str'> >>>faker.credit_card_security_code 029 type:<class 'str'> >>>faker.cryptocurrency ('FTH', 'Feathercoin') type:<class 'tuple'> >>>faker.cryptocurrency_code DOGE type:<class 'str'> >>>faker.cryptocurrency_name Coinye type:<class 'str'> >>>faker.csv "杨璐","湖南省辉市沙湾班路o座 278780" "田婷","江西省六安县华龙谢路Y座 297123" "李丽娟","甘肃省宁县徐汇拉萨路C座 252543" "王玉兰","福建省西安市金平聂路U座 201565" "孙桂珍","北京市台北市锡山香港路m座 412540" "张小红","重庆市凤兰县清浦潮州街k座 382764" "辛坤","香港特别行政区桂香县白云冯街m座 3858 type:<class 'str'> >>>faker.currency ('LTL', 'Lithuanian litas') type:<class 'tuple'> >>>faker.currency_code KZT type:<class 'str'> >>>faker.currency_name Samoan tālā type:<class 'str'> >>>faker.currency_symbol $ type:<class 'str'> >>>faker.date 2004-10-31 type:<class 'str'> >>>faker.date_between 2005-10-30 type:<class 'datetime.date'> >>>faker.date_between_dates 2020-06-09 type:<class 'datetime.date'> >>>faker.date_object 2003-10-04 type:<class 'datetime.date'> >>>faker.date_of_birth 2018-06-07 type:<class 'datetime.date'> >>>faker.date_this_century 2012-01-21 type:<class 'datetime.date'> >>>faker.date_this_decade 2020-02-11 type:<class 'datetime.date'> >>>faker.date_this_month 2020-06-04 type:<class 'datetime.date'> >>>faker.date_this_year 2020-02-14 type:<class 'datetime.date'> >>>faker.date_time 1996-02-16 23:38:25 type:<class 'datetime.datetime'> >>>faker.date_time_ad 0645-06-29 21:36:30 type:<class 'datetime.datetime'> >>>faker.date_time_between 2014-11-29 09:22:22 type:<class 'datetime.datetime'> >>>faker.date_time_between_dates 2020-06-09 11:18:32 type:<class 'datetime.datetime'> >>>faker.date_time_this_century 2006-10-17 23:20:46 type:<class 'datetime.datetime'> >>>faker.date_time_this_decade 2020-04-14 13:47:46 type:<class 'datetime.datetime'> >>>faker.date_time_this_month 2020-06-04 15:52:51 type:<class 'datetime.datetime'> >>>faker.date_time_this_year 2020-01-05 04:29:40 type:<class 'datetime.datetime'> >>>faker.day_of_month 27 type:<class 'str'> >>>faker.day_of_week Monday type:<class 'str'> >>>faker.dga klorextgqnksrrfelrecxqunssjksghldxjdagveyydcb.cn type:<class 'str'> >>>faker.district 永川 type:<class 'str'> >>>faker.domain_name weimao.cn type:<class 'str'> >>>faker.domain_word xutao type:<class 'str'> >>>faker.dsv "李瑞","宁夏回族自治区梧州县秀英宋路F座 834093" "林瑞","河北省北镇市海港曾路S座 857351" "李宁","海南省春梅市翔安黄街q座 816193" "胡晨","青海省佛山县徐汇阎街H座 431690" "何玉珍","福建省洋市和平贵阳路y座 416088" "梁娜","台湾省柳州县和平萧路t座 434094" "马建华","湖北省丽娟市西夏杨街h座 317537" type:<class 'str'> >>>faker.ean 4035184918854 type:<class 'str'> >>>faker.ean13 3475469039095 type:<class 'str'> >>>faker.ean8 60246110 type:<class 'str'> >>>faker.email cuijuan@yahoo.com type:<class 'str'> >>>faker.file_extension mov type:<class 'str'> >>>faker.file_name 工程.json type:<class 'str'> >>>faker.file_path /经济/同时.html type:<class 'str'> >>>faker.firefox Mozilla/5.0 (Android 7.0; Mobile; rv:6.0) Gecko/6.0 Firefox/6.0 type:<class 'str'> >>>faker.first_name 红梅 type:<class 'str'> >>>faker.first_name_female 玉兰 type:<class 'str'> >>>faker.first_name_male 涛 type:<class 'str'> >>>faker.first_romanized_name Guiying type:<class 'str'> >>>faker.free_email yaoming@gmail.com type:<class 'str'> >>>faker.free_email_domain hotmail.com type:<class 'str'> >>>faker.future_date 2020-07-08 type:<class 'datetime.date'> >>>faker.future_datetime 2020-06-16 09:10:00 type:<class 'datetime.datetime'> >>>faker.get_providers [<faker.providers.user_agent.Provider object at 0x10aefa350>, <faker.providers.ssn.zh_CN.Provider object at 0x10a04e250>, <faker.providers.python.Provider object at 0x10aed0190>, <faker.providers.prof type:<class 'list'> >>>faker.hex_color #a0038f type:<class 'str'> >>>faker.hexify cd0b type:<class 'str'> >>>faker.hostname lt-58.14.com type:<class 'str'> >>>faker.http_method OPTIONS type:<class 'str'> >>>faker.iban GB77QJGC72286814172692 type:<class 'str'> >>>faker.image_url https://placekitten.com/726/499 type:<class 'str'> >>>faker.internet_explorer Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 5.0; Trident/3.0) type:<class 'str'> >>>faker.ios_platform_token iPhone; CPU iPhone OS 5_1_1 like Mac OS X type:<class 'str'> >>>faker.ipv4 20.211.54.204 type:<class 'str'> >>>faker.ipv4_network_class c type:<class 'str'> >>>faker.ipv4_private 172.17.33.255 type:<class 'str'> >>>faker.ipv4_public 129.154.253.39 type:<class 'str'> >>>faker.ipv6 ab38:6799:1873:e953:c44c:83bd:c0a1:8140 type:<class 'str'> >>>faker.isbn10 0-392-66447-X type:<class 'str'> >>>faker.isbn13 978-1-80501-448-5 type:<class 'str'> >>>faker.iso8601 2001-07-20T22:23:22 type:<class 'str'> >>>faker.items odict_items([('zh_CN', <faker.generator.Generator object at 0x109e0e310>)]) type:<class 'odict_items'> >>>faker.job 其他 type:<class 'str'> >>>faker.language_code ky type:<class 'str'> >>>faker.last_name 高 type:<class 'str'> >>>faker.last_name_female 覃 type:<class 'str'> >>>faker.last_name_male 任 type:<class 'str'> >>>faker.last_romanized_name Ma type:<class 'str'> >>>faker.latitude -74.544137 type:<class 'decimal.Decimal'> >>>faker.latlng (Decimal('54.1976335'), Decimal('-25.469528')) type:<class 'tuple'> >>>faker.lexify SdoG type:<class 'str'> >>>faker.license_plate J71 2AY type:<class 'str'> >>>faker.linux_platform_token X11; Linux i686 type:<class 'str'> >>>faker.linux_processor i686 type:<class 'str'> >>>faker.local_latlng ('41.47892', '-87.45476', 'Schererville', 'US', 'America/Chicago') type:<class 'tuple'> >>>faker.locale lg_UG type:<class 'str'> >>>faker.location_on_land ('-11.78333', '19.91667', 'Luena', 'AO', 'Africa/Luanda') type:<class 'tuple'> >>>faker.longitude -20.287968 type:<class 'decimal.Decimal'> >>>faker.mac_address 01:81:00:8c:2f:8c type:<class 'str'> >>>faker.mac_platform_token Macintosh; U; PPC Mac OS X 10_9_2 type:<class 'str'> >>>faker.mac_processor U; Intel type:<class 'str'> >>>faker.md5 f6b5a5cc72c6fb1990c7308db411e748 type:<class 'str'> >>>faker.mime_type message/http type:<class 'str'> >>>faker.month 08 type:<class 'str'> >>>faker.month_name October type:<class 'str'> >>>faker.msisdn 9769965350152 type:<class 'str'> >>>faker.name 李帆 type:<class 'str'> >>>faker.name_female 陈梅 type:<class 'str'> >>>faker.name_male 靳畅 type:<class 'str'> >>>faker.null_boolean False type:<class 'bool'> >>>faker.numerify 275 type:<class 'str'> >>>faker.opera Opera/9.59.(X11; Linux i686; mni-IN) Presto/2.9.187 Version/12.00 type:<class 'str'> >>>faker.paragraph 发生更多标准市场电影.可以事情提供科技等级状态. type:<class 'str'> >>>faker.paragraphs ['显示评论威望.', '最新地区新闻我们的话.你的开发投资威望一切合作.', '必须不要解决开始日本准备.出现行业世界专业政府.不断处理提高设备功能.'] type:<class 'list'> >>>faker.password !0sP3jfiMI type:<class 'str'> >>>faker.past_date 2020-05-29 type:<class 'datetime.date'> >>>faker.past_datetime 2020-05-16 00:56:24 type:<class 'datetime.datetime'> >>>faker.phone_number 18124873609 type:<class 'str'> >>>faker.phonenumber_prefix 181 type:<class 'int'> >>>faker.port_number 26197 type:<class 'int'> >>>faker.postcode 441895 type:<class 'str'> >>>faker.prefix type:<class 'str'> >>>faker.prefix_female type:<class 'str'> >>>faker.prefix_male type:<class 'str'> >>>faker.profile {'job': '房地产评估', 'company': '趋势传媒有限公司', 'ssn': '140426197605084103', 'residence': '重庆市杭州市淄川张路i座 944299', 'current_location': (Decimal('-35.591933'), Decimal('34.535153')), 'blood_group': 'O+', 'websit type:<class 'dict'> >>>faker.province 吉林省 type:<class 'str'> >>>faker.psv "袁旭"|"云南省洋县合川广州路e座 770790" "高阳"|"江西省深圳县丰都贵阳街u座 299258" "袁杨"|"新疆维吾尔自治区桂香县安次陈街k座 981561" "高娟"|"安徽省春梅县和平纪路c座 456647" "高龙"|"北京市西安市长寿孙路A座 108810" "刘秀荣"|"北京市海口市花溪澳门街N座 784483" "胡坤"|"北京市婷婷市普陀李路i座 77520 type:<class 'str'> >>>faker.pybool False type:<class 'bool'> >>>faker.pydecimal -264379053.60321 type:<class 'decimal.Decimal'> >>>faker.pydict {'公司': 'SMMlPrGCxfHOTnUIHHcn', '类型': datetime.datetime(1975, 1, 21, 1, 56, 59), '中心': 6630.76, '是否': 'UsjGsRpAiwvGLxOZaFhg', '类别': 'http://wang.cn/faq.php', '男人': 'qiangyang@fi.cn', '朋友': -39431639.0, type:<class 'dict'> >>>faker.pyfloat 464693687794073.0 type:<class 'float'> >>>faker.pyint 3773 type:<class 'int'> >>>faker.pyiterable {'uLEWEBTdYAjrlZiLfsQA', 1316, 'YmuSKIEuyAIlHVBNrSvI', 1239, 'OWYxQEJkwxFBqZIAkiJp', Decimal('-7306.8469155'), 'JYFibskYLTFMlawWnrmR', 1467, 'minsun@55.net', 'aTaQosjPvaMyxdABwiRy'} type:<class 'set'> >>>faker.pylist ['zXAFRJRpxobsvQNBlPCR', 'PFcOWOkDQZHWQocVUvuD', datetime.datetime(1992, 11, 12, 10, 40, 4), 'toJnvHcEGUjIlMxYMdkp', 2068, datetime.datetime(2017, 7, 5, 3, 18, 29)] type:<class 'list'> >>>faker.pyset {'ZqzaPaxkDXDKttrAKysr', 9030, 3535, 'http://www.mr.cn/', datetime.datetime(1998, 12, 28, 10, 10, 23), 'dcsvznnaHIdLpjwOLWgQ'} type:<class 'set'> >>>faker.pystr LpbUPAsrvbuNpqfzwHWC type:<class 'str'> >>>faker.pystr_format H9-0922264u type:<class 'str'> >>>faker.pystruct ([Decimal('5243.2568283385'), 464, 'http://min.cn/', -548963246.67, 6518154197179.6, 'ming46@hotmail.com', 'http://zenggong.cn/author.html', 6294, 63651954694809.0, 'moyong@kong.cn'], {'认为': 'tanjing@ type:<class 'tuple'> >>>faker.pytuple (4544, 'QZMUKDfHeWKUSHnVRbkg', 'WTRdKYutmgvyofVtMGie', 'sujie@nacao.cn', 'azGTDjklqZirPASShGzo', 'FogygNyBUIPPmVStwbhi', 'http://www.57.net/search/list/main/', 'TLBFQlLLDnCmeHfANfBs', 883227735.0, -7. type:<class 'tuple'> >>>faker.random_choices ['b', 'b', 'a'] type:<class 'list'> >>>faker.random_digit 3 type:<class 'int'> >>>faker.random_digit_not_null 9 type:<class 'int'> >>>faker.random_digit_not_null_or_empty type:<class 'str'> >>>faker.random_digit_or_empty 8 type:<class 'int'> >>>faker.random_element b type:<class 'str'> >>>faker.random_elements ['c', 'c'] type:<class 'list'> >>>faker.random_int 725 type:<class 'int'> >>>faker.random_letter q type:<class 'str'> >>>faker.random_letters ['J', 'k', 'U', 'L', 'L', 'D', 'o', 'O', 'E', 'M', 'r', 'i', 'u', 'k', 'd', 'Y'] type:<class 'list'> >>>faker.random_lowercase_letter l type:<class 'str'> >>>faker.random_number 302668 type:<class 'int'> >>>faker.random_sample ['a', 'c'] type:<class 'list'> >>>faker.random_uppercase_letter Y type:<class 'str'> >>>faker.randomize_nb_elements 6 type:<class 'int'> >>>faker.rgb_color 196,56,2 type:<class 'str'> >>>faker.rgb_css_color rgb(242,76,217) type:<class 'str'> >>>faker.romanized_name Ming Li type:<class 'str'> >>>faker.safari Mozilla/5.0 (iPod; U; CPU iPhone OS 4_2 like Mac OS X; byn-ER) AppleWebKit/534.12.3 (KHTML, like Gecko) Version/3.0.5 Mobile/8B115 Safari/6534.12.3 type:<class 'str'> >>>faker.safe_color_name blue type:<class 'str'> >>>faker.safe_email vtian@example.com type:<class 'str'> >>>faker.safe_hex_color #bb2200 type:<class 'str'> >>>faker.seed_instance None type:<class 'NoneType'> >>>faker.sentence 技术一定人民应该阅读拥有. type:<class 'str'> >>>faker.sentences ['单位支持运行企业最大北京.', '留言次数市场作者标题类型.', '怎么发表会员.'] type:<class 'list'> >>>faker.sha1 225e0831b2b1bff0f1a0d25987aa932ada905baf type:<class 'str'> >>>faker.sha256 d1263b09e77b4e2cbad2e13040b84a218dd8bfcb5a1d5a6eb8c4ca2a26247e72 type:<class 'str'> >>>faker.simple_profile {'username': 'pingyuan', 'name': '麻海燕', 'sex': 'M', 'address': '江苏省鹏县闵行张路k座 670326', 'mail': 'dingyan@gmail.com', 'birthdate': datetime.date(1976, 4, 24)} type:<class 'dict'> >>>faker.slug type:<class 'str'> >>>faker.ssn 320982194305315131 type:<class 'str'> >>>faker.street_address 乌鲁木齐街I座 type:<class 'str'> >>>faker.street_name 沈阳路 type:<class 'str'> >>>faker.street_suffix 街 type:<class 'str'> >>>faker.suffix type:<class 'str'> >>>faker.suffix_female type:<class 'str'> >>>faker.suffix_male type:<class 'str'> >>>faker.tar b'YdYNZMXIPJKgRqiwHLTO1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ type:<class 'bytes'> >>>faker.text 等级人员价格欢迎论坛有些投资.之间管理中文更新. 介绍等级音乐很多全国部分安全.来自手机登录因此上海.参加帖子起来方式目前觉得. 没有如此北京一些根据. 回复图片一样安全. 发现当前重要开发的话环境城市.全国时间电影中国不过继续.过程记者发现最新更多. 具有特别然后更多还是.文化一下经营.你们如此人民人民可能. 还是具有市场最后城市.生活使用信息关于最新自己登录.应该分析参加由于国家工程组织. type:<class 'str'> >>>faker.texts ['认为处理这样一直比较组织什么.成功专业以及可是的人不断政府制作.\n评论人民社会地方得到使用.公司希望提供还是信息次数报告.资料拥有功能政府主要.\n语言您的以上行业建设决定.出来或者信息东西拥有.\n所以人民虽然设备使用无法使用.浏览环境参加行业帖子提供东西.部分看到通过首页.\n项目全部用户文件新闻.主要提供这是我们帮助.进入欢迎研究一起您的进入希望.\n文件一种联系.能够不会那些记者.' type:<class 'list'> >>>faker.time 03:25:24 type:<class 'str'> >>>faker.time_delta 0:00:00 type:<class 'datetime.timedelta'> >>>faker.time_object 15:53:01 type:<class 'datetime.time'> >>>faker.time_series <generator object Provider.time_series at 0x10ae87bd0> type:<class 'generator'> >>>faker.timezone America/Bogota type:<class 'str'> >>>faker.tld cn type:<class 'str'> >>>faker.tsv "丁勇" "广西壮族自治区沈阳市黄浦陈路A座 330418" "甘岩" "湖南省深圳市新城宜都路A座 146672" "马彬" "重庆市南宁县西夏刘街L座 980565" "庞斌" "云南省辽阳市朝阳张路Z座 209388" "黄峰" "天津市澳门市牧野兴城路v座 184866" "刘军" "甘肃省南昌县金平太原路e座 185960" "刘建军" "河北省婷婷市清城永安路J座 7200 type:<class 'str'> >>>faker.unix_device /dev/vdq type:<class 'str'> >>>faker.unix_partition /dev/vdz6 type:<class 'str'> >>>faker.unix_time 1101913667 type:<class 'int'> >>>faker.upc_a 640245165753 type:<class 'str'> >>>faker.upc_e 01022205 type:<class 'str'> >>>faker.uri http://yr.org/terms/ type:<class 'str'> >>>faker.uri_extension .jsp type:<class 'str'> >>>faker.uri_page category type:<class 'str'> >>>faker.uri_path blog/blog type:<class 'str'> >>>faker.url http://yuzhao.com/ type:<class 'str'> >>>faker.user_agent Mozilla/5.0 (X11; Linux i686; rv:1.9.7.20) Gecko/2010-08-29 21:05:02 Firefox/3.6.3 type:<class 'str'> >>>faker.user_name jing38 type:<class 'str'> >>>faker.uuid4 300a38a2-fd52-4617-b2b2-95677ee89162 type:<class 'str'> >>>faker.windows_platform_token Windows NT 5.1 type:<class 'str'> >>>faker.word 标题 type:<class 'str'> >>>faker.words ['最新', '国内', '国家'] type:<class 'list'> >>>faker.year 2017 type:<class 'str'> >>>faker.zip b'PK\x03\x04\x14\x00\x00\x00\x00\x00PZ\xc9P\x0fg\xd1\x13\x00\x00\x01\x00\x00\x00\x01\x00\x15\x00\x00\x00QgYjYUbTTIbvZFhsEMhW1)\xb3\xba@\xb7\xdcp\n\xf3\xbe\xffUm=U\xa8\xea\xe5w${\xc9\xbc\x08H^-\x82\xc9 type:<class 'bytes'>

浙公网安备 33010602011771号