python Faker 批量生成数据

转自:python Faker 包常用法整理_faker包-CSDN博客

关于python Faker包用法整理

基本用法
from faker import Faker # 导入第三方包
fake = Faker(“zh_CN”) # 实例化方法,这是中文的,也可以多种语言
fake = Faker([“zh_CN”, “ja_JP”]) # 这种写法也可以

常用用法
fake.name() # 姓名
fake.address() # 地址
fake.city() # 城市
fake.country() # 国家
fake.phone_numer() # 手机号码
fake.ssn() # 身份证
print(fake.ssn(min_age=18, max_age=90)) # 带性别获取参数
fake.company() # 公司名字

地址相关
print(fake.address()) # 详细的地址 如:重庆市石家庄市沙市长春路p座
print(fake.building_number()) # 如:J座
print(fake.city()) # 城市 如:长沙市
print(fake.city_name()) # 城市 如 :长沙
print(fake.city_suffix()) # 城市后缀名 如 :市
print(fake.country()) # 国家名称 朝鲜
print(fake.country_code(representation=“alpha-2”)) # 国家编号 如MK
print(fake.district()) # 区 如: 开福区
print(fake.postcode()) # 邮政编码 如:51000
print(fake.province()) # 省 如:河南省
print(fake.street_address()) # 街道地址 如: 跛子街5号
print(fake.street_name()) # 街道名称 如: 跛子街
print(fake.street_suffix()) # 街道后缀 如:街

时间相关 --时间相关的操作非常多,基本上什么样的操作支持
print(fake.year()) # 某年
print(fake.month()) # 第几月
print(fake.day_of_month()) # 几号
print(fake.month_name()) # 月份名称
print(fake.day_of_week()) # 星期几
print(fake.am_pm()) # AM或PM 如:‘PM’
print(fake.century()) # 世纪# ‘XII’
print(fake.date(pattern=“%Y-%m-%d”, end_datetime=None)) # 日期字符串(可设置格式和最大日期) 如:‘1990-05-13’
print(fake.date_between(start_date=“-30y”, end_date=“today”)) # 日期(可设置限定范围) 如:datetime.date(2014, 8, 17)
print(fake.date_between_dates(date_start=None, date_end=None)) # 同上
print(fake.date_object(end_datetime=None) # 日期(可设置最大日期)
print(fake.date_of_birth(tzinfo=None, minimum_age=0, maximum_age=100)) # 出生日期 如:datetime.date(1931, 12, 8)
print(fake.date_this_century(before_today=True, after_today=False)) # 本世纪日期 如:datetime.date(2003, 5, 4)
print(fake.date_this_decade(before_today=True, after_today=False)) # 本年代中的日期 如: datetime.date(2014, 1, 29)
print(fake.date_this_month(before_today=True, after_today=False)) # 本月中的日期 如: datetime.date(2022, 08, 05)
print(fake.date_this_year(before_today=True, after_today=False)) # 本年中的日期 如: datetime.date(2019, 3, 6)
print(fake.date_time(tzinfo=None, end_datetime=None)) # 日期和时间 如: datetime.datetime(1987-02-02 13:09:31)
print(fake.date_time_between(start_date=“-30y”, end_date=“now”, tzinfo=None)) # 日期时间(可设置限定范围)
print(fake.date_time_between_dates(datetime_start=None, datetime_end=None, tzinfo=None)) # 同上
print(fake.date_time_this_century(before_now=True, after_now=False, tzinfo=None)) # 本世纪中的日期和时间
print(fake.date_time_this_decade(before_now=True, after_now=False, tzinfo=None)) # 本年代中的日期和时间
print(fake.date_time_this_month(before_now=True, after_now=False, tzinfo=None)) # 本月中的日期和时间
print(fake.date_time_this_year(before_now=True, after_now=False, tzinfo=None)) # 本年中的日期和时间
print(fake.future_date(end_date=“+30d”, tzinfo=None)) # 未来日期
print(fake.future_datetime(end_date=“+30d”, tzinfo=None)) # 未来日期和时间
print(fake.iso8601(tzinfo=None, end_datetime=None)) # iso8601格式日期和时间
print(fake.past_date(start_date=“-30d”, tzinfo=None)) # 过去日期
print(fake.past_datetime(start_date=“-30d”, tzinfo=None)) # 过去日期和时间
print(fake.time(pattern=“%H:%M:%S”, end_datetime=None)) # 时间(可设置格式和最大日期时间)
print(fake.time_delta(end_datetime=None)) # 时间间隔
print(fake.time_object(end_datetime=None)) # 时间(可设置最大日期时间)
print(fake.time_series(start_date=“-30d”, end_date=“now”, precision=None, distrib=None, tzinfo=None))
print(fake.timezone()) # 时区
print(fake.unix_time(end_datetime=None, start_datetime=None)) # UNIX时间戳

银行相关
print(fake.bank_country()) # 银行所属国家 如:GB
print(fake.bban()) # 基本银行账号 如:NWOO38920100806369
print(fake.iban()) # 国际银行代码 如: GB60IMDE10095414103482
print(fake.credit_card_expire(start=“now”, end=“+10y”, date_format=“%m/%y”)) # 过期年月 如:‘12/29’
print(fake.credit_card_full(card_type=None)) # 完整信用卡信息
如:VISA 19 digit | 慧 徐 | 4048905798435485388 | 04/28 | CVC: 408
print(fake.credit_card_number(card_type=None)) # 信用卡卡号 如:‘3589756832646905’
print(fake.credit_card_provider(card_type=None)) # 信用卡提供商 如:ISA 19 digit
print(fake.credit_card_security_code(card_type=None)) # 信用卡安全码 如:760
print(fake.currency()) # 货币代码+名称 如:(‘PHP’, ‘Philippine peso’)
print(fake.currency_code()) # 货币代码 如:VND
print(fake.currency_name()) # 货币名称 如: Eastern Caribbean dollar

网络 邮箱
print(fake.free_email()) # 免费邮箱 如:gangqiu@gmail.com
print(fake.ascii_company_email()) # 企业邮箱(ascii编码) 如:rdu@zo.cn
print(fake.ascii_email()) # 企业邮箱+免费邮箱(ascii编码) 如:ping44@gmail.com
print(fake.ascii_free_email()) # 免费邮箱(ascii编码) 如: jie67@yahoo.com
print(fake.ascii_safe_email()) # 安全邮箱(ascii编码) 如: ggong@example.org
print(fake.company_email()) # 企业邮箱 如: shaoli@chaoyang.cn
print(fake.domain_name(levels=1)) # 域名 如:najing.cn
print(fake.domain_word()) # 二级域名 如: shen
print(fake.email()) # 企业邮箱+免费邮箱 如: guiying06@hotmail.com
print(fake.free_email_domain()) # 免费邮箱域名 如:hotmail.com
print(fake.hostname()) # 主机名 如:lt-03.gangdeng.net
print(fake.image_url(width=None, height=None)) # 图片URL 如: https://www.lorempixel.com/546/372
print(fake.ipv4(network=False, address_class=None, private=None)) # ipv4 如:53.167.120.236
print(fake.ipv4_network_class()) # ipv4网络等级 如: ‘b’
print(fake.ipv4_private(network=False, address_class=None)) # 私有ipv4 如: ‘192.168.144.0’
print(fake.ipv4_public(network=False, address_class=None)) # 公共ipv4# 如:‘166.51.178.162’
print(fake.ipv6(network=False)) # ipv6 如: ‘ed76:e285:a850:78a4:4f5d:3e57:bf4b:9622’
print(fake.mac_address()) # MAC地址 如: ad:61:c0:82:ce:5e
print(fake.safe_email()) # 安全邮箱 如:xiahu@example.net
print(fake.slug()) # URL中的slug 如:
print(fake.tld()) # 顶级域名 如:cn
print(fake.uri()) # URI 如: http://www.xo.cn/post/
print(fake.uri_extension()) # URI扩展 如:.php
print(fake.uri_page()) # URI页 如: home
print(fake.uri_path(deep=None)) # URI路径 如:wp-content/search
print(fake.url(schemes=None)) # URL 如:http://www.tao.net/
print(fake.user_name()) # 用户名 如: jfu

颜色
print(fake.color_name()) # 颜色名称 如: Cornsilk
print(fake.hex_color()) # 颜色十六进制值 如: #c4ffee
print(fake.rgb_color()) # 颜色RGB值 如: 186,165,100
print(fake.rgb_css_color()) # CSS颜色值 如: rgb(33,172,200)
print(fake.safe_color_name()) # 安全色 如: navy
print(fake.safe_hex_color()) # 安全色十六进制值 如: #44cc88

经纬度
print(fake.coordinate(center=None, radius=0.001)) # 坐标 如:105.414809
print(fake.latitude()) # 纬度 如:27.122281
print(fake.latlng()) # 经纬度 如: (Decimal(‘-34.230344’), Decimal(‘139.780765’))
print(fake.local_latlng(country_code=“US”, coords_only=False)) # 返回某个国家某地的经纬度 如:(‘33.44872’, ‘-86.78777’, ‘Vestavia Hills’, ‘US’, ‘America/Chicago’)
print(fake.location_on_land(coords_only=False)) # 返回地球上某个位置的经纬度 如: (‘54.84444’, ‘38.16694’, ‘Kashira’, ‘RU’, ‘Europe/Moscow’)
print(fake.longitude()) # 经度 如:158.773972
 

另附:python完美测试数据之faker - 知乎

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值