Summary of common methods in python-Faker library

It's coming, it's coming, it's coming with the form~~~

The Faker library usage instructions mentioned before, a relatively detailed version is here~~~

Here we mainly list some usages in the Chinese language environment. If you want to know the usage in other language environments, please log in to the official documentation to view.

Faker instance object method usage instructions table with return value reference display
Official document address: https://faker.readthedocs.io/en/master/locales/zh_CN.html
1. Language settings
language code illustrate Instructions
zh_CN Simplified Chinese Faker(locale='zh_CN')
zh_TW traditional Chinese Faker(locale='zh_TW')
in_US English (United States) Faker(location='in_US')
one_GB English (UK) Faker(location='in_GB')
from_OF German Faker(locale='de_DE')
ja_JP Japanese Faker(locale='ja_JP')
ko_KR Korean Faker(locale='ko_KR')
fr_FR French Faker(locale='fr_FR')
... ... For more language settings, please refer to the official documentation.
2. Geographic information
method illustrate Reference return value
city_suffix() administrative unit city
country() nation People's Republic of China
country_code() Country code abbreviation GA (Description: Coding of the Republic of Albania)
district() Area name new city
coordinate() coordinate -73.157439
latitude() Geographical coordinates (latitude) 27.8782985
longitude() Geographical coordinates (longitude) -32.243069
postcode() post code 037000
province() province Hunan Province
address() Address Block C, Muye North Town Road, Shuhua County, Heilongjiang Province 828820
street_address() Street address Block G, Zhu Street
street_name() street name king street
street_suffix() Street (suffix) city
3. Basic information
method illustrate Reference return value
ssn() Generate ID number 511113195907044000
bs() Random company service name monetize B2B supply-chains
company() Random company name (long) Time and Space Box Digital Network Co., Ltd.
company_prefix() Random company name (short) Dimo
company_suffix() Company Type Information Co., Ltd.
credit_card_expire() Random credit card expiration date 11/28
credit_card_full() Generate complete credit card information Discover Lei Wang 6011307077972381 11/25 CVC: 022
credit_card_number() credit card number 639026733282
credit_card_provider() Credit card type JCB 16 digit
credit_card_security_code() Credit card security code 058
job() random positions Materials manager
first_name() first name (first name) Li
first_name_female() Female name (commonly used in English) snow
first_name_male() Male name (commonly used in English) Bo
first_romanized_name() Roman name Ping
last_name() Last name (last name) Thanks
last_name_female() Female surname (commonly used in English) Korea
last_name_male() Male surname (commonly used in English) Gu
last_romanized_name() Last name Feng
name() Randomly generate full name Guo Kun
name_female() Full male name Zheng Guirong
name_male() Female full name Golden Fenglan
romanized_name() Roman name Juan Sun
msisdn() Mobile station international subscriber identification code, that is, the ISDN number of the mobile user 9271661830556
phone_number() Randomly generate mobile phone number 15217915763
phonenumber_prefix() Randomly generate mobile phone number segments 131
4. Account information (in email form)
method illustrate Return value reference
company_email() Random company email [email protected]
email() random mailbox [email protected]
free_email() Random free email [email protected]
free_email_domain() Email suffix hotmail.com
safe_email() safe mailbox [email protected]
5. Basic network information
method illustrate Return value reference
domain_name() Generate domain name kong.cn
domain_word() Domain word (i.e., does not contain suffix) which
ipv4() Random IP4 address 106.16.131.248
ipv6() Random IP6 address 84ca:702f:6242:9e4:de25:fd3b:6ff:6c9c
mac_address() Random MAC address be:b7:fe:f2:7b:25
tld() Website domain name suffix (com, net, cn, etc., excluding .) org
type() Random URI address https://linzhao.cn/search/posts/faq/
uri_extension() URL file suffix .php
uri_page() URL file (excluding suffix) about
uri_path() URL file path (excluding file name) category/categories
url() Random URL address https://www.vi.cn/
6. Browser information category
method illustrate Return value reference
chrome() Randomly generate Chrome's browser user_agent information Mozilla/5.0 (X11; Linux i686) AppleWebKit/531.0 (KHTML, like Gecko) Chrome/25.0.820.0 Safari/531.0
firefox() Randomly generate FireFox browser user_agent information Mozilla/5.0 (Android 5.1.1; Mobile; rv:48.0) Gecko/48.0 Firefox/48.0
internet_explorer() Randomly generate IE browser user_agent information Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 10.0; Trident/3.1)
opera() Randomly generate Opera browser user_agent information Opera/9.37.(X11; Linux i686; li-BE) Presto/2.9.186 Version/11.00
safari() Randomly generate Safari browser user_agent information Mozilla/5.0 (Windows; U; Windows NT 5.0) AppleWebKit/534.29.6 (KHTML, like Gecko) Version/4.0.4 Safari/534.29.6
linux_platform_token() Randomly generate Linux information X11; Linux x86_64
user_agent() Randomly generate user_agent information Mozilla/5.0 (compatible; MSIE 6.0; Windows 98; Trident/4.1)
7. File information category
method illustrate Return value reference
file_extension() Random file extension wav
file_name() Random filename (including extension, not path) click.key
file_path() 随机文件路径(包含文件名,扩展名) /他的/开发.odt
mime_type() 随机mime类型 application/rdf+xml
八、数字类
方法 说明 返回值参考
numerify() 三位随机数字 384
random_digit() 0~9随机数 9
random_digit_not_null() 1~9的随机数 8
random_int() 随机整数,默认0~9999(参数:min=1000 设置最小值,max=1002 设置最大值) 1002
random_number() 随机数字(参数:digits=10 设置生成的数字位数) 2031324935
pyfloat() 随机浮点数(参数:left_digits=6生成数字的整数位数,right_digits=5生成数字的小数位数,positive=True是否只有正数) 394394.41482
pyint() 随机Int数字(参考random_int参数) 5017
pydecimal() 随机Decimal类型数字(参考pyfloat参数) 4768443424.80596201438295535130904406227846700544212052798887592467
九、文本、加密处理等
方法 说明 返回值参考
pystr() 随机字符串 XTSMLHRDblpkubnIsGDz
random_element() 随机一个元素(参数:elements=('a', 'b', 'c', 'd') 表示选取元素的范围) c
random_elements() 随机多个元素,返回数组(参数:elements=('a', 'b', 'c', 'd') 表示选取元素的范围, unique=False 元素出现次数是否唯一, length=4 数组长度) ['b', 'a', 'a', 'd']
random_letter() 随机的ASCII字母(a-z和A-Z) f
paragraph() 随机生成一个段落 只有美国但是产品各种进行这里.语言加入计划成为教育.希望功能之间得到的人积分有限.
paragraphs() 随机生成多个段落,返回数组(参数 nb=2 段落数) ['一切分析所有单位开始方法电话因此.', '软件研究合作系统公司情况.在线以后状态帮助汽车资源评论.开发系列来自.']
sentence() 随机生成一句话 汽车最大销售留言评论.
sentences() 随机生成多句话,返回数组(参数 nb=2 段落数) ['广告功能其中教育.', '介绍研究无法拥有的人以上.']
word() 随机生成一个词语 今年
words() 随机生成多个词语,返回数组(参数 nb=2 段落数) ['文化', '要求']
text() 随机生成一段文本(不要幻想着人工智能,可以读的通顺,它只是随机的文字组合=.=) 合作精华对于地方.关于一定最大的话现在合作事情.
这是免费问题原因留言可能什么.感觉其中如此法律一起.
增加应用我的各种作者孩子市场.生活个人不过没有.
时候欢迎发展程序政府如何任何工程.价格起来类别类型文化在线.
binary() 随机生成二进制编码(参数 length=16 设置二级制编码长度,默认长度非常之大——1048576) b'\x05\xa2*\xb6\x92r\xa1aj\x07\x88;H&\xf4\xb5'
boolean() 随机布尔值 True/False True
null_boolean() 随机布尔值,带有null值(None/True/False) True
language_code() 随机生成两位语言编码 sk
locale() 随机生成语言/国际 信息 el_GR
md5() 随机生成MD5 3cf766ec45836c41e15f4f2a04b4d4ad
password() 随机生成密码(参数 int型数字 控制密码长度) XLmLGq$u!1
sha1() 随机SHA1 89a251e5c7e8a5fa46a27477caefd0ee711b038e
sha256() 随机SHA256 74d7fe74317f0bbc6d90edce102e021314202c9e504be1ed71c130a714c7fb7a
uuid4() 随机UUID b47dd3c8-72b2-4753-a6d0-82e8e0508e82
csv(data_columns=('{ {name}}', '{ {address}}'), num_rows=3, include_row_ids=True) 随机生成csv格式文本,末尾有换行符 (参数:data_columns=('{ {name}}', '{ {address}}') 设置每一列内容,具体可以参考官网, num_rows=3 设置行数, include_row_ids=True 是否包含行数) "1","赖红","山西省畅县黄浦阜新路V座 538652"
"2","许岩","江西省关岭县沙湾淮安街A座 979501"
"3","何桂芳","湖南省齐齐哈尔市白云巢湖街K座 684754"
csv(data_columns=('段落', '地址'), num_rows=3, include_row_ids=True) 随机生成csv格式文本  "1","段落","地址"
"2","段落","地址"
"3","段落","地址"
十、时间信息类
方法 说明 返回值参考
am_pm() AM/PM PM
century() 随机世纪 XI
date() 随机日期 1982-04-28
date_between() 随机生成指定范围内日期(参数:start_date,end_date取值:具体日期或者today,-30d,-30y类似) 2001-05-30
date_between_dates() 随机生成指定范围内日期,接受两个Date对象并返回两个给定日期之间的随机日期。接受Date或datetime对象(参数:date_start,date_end ) 2023-03-31
date_object() 随机生产从1970-1-1到指定日期的随机日期。 1998-02-16
date_this_month() 现在这个月的日期 2023-03-02
date_this_year() 现在这一年的日期 2023-03-22
date_time() 随机生成指定时间(1970年1月1日至今) 2006-06-27 08:26:40
date_time_ad() 生成公元1年到现在的随机时间 1934-03-01 10:12:48
date_time_between() 根据两个给定日期之间的随机日期获取datetime对象。接受可以被strtotime()识别的日期字符串。 2014-03-02 01:03:31
future_date() 随机生成未来日期 2023-04-17
future_datetime() 随机生成未来时间 2023-04-16 14:10:13
month() 随机月份 04
month_name() 随机月份名称 六月
past_date() 随机生成已经过去的日期 2023-03-26
past_datetime() 随机生成已经过去的时间 2023-03-10 04:24:10
time() 随机24小时时间 07:40:52
timezone() 随机时区 America/La_Paz
unix_time() 随机Unix时间 158238094
year() 随机年份 1990

Guess you like

Origin blog.csdn.net/m0_54701273/article/details/129887040