标签:prefix doc 应该 type sha1 env 专业 lower method
Faker
,它解决的问题是python
模拟(随机)数据!不知道大家在工作中没有用到过假数据,特别前后端开发的人员,应该经常用到,前端人员页面展示,效果展示。后端人员数据库数据模拟。今天给大家介绍的这个项目完美的解决了这个方案,可以模拟多种语言的数据,中文,英文,日语,韩语等等。有兴趣的小伙伴可以下载尝试一下。
pip install Faker
使用faker.Faker()初始化,可通过访问你想要的数据类型来命名的属性生成你要的数据。
from faker import Faker fake = Faker() fake.name() # ‘Lucy Cechtelar‘ fake.address() # ‘426 Jordy Lodge # Cartwrightshire, SC 88120-6700‘ fake.text() # ‘Sint velit eveniet. Rerum atque repellat voluptatem quia rerum. Numquam excepturi # beatae sint laudantium consequatur. Magni occaecati itaque sint et sit tempore. Nesciunt # amet quidem. Iusto deleniti cum autem ad quia aperiam. # A consectetur quos aliquam. In iste aliquid et aut similique suscipit. Consequatur qui # quaerat iste minus hic expedita. Consequuntur error magni et laboriosam. Aut aspernatur # voluptatem sit aliquam. Dolores voluptatum est. # Aut molestias et maxime. Fugit autem facilis quos vero. Eius quibusdam possimus est. # Ea quaerat et quisquam. Deleniti sunt quam. Adipisci consequatur id in occaecati. # Et sint et. Ut ducimus quod nemo ab voluptatum.‘
from faker import Faker fake = Faker("zh-CN") fake.name() # ‘张柳‘ fake.address() # ‘黑龙江省辽阳县江北李路C座 461467‘ fake.text() # ‘继续浏览音乐行业国内什么.任何同时专业但是人民而且无法.认为大家的是更新. 数据设备日本更多.生活发表一般最大一下.状态得到游戏今天喜欢. 专业无法工作这么文化如此感觉教育.工程全部详细注意.现在增加女人一些日本觉得不过. 感觉原因全部感觉表示.质量所以管理但是因此.图片都是一种注册表示主要汽车影响. 质量喜欢有关希望更多.已经那个更多决定运行. 系列名称完全研究女人没有企业.‘
可以自定义不同的语言,也可以输出多种语言,这里我们就展示中英文,有兴趣的可以去查看官方文档。
from faker import Faker from faker.providers import internet fake = Faker() fake.add_provider(internet) print(fake.ipv4_private()) # ‘192.168.91.234‘
随机生成IP地址,每次产生不同的(随机)结果。
faker [-h] [--version] [-o output] [-l {bg_BG,cs_CZ,...,zh_CN,zh_TW}] [-r REPEAT] [-s SEP] [-i {package.containing.custom_provider otherpkg.containing.custom_provider}] [fake] [fake argument [fake argument ...]]
Where:
faker
: is the script when installed in your environment, in development you could use python -m faker
instead-h, --help
: 显示帮助文档--version
: 显示版本信息-o FILENAME
: 将输出重定向到指定的文件名中。-l {bg_BG,cs_CZ,...,zh_CN,zh_TW}
: 允许自定义语言,一种或多种语言。-r REPEAT
: 指定输出的数量-s SEP
: 每次生成输出后,会生成指定的字符-i {my.custom_provider other.custom_provider}
list of additional custom providers to use. Note that is the import path of the package containing your Provider class, not the custom Provider class itself.fake
: 用于生成输出(例如名称、地址或文本)的伪名称[fake argument ...]
: 传递给fake的可选参数$ faker address 968 Bahringer Garden Apt. 722 Kristinaland, NJ 09890 $ faker -l de_DE address Samira-Niemeier-Allee 56 94812 Biedenkopf $ faker profile ssn,birthdate {‘ssn‘: u‘628-10-1085‘, ‘birthdate‘: ‘2008-03-29‘} $ faker -r=3 -s=";" name Willam Kertzmann; Josiah Maggio; Gayla Schmitt;
如果不想使用默认数据,可以提供自己的单词集。
fake = Faker() my_word_list = [ ‘danish‘,‘cheesecake‘,‘sugar‘, ‘Lollipop‘,‘wafer‘,‘Gummies‘, ‘sesame‘,‘Jelly‘,‘beans‘, ‘pie‘,‘bar‘,‘Ice‘,‘oat‘ ] fake.sentence() # ‘Expedita at beatae voluptatibus nulla omnis.‘ fake.sentence(ext_word_list=my_word_list) # ‘Oat beans oat Lollipop bar cheesecake.‘
常用方法:
from faker import Faker from faker.providers import internet fake = Faker("zh-CN") # 产生随机手机号 print(fake.phone_number()) # 产生随机姓名 print(fake.name()) # 产生随机地址 print(fake.address()) # 随机产生国家名 print(fake.country()) # 随机产生国家代码 print(fake.country_code()) # 随机产生城市名 print(fake.city_name()) # 随机产生城市 print(fake.city()) # 随机产生省份 print(fake.province()) # 产生随机email print(fake.email()) # 产生随机IPV4地址 print(fake.ipv4()) # 产生长度在最大值与最小值之间的随机字符串 print(fake.pystr(min_chars=0, max_chars=8)) # 随机产生车牌号 print(fake.license_plate()) # 随机产生颜色 print(fake.rgb_color()) # rgb print(fake.safe_hex_color()) # 16进制 print(fake.color_name()) # 颜色名字 print(fake.hex_color()) # 16进制 # 随机产生公司名 print(fake.company()) # 随机产生工作岗位 print(fake.job()) # 随机生成密码 print(fake.password(length=10, special_chars=True, digits=True, upper_case=True, lower_case=True)) # 随机生成uuid print(fake.uuid4()) # 随机生成sha1 print(fake.sha1(raw_output=False)) # 随机生成md5 print(fake.md5(raw_output=False)) # 随机生成女性名字 print(fake.name_female()) # 男性名字 print(fake.name_male()) # 随机生成名字 print(fake.name()) # 生成基本信息 print(fake.profile(fields=None, sex=None)) print(fake.simple_profile(sex=None)) # 随机生成浏览器头user_agent print(fake.user_agent()) # 随机产生时间 月份 print(fake.month_name()) # ‘May‘ print(fake.date_time_this_century(before_now=True, after_now=False, tzinfo=None)) # 2005-10-08 08:32:02 print(fake.time_object(end_datetime=None)) # 06:45:11 print(fake.date_time_between(start_date="-10y", end_date="now", tzinfo=None)) # 2012-08-25 03:07:38 print(fake.future_date(end_date="+30d", tzinfo=None)) # 2020-04-25 print(fake.date_time(tzinfo=None, end_datetime=None)) # 2002-09-01 18:27:45 print(fake.date(pattern="%Y-%m-%d", end_datetime=None)) # ‘1998-08-02‘ print(fake.date_time_this_month(before_now=True, after_now=False, tzinfo=None)) # 2020-04-03 16:03:21 print(fake.timezone()) # ‘Africa/Addis_Ababa‘ print(fake.date_time_this_decade(before_now=True, after_now=False, tzinfo=None)) # 2020-01-09 01:15:08 print(fake.month()) # ‘04‘ print(fake.day_of_week()) # ‘Sunday‘ print(fake.iso8601(tzinfo=None, end_datetime=None)) # ‘1988-02-28T09:22:29‘ print(fake.date_object(end_datetime=None)) # 2017-06-26 print(fake.date_this_decade(before_today=True, after_today=False)) # 2020-03-30 fake.date_this_century(before_today=True, after_today=False) # datetime.date(2000, 6, 1) fake.date_this_month(before_today=True, after_today=False) # datetime.date(2018, 6, 13) fake.am_pm() # ‘AM‘ fake.past_datetime(start_date="-30d", tzinfo=None) # datetime.datetime(2018, 6, 25, 7, 41, 34) fake.date_this_year(before_today=True, after_today=False) # datetime.date(2018, 2, 24) fake.date_time_between_dates(datetime_start=None, datetime_end=None, tzinfo=None) # datetime.datetime(2018, 6, 26, 14, 40, 5) fake.date_time_ad(tzinfo=None, end_datetime=None) # datetime.datetime(673, 1, 28, 18, 17, 55) fake.date_between_dates(date_start=None, date_end=None) # datetime.date(2018, 6, 26) fake.future_datetime(end_date="+30d", tzinfo=None) # datetime.datetime(2018, 7, 4, 10, 53, 6) fake.century() # ‘IX‘ fake.past_date(start_date="-30d", tzinfo=None) # datetime.date(2018, 5, 30) fake.time(pattern="%H:%M:%S", end_datetime=None) # ‘01:32:14‘ fake.day_of_month() # ‘19‘ fake.unix_time(end_datetime=None, start_datetime=None) fake.date_time_this_year(before_now=True, after_now=False, tzinfo=None) # datetime.datetime(2018, 5, 24, 11, 25, 25) fake.date_between(start_date="-30y", end_date="today") # datetime.date(2003, 1, 11) fake.year() # ‘1993‘ fake.time_series(start_date="-30d", end_date="now", precision=None, distrib=None, tzinfo=None) # <generator object time_series at 0x7f44e702a620> # 随机产生文件 fake.file_extension(category=None) # ‘xls‘ print(fake.file_name(category=None, extension=None)) # 那么.mov fake.file_path(depth=1, category=None, extension=None) # ‘/教育/客户.js‘ fake.unix_device(prefix=None) # ‘/dev/sdf‘ print(fake.unix_partition(prefix=None)) # ‘/dev/vdv4‘ print(fake.mime_type(category=None)) # ‘message/imdn+xml‘
开源地址: https://github.com/joke2k/fakerv
项目文档:https://faker.readthedocs.io/en/master/
标签:prefix doc 应该 type sha1 env 专业 lower method
原文地址:https://www.cnblogs.com/xingxia/p/python_faker.html