轻松生成测试接口数据-python faker

常用方法

name() 生成随机名字

random_int() 整数
random_digit() 0-9 的随机数字
random_digit_not_null() 1-9的随机数字

random_digit_or_empty() 0-9 的随机数字 或''空字符

random_number(digits=None, fix_len=False) 随机数,digist 最大值,fix_len 固定长度
random_letter() 随机字母a-z A-Z

random_element(elements=('a', 'b', 'c')) 随机元素,如果elements是字典,可以设置权重

random_element({"{{variable_1}}": 0.5, "{{variable_2}}": 0.2, "{{variable_3}}": 0.2, "
{{variable_4}}": 0.1})

will have the following distribution:
    * `variable_1`: 50% probability
    * `variable_2`: 20% probability
    * `variable_3`: 20% probability
    * `variable_4`: 10% probability

text(max_nb_chars=200, ext_word_list=None) 生成随机文当,默认200个字符,可以传入ext_word_listlist替换默认库来指定随机内容

sentences(nb=3, ext_word_list=None)生成随机句子
paragraph()、paragraphs()生成随机段落

phone_number() 生成随机电话号码

simple_profile()生成一个简单的用户数据

{'username': 'chao01', 'name': '劳桂兰', 'mail': '[email protected]', 'birthdate': '2004-12-29', 'address': '建国市魏路B座 492445', 'sex': 'F'}

profile()生成一个详细的用户数据

{'current_location': (Decimal('-27.659994'), Decimal('-53.784111')), 'username': 'yangjun', 'company': '太极网络有限公司', 'blood_group': '0+', 'sex': 'F', 'birthdate': '1975-02-05', 'address': '佳市仇街Q座 837357', 'job': 'Outdoor activities/education manager', 'ssn': '350723199112018162', 'residence': '柳市濮路l座 914446', 'mail': '[email protected]', 'name': '盛明', 'website': ['https://www.lai.com/', 'http://www.su.com/', 'http://jiang.cn/']}

ssn() 序列号

地点

city_suffix() 城市后缀

street_suffix() 街道后缀

building_number() 楼栋号

city() 城市

street_name() 街道名

street_address() 街道地址

address() 地址

postcode() 邮编

country() 国家

latitude()
longitude()

日期和时间

date_time() 日期时间

date(pattern='%Y-%m-%d') 日期

date_object() date对象

time(pattern='%H:%M:%S') 时间 默认是24小时制

time_object() 时间对象

profile() 生成一个详细的用户数据

future_datetime(end_date='+30d', tzinfo=None)

Get a DateTime object based on a random date between 1 second form now and a given date.
Accepts date strings that can be recognized by strtotime()

future_date(end_date='+30d', tzinfo=None)

Get a Date object based on a random date between 1 day from now and a given date.
Accepts date strings that can be recognized by strtotime().

past_datetime(start_date='-30d', tzinfo=None)

Get a DateTime object based on a random date between a given date and 1 second ago.
Accepts date strings that can be recognized by strtotime().

past_date(start_date='-30d', tzinfo=None)

Get a Date object based on a random date between a given date and 1 day ago.
Accepts date strings that can be recognized by strtotime().

date_time_between(start_date='-30y', end_date='now', tzinfo=None) 指定区间内的时间,默认是过去30天内

date_time_between_dates(datetime_start=None, datetime_end=None, tzinfo=None) 指定区间内的时间

date_time_this_year(before_now=True, after_now=False, tzinfo=None) 当年内时间

date_time_this_month(before_now=True, after_now=False, tzinfo=None) 当月内时间

文件

file_path(depth=1, category=None, extension=None) 生成带路径的文件,默认文件路径深度为1,类别和扩展名

信用卡

credit_card_number() 信用卡号码

公司

company() 公司

网路

email() 邮箱
safe_email() company_email()
user_name()
url()
ipv4() ipv6()
mac_address()
image_url()

python数据类型

pybool() 布尔型

pystr(min_chars=None, max_chars=20) 生成字符串,默认最大长度为20,大小写随机
pyint() 整数
pyfloat(left_digits=None, right_digits=None, positive=False) 生成浮点数,可以指定小数点左右数字的位数,正负

pydecimal(left_digits=None, right_digits=None, positive=False) 生成十进制小数
pydict(nb_elements=10, variable_nb_elements=True, *value_types) 生成字典

你可能感兴趣的:(轻松生成测试接口数据-python faker)