My Coding > Programming language > Python > Python libraries and packages > Faker

Faker

Faker is a Python library for making dummy user profiles. It is very convenient when you need to have a lot of them with different localizations for some test purposes.

To install it use:


pip install Faker

You can create a name, email, phone, profession, address and many more other parameters which can be used by the user to fill in the information about him. Almost all languages are available. It is very convenient for creating test datasets.

Examples of usage:

Load module, create generator with default English localization and print a random name.


from faker import Faker
fake = Faker()
print(fake.name())
#Jessica Dixon

Very simple and straightforward procedure.

It is possible to create a full dummy profile:


print(fake.profile())
#{'job': 'Event organiser', 'company': 'Rogers-Bailey', 'ssn': '735-18-8833', 
#'residence': '30965 Potts Tunnel Apt. 357\nLucasfurt, AL 27992',
# 'current_location': (Decimal('69.871843'), Decimal('-5.019277')),
# 'blood_group': 'A-', 'website': ['https://www.stephenson.com/', 
#'https://www.preston-rodriguez.biz/',# 'https://www.rivera.com/', 
#'https://www.young.net/'], 'username': 'taylormeyer',# 'name': 'Samantha Francis',
# 'sex': 'F', 'address': '5607 James Trail Apt. 973\nAaronstad, SC 13519',
#'mail': 'christina39@yahoo.com', 'birthdate': datetime.date(1994, 8, 14)}

To create other locality, use standard code, or list of codes:


fake1=Faker('zh_CN')
print(fake1.profile())
{'job': '外科医生', 'company': '毕博诚网络有限公司', 'ssn': '51090319610728613X',
# 'residence': '山东省石家庄市城东天津路o座 827531', 'current_location': (Decimal('52.451680'),
# Decimal('22.043767')), 'blood_group': 'B+', 'website': ['https://www.tanglin.cn/'],
# 'username': 'zhao', 'name': '方慧', 'sex': 'F', 'address': '上海市金凤市海港黄街O座 307596',
# 'mail': 'chao08@hotmail.com', 'birthdate': datetime.date(2008, 4, 21)}

This is our short of showing this work:


Published: 2024-07-24 09:29:25
Updated: 2024-07-24 09:32:51

Last 10 artitles


9 popular artitles

© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit.