Use faker You can get a lot of simulation data , Such as : full name 、 Telephone 、 Address 、 Bank 、 automobile 、 Bar code 、 company 、 The credit card 、email、user_agen wait
Learn to use this library , Don't worry about making fake data anymore ......
meanwhile , It's very simple to use , Just install , Import library , And create an instance , You can use , as follows :
As in the example above , Every time you call fake Example of name()
When the method is used , It's going to produce different random names .fake There are many ways to use examples , These methods fall into the following categories :
>>> fake.country() # Country
' Austria '
>>> fake.city() # City
' Zhengzhou city '
>>> fake.city_suffix() # The suffix of the city , Chinese is : City or county
' City '
>>> fake.address() # Address
' Nanning Road, Huairou, Chaohu County, Hebei Province f seat 169812'
>>> fake.street_address() # The street
' Handan Road W seat '
>>> fake.street_name() # Street name
' Hefei Road '
>>> fake.postcode() # Zip code
'314548'
>>> fake.latitude() # dimension
Decimal('68.0228435')
>>> fake.longitude() # longitude
Decimal('155.964341')
>>> fake.name() # full name
' Shan Yuzhen '
>>> fake.last_name() # surname
' Pan '
>>> fake.first_name() # name
' Qin '
>>> fake.name_male() # Male name
' Guanping '
>>> fake.last_name_male() # Male surname
' Ann '
>>> fake.first_name_male() # Male name
' writing '
>>> fake.name_female() # Female name
' Phoebe '
>>> fake.ean8() # 8 Bit bar code
'12771363'
>>> fake.ean13() # 13 Bit bar code
'9133134950963'
>>> fake.ean(length=8) # User defined digit bar code , Only choose 8 perhaps 13
'20417161'
>>> fake.hex_color() # 16 The color of the decimal representation
'#671f6d'
>>> fake.rgb_css_color() # css With rgb color
'rgb(237,74,237)'
>>> fake.rgb_color() # Express rgb Color string
'208,102,218'
>>> fake.color_name() # Color name
'Brown'
>>> fake.safe_hex_color() # Security 16 Base color
'#ee4400'
>>> fake.safe_color_name() # Safety color name
'maroon'
>>> fake.company() # Company name
' Time box Digital Technology Co., Ltd '
>>> fake.company_suffix() # Company name suffix
' Technology Co., Ltd '
>>> fake.credit_card_number(card_type=None) # Card number
'375325478746231'
>>> fake.credit_card_provider(card_type=None) # Card provider
'VISA 13 digit'
>>> fake.credit_card_security_code(card_type=None)# Security password of the card
'450'
>>> fake.credit_card_expire() # Validity of the card
'04/22'
>>> fake.credit_card_full(card_type=None) # Complete card information
'Maestro\n Hideyoshi merchant \n502001016117 04/27\nCVV: 144\n'
>>> fake.currency_code() # Currency code
'HNL'
>>> fake.date_time(tzinfo=None) # Random date time
datetime.datetime(2001, 3, 18, 17, 57, 44)
>>> fake.iso8601(tzinfo=None) # With iso8601 Date of standard output
'1973-11-16T22:58:37'
>>> fake.date_time_this_month(before_now=True, after_now=False, tzinfo=None) # A date of the month
datetime.datetime(2017, 11, 1, 14, 33, 48)
>>> fake.date_time_this_year(before_now=True, after_now=False, tzinfo=None) # A date of the year
datetime.datetime(2017, 3, 2, 13, 55, 31)
>>> fake.date_time_this_decade(before_now=True, after_now=False, tzinfo=None) # A date in this decade
datetime.datetime(2010, 3, 26, 6, 33, 23)
>>> fake.date_time_this_century(before_now=True, after_now=False, tzinfo=None) # A date of the century
datetime.datetime(2015, 7, 21, 19, 27, 53)
>>> fake.date_time_between(start_date="-30y", end_date="now", tzinfo=None) # A random time between two times
datetime.datetime(2005, 12, 3, 17, 17, 15)
>>> fake.timezone() # The time zone
'America/Guatemala'
>>> fake.time(pattern="%H:%M:%S") # Time ( Customizable format )
'11:21:52'
>>> fake.am_pm() # Random in the afternoon
'PM'
>>> fake.month() # Random months
'02'
>>> fake.month_name() # Random month name
'August'
>>> fake.year() # Random year
'1974'
>>> fake.day_of_week() # Random day of the week
'Sunday'
>>> fake.day_of_month() # One day in a random month
'02'
>>> fake.time_delta() # Random time delay
datetime.timedelta(13371, 27637)
>>> fake.date_object() # Random Date object
datetime.date(1983, 1, 26)
>>> fake.time_object() # Random time object
datetime.time(17, 8, 56)
>>> fake.unix_time() # Random unix Time ( Time stamp )
1223246848
>>> fake.date(pattern="%Y-%m-%d") # Random date ( Customizable format )
'1984-04-20'
>>> fake.date_time_ad(tzinfo=None) # Random date after AD
datetime.datetime(341, 9, 11, 8, 6, 9)
>>> fake.file_name(category="image", extension="png") # file name ( Specify the file type and suffix )
' increase .png'
>>> fake.file_name() # Random generation of various types of files
' Provide .pdf'
>>> fake.file_extension(category=None) # file extension
'txt'
>>> fake.mime_type(category=None) # mime-type
'image/png'
>>> fake.ipv4(network=False) # ipv4 Address
'104.225.105.10'
>>> fake.ipv6(network=False) # ipv6 Address
'dea6:ca11:39d0:b49f:fff1:82f1:bf88:698b'
>>> fake.uri_path(deep=None) # uri route
'search/categories'
>>> fake.uri_extension() # uri Extension
'.htm'
>>> fake.uri() # uri
'https://www.wei.com/terms/'
>>> fake.url() # url
'http://zheng.org/'
>>> fake.image_url(width=None, height=None) # picture url
'https://www.lorempixel.com/700/990'
>>> fake.domain_word() # Domain name subject
'hu'
>>> fake.domain_name() # domain name
'hu.cn'
>>> fake.tld() # The domain name suffix
'com'
>>> fake.user_name() # user name
'xia13'
>>> fake.user_agent() # UA
'Opera/8.33.(Windows NT 5.1; an-ES) Presto/2.9.171 Version/10.00'
>>> fake.mac_address() # MAC Address
'd6:38:cc:2a:76:b2'
>>> fake.safe_email() # Secure email
'[email protected]'
>>> fake.free_email() # Free mailbox
'[email protected]'
>>> fake.company_email() # Company email
'[email protected]'
>>> fake.email() # mailbox
'[email protected]'
>>> fake.job()# Job title
'Dealer'
>>> fake.job()
'Musician'
>>> fake.text(max_nb_chars=200) # Randomly generate an article
' Why can't language be used in China . Ask to complete how the world computer publishes the work . The economy is different, the education is personal, the technology is national .\n Online students release information about Shanghai status .\n Contact once, introduce the world through the fact . Increase is also the use of the successful one .\n Commodity free management company . Leave your own message .\n I know how many times a woman feels . Operating his production how to report articles only .\n The personal culture center can't release the latest . Improve the quality . Feeling the biggest tool means the final plan . This is the number of times, the result is actually special .'
>>> fake.word() # Random words
' Ability '
>>> fake.words(nb=3) # Random generation of a few words
[' Country ', ' business ', ' result ']
>>> fake.sentence(nb_words=6, variable_nb_words=True) # Randomly generate a sentence
' More important, more places for our work .'
>>> fake.sentences(nb=3) # Randomly generate several sentences
[' Production of Shanghai students .', ' The way the car is like technical help welcome .', ' Explain a kind of Shenzhen business telephone post .']
>>> fake.paragraph(nb_sentences=3, variable_nb_sentences=True) # Randomly generate a paragraph of text ( character string )
' Special environment, limited location, developing home page industry . It's the feeling of the emerging Department . After the product because although due to different Japan .'
>>> fake.paragraphs(nb=3) # Randomly generate several paragraphs of text ( list )
[' This is about international requirements . Shenzhen operation of American equipment . The home page is also a support report .', ' It's decided, but only when it's discovered that it's been . Finally, some projects are being decided in Shenzhen relations . Download the registration image to do more of his .', ' They have to have data ready to contact . At the same time, this content school essence. .']
>>> fake.binary(length=10) # Random binary string ( Length can be specified )
b'U\[email protected]\x1e\x96\xe7\xca\x82\x14f'
>>> fake.language_code() # Random language code
'tg'
>>> fake.md5(raw_output=False) # Random md5,16 Base string
'cc4feebe419791332bbcff5e0fdf084a'
>>> fake.sha1(raw_output=False) # Random sha1,16 Base string
'8ac0e9980f880860b6e45ae6fd257cc847b7ae8d'
>>> fake.sha256(raw_output=False) # Random sha256,16 Base string
'033151f173f4a389e38e7df2363d89741f752c474e7bdfa2ee0a794bf0b505b5'
>>> fake.boolean(chance_of_getting_true=50) # Random true false value ( obtain True The odds are 50%)
False
>>> fake.null_boolean() # Sum of random true and false values null
>>> fake.null_boolean()
True
>>> fake.password(length=10, special_chars=True, digits=True, upper_case=True, lower_case=True) # Random cipher ( Password policy can be specified )
'F%722TJg_U'
>>> fake.locale() # Random local code
'hy_AM'
>>> fake.uuid4() # Random uuid
'a50d17e7-bc4f-37a3-27b3-04a24fdd0055'
>>>
>>> fake.phone_number() # Phone number
'13334603608'
>>> fake.phonenumber_prefix() # Operator segment , Top three mobile phone numbers
158
>>> fake.pyint() # Random int
7775
>>> fake.pyfloat(left_digits=None, right_digits=None, positive=False) # Floating point numbers
-84901.5586333
>>> fake.pydecimal(left_digits=None, right_digits=None, positive=False) # Random high precision number
Decimal('-12273687068527.0')
>>> fake.pystr(min_chars=None, max_chars=20) # Random string ( Length can be specified )
'cblutNKFIyegfcHPrjzx'
>>> fake.pybool() # Random bool value
True
>>> fake.pyiterable(nb_elements=10, variable_nb_elements=True) # Random iterable
['ODfeVvcbAjPDBGwzljQw', 'https://www.tan.cn/list/category/homepage.php', 'YQlrsFkBieyKYaXlCljJ', Decimal('42778240911787.2'), Decimal('957411812.6383'), 'TGbqZufoiUXLQTZDrVcP', 'http://yan.com/posts/tags/search/terms.php', 3.680492634254, '[email protected]', datetime.datetime(2001, 8, 16, 6, 10, 49), 'xMMOjlETIgKGqVGTrChG', '[email protected]']
>>> fake.pylist(nb_elements=10, variable_nb_elements=True ) # Randomly generate one list
['KXQMXAkcEMSLfnIZkgJb', 'BtowiRsuIqyyULnSYYdr', datetime.datetime(2011, 10, 10, 14, 44, 2), datetime.datetime(2008, 5, 10, 1, 38, 38), '[email protected]', 'QEsdUpEqHLpThyWCjkNx', Decimal('-801375867.9'), 'ucDyeZnHAXfZtkwdVUbR', 4707, datetime.datetime(1974, 8, 7, 1, 54, 29)]
>>> fake.pydict(nb_elements=10, variable_nb_elements=True) # Random dictionary
{' among ': 9047, ' always ': 'AUiUjuqccIdVAWSqzDbW', ' choice ': '[email protected]', ' Development ': datetime.datetime(1972, 10, 20, 14, 14, 9), ' The movie ': 'KYmolBhkjSRxloXXFUUT', ' Culture ': 2681, ' here ': '[email protected]', ' Can't ': 'ZPkwuxWsrJSHMNuFiWEx', ' social ': 'CiujeaZMZSuyYwuKzEdN'}
>>> fake.pyset(nb_elements=10, variable_nb_elements=True) # Random set
{'[email protected]', 'http://fu.cn/list/home.htm', 'MlJluVirRkofBnKNtphM', 296, 'ghoUSHkuEGmCzlJFKyHZ', datetime.datetime(2008, 4, 4, 2, 55, 4), 'AgbynHjdvwYpUkbMsfqr', 8751, 9649, '[email protected]', Decimal('5727570036.91'), 'HmDkExndcQIOaTtsSpsc', 'hjQlLLXuHVVzENEwoHJK'}
>>> fake.pytuple(nb_elements=10, variable_nb_elements=True) # Random tuple
('http://www.cai.com/index/', datetime.datetime(1973, 7, 28, 2, 12, 23), 'khltJQMYJvIDRMYodviZ', 'uJezUsEqiHaiFxwOPWvl', 'qojwZHyytBSQQavkDaTu', 'AHUCHYuVJTHnoSEuQDSY', 1012, 'uEYVuzeTlgVhrnCATfKw', 'https://www.zhou.com/categories/tags/main/', 'LbLSFZPeATtzHvbmYhGr')
>>> fake.pystruct() # Random generation 3 a 10 An element of python data structure
([datetime.datetime(1996, 10, 26, 7, 35, 26), datetime.datetime(1998, 2, 28, 17, 20, 8), '[email protected]', 'yEWMrpTqtAHfbxqldGrb', 'YgKYOnrjuthOrOXhlYIl', datetime.datetime(1994, 12, 10, 0, 55, 30), Decimal('-6865068.3'), 'SYHFHiFvJlRVPcCKumUM', -8619.4354, 'kwGipwcASeALLeKdaWBi'], {' meanwhile ': 'BvtYdkNTHwZNMiIIRwKd', ' Space ': 310959668662.457, ' special ': 'PZQDBuuQWkcdryMloyKS', ' music ': Decimal('-7219015925.0'), ' project ': 'https://www.zhou.cn/main.php', ' reply ': 30.408750841, ' Show ': 'etZMrsjXJgZpDfZWhpoS', ' size ': 7472, ' type ': 'OsjpxgLqnTcdVOlHoMoP', ' what ': 'http://www.xia.com/posts/app/index/'}, {' friend ': {0: -415025.243093017, 1: [1799, 585, '[email protected]'], 2: {0: 9980, 1: 'qnOnFTzGnsjvXGybBnMF', 2: ['http://zheng.cn/list/search/tag/faq.html', Decimal('964285276661463.0')]}}, ' happen ': {1: -5339010.6134, 2: [datetime.datetime(1987, 6, 23, 15, 21, 45), 'SvSpvKqTXlJvdQhHScwM', 'PZjKOYzZzoNVsHLRcARQ'], 3: {1: 'https://www.yan.cn/register/', 2: 2191, 3: ['HMHKQuLRBQaaAypRbtHU', datetime.datetime(2014, 5, 24, 3, 32, 36)]}}, ' my ': {2: '[email protected]', 3: ['http://gu.com/about.php', 'DhzpWYkgLCobGSHDLXzI', 1420], 4: {2: datetime.datetime(1986, 2, 22, 4, 50, 12), 3: 'rRHwQQzkpAMBQxwVITBa', 4: [datetime.datetime(1984, 2, 6, 11, 52, 18), -73821572962388.7]}}, ' All ': {3: 'uMQeeBXYNGhrHnAerdjp', 4: [323329.56403, 'kFvqXFhhtQPNtrOjKtxa', 'http://peng.cn/'], 5: {3: 'lcaoeisYIAOsuRjbOXia', 4: Decimal('-902407032449085.0'), 5: [2296, 'uyuWgnsONzLluXqXdASM']}}, ' size ': {4: '[email protected]', 5: [datetime.datetime(1991, 10, 22, 19, 21, 48), 'cDYEScdIokWuvGhRkWqs', 'XeDJojWyywFvzmWYaokO'], 6: {4: Decimal('-4167029.2915827'), 5: 4030, 6: [6372, 'xfRXXEFGsNQpeIGmbaHU']}}, ' Language ': {5: 'https://www.guo.cn/', 6: [6498, datetime.datetime(1981, 12, 3, 18, 4, 29), 42598100345.61], 7: {5: 'http://zheng.cn/', 6: -229316.268238, 7: ['https://www.qiao.cn/home/', 'GtaEXeVxjRnnkggjEguv']}}, ' Express ': {6: 'xcBvcGUWxdMhDqgzmhSd', 7: ['kwDaFhyTKqHajGSaNOMf', 8561, 5456], 8: {6: 'https://zhou.cn/tags/tag/faq.html', 7: 'IGayAZtTQVlSOasQwgug', 8: ['iCjwBzHfmPSLqAgmIOle', 70511766106574.5]}}, ' Electronics ': {7: 'http://www.lu.org/tags/posts/terms/', 8: [datetime.datetime(1978, 8, 11, 12, 16, 35), 'https://song.cn/main/categories/homepage.html', 'https://long.com/register.html'], 9: {7: 'nFJNhyMYBvfTxrYwYPUQ', 8: -2252757903.0, 9: ['GuJnhMEgXoMAivrgGZie', datetime.datetime(2014, 5, 29, 1, 17, 50)]}}, ' People who ': {8: 'WgHePwYSPgSiPllXpLlJ', 9: [1782, 'fSepbXwpvhiBphzDTDNC', -9117731.63459416], 10: {8: 5602, 9: 3664, 10: ['http://www.mao.com/search/tag/main/', Decimal('5579.7377')]}}, ' however ': {9: 'rOfkDPTHvzKbfvQHbPNm', 10: [314.397, 'StqeLyXkIDKHfExSjggk', '[email protected]'], 11: {9: 'BLKNdcccamYzBwRcMxlx', 10: '[email protected]', 11: ['ZocoQHdbhaNloWALnzwt', 'eWVvvHurAlZZRxlYHZXi']}}})
>>> fake.profile(fields=None, sex=None) # Character description information : full name 、 Gender 、 Address 、 Company, etc
{'job': 'Licensed conveyancer', 'company': ' Wanxun Computer Information Co., Ltd ', 'ssn': '370684199902182726', 'residence': ' Guangzhou Street, Nanchang, Xiaohong City, Fujian Province K seat 406448', 'current_location': (Decimal('18.050895'), Decimal('-0.877117')), 'blood_group': '0-', 'website': ['https://www.yi.org/', 'https://www.hu.com/', 'https://www.yin.cn/'], 'username': 'minghuang', 'name': ' Hou Ying ', 'sex': 'F', 'address': ' Jiahe Road, Bishan, Xiurong City, Anhui Province T seat 954960', 'mail': '[email protected]', 'birthdate': '1975-03-09'}
>>> s = fake.simple_profile(sex="m") # Character reduction information
>>> for i,v in s.items():
... print(i,v)
...
username chao85
name Bing Yu
sex M
address Liao street, Chaoyang, Dongshi, Shaanxi Province Y seat 757661
mail [email protected]
birthdate 1996-09-20
>>> fake.ssn() # Generate ID number randomly (18 position )
'140100196612297997'
>>> len(fake.ssn())
18
It is often used to forge browser information
>>> fake.user_agent() # forge UA
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/5361 (KHTML, like Gecko) Chrome/15.0.812.0 Safari/5361'
Platform information forgery
>>> fake.linux_platform_token()
'X11; Linux i686'
>>> fake.linux_processor()
'i686'
>>> fake.windows_platform_token()
'Windows CE'
>>> fake.mac_platform_token()
'Macintosh; Intel Mac OS X 10_7_4'
>>> fake.mac_processor()
'PPC'
Browser forgery
>>> fake.internet_explorer() # IE browser
'Mozilla/5.0 (compatible; MSIE 5.0; Windows NT 6.1; Trident/4.0)'
>>> fake.opera() # opera browser
'Opera/9.37.(Windows 95; doi-IN) Presto/2.9.178 Version/10.00'
>>> fake.firefox() # firefox browser
'Mozilla/5.0 (Windows NT 5.0; te-IN; rv:1.9.2.20) Gecko/2015-09-28 13:29:05 Firefox/12.0'
>>> fake.safari() # safari browser
'Mozilla/5.0 (Windows; U; Windows NT 4.0) AppleWebKit/533.37.4 (KHTML, like Gecko) Version/5.0 Safari/533.37.4'
>>> fake.chrome() # chrome browser
'Mozilla/5.0 (Windows 98; Win 9x 4.90) AppleWebKit/5361 (KHTML, like Gecko) Chrome/14.0.866.0 Safari/5361'
Faker Enough information has been provided to generate , Including the name 、 cell-phone number 、 Email address 、 Postcode, etc . For all that , There may still be no way to meet your needs . At this time , You can take advantage of custom extensions , Quote from the outside provider, Customize the features you want .
Faker Objects can pass through add_provider
Method will be customized Provider Add to object , Self defined Provider Need to inherit from BaseProvider.
from faker import Faker
fake = Faker()
# first, import a similar Provider or use the default one
from faker.providers import BaseProvider
# create new provider class
class MyProvider(BaseProvider):
def foo(self):
return 'bar'
# then add new provider to faker instance
fake.add_provider(MyProvider)
# now you can use:
print(fake.foo())
Results show :
bar
Faker
Randomly generated by random.Random
drive . among ,.random
Property returns random.Random
object . Through the operation on the object , Custom behavior can be implemented .
from faker import Faker
fake = Faker()
fake.random
fake.random.getstate()
pip install faker
from faker import Faker
fake = Faker()
for i in range(0,10):
print(fake.name())
No further explanation ,
For more details, see faker Document address :https://faker.readthedocs.io/en/master/#