![pexelsenergepiccom313691 | Embarcadero RAD Studio Delphi C++Builder Blogs 6 Simple Ways to Generate Dummy Data for Your Windows Apps hero image](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/pexels-energepiccom-313691-7959472-scaled.jpg?resize=1140%2C694&ssl=1)
In this article, you’ll learn what is the purpose of dummy data generation, using python windows GUI builder to add features and functionalities to python, using python libraries to generate Dummy Data for Windows apps; Getting started with Python4Delphi and RAD Studio, and many more.
Table of Contents
What is the purpose of dummy data generation?
As a Developer or Tester, sometimes we need a large volume of data in the database to test the applications. Manually creating this data and inserting it into the database is not an affordable option if we consider the price and effort involved too. This is where you need the tools for automatically generating as much dummy data as you need, to test or populate your apps at the lowest cost.
Load, performance, and stress testing are just impossible without the help of these data generation tools. These tools are easy to use, and in turn, save a lot of time. It not only saves time for creating lengthy scripts but has also made data generation easy. With just a few lines of Python code, you will be able to create a large volume of data.
To get the data using web scraping, instead of dummy data generation, read this article for tutorials and best options:
Delphi adds powerful GUI features and functionalities to Python
In this tutorial, we’ll build Windows Apps with extensive Test Data Generation capabilities by integrating Python’s Test Data Generation libraries with Embarcadero’s Delphi, using Python4Delphi (P4D).
P4D empowers Python users with Delphi’s award-winning VCL functionalities for Windows which enables us to build native Windows apps 5x faster. This integration enables us to create a modern GUI with Windows 10 looks and responsive controls for our Python Test Data Generation applications. Python4Delphi also comes with an extensive range of demos, use cases, and tutorials.
We’re going to cover the following…
How to use Faker, FauxFactory, lipsum, Mimesis, pandas, and radar Python libraries to Generate Dummy Data for Your Windows Apps
All of them would be integrated with Python4Delphi to create Windows Apps with Test Data Generation capabilities.
Prerequisites
Before we begin to work, download and install the latest Python for your platform. Follow the Python4Delphi installation instructions mentioned here. Alternatively, you can check out the easy instructions found in the Getting Started With Python4Delphi video by Jim McKeeth.
Getting started with Python4Delphi and RAD Studio
First, open and run our Python GUI using project Demo1 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo1 source on GitHub. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.
![python4delphi run demo01 | Embarcadero RAD Studio Delphi C++Builder Blogs 6 Simple Ways to Generate Dummy Data for Your Windows Apps using the Python4Delphi GUI tools](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/04/0_runDemo1-1610538.png?resize=750%2C401&ssl=1)
1. How can I use Faker to generate dummy data?
Faker is a Python package that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.
After installing Python4Delphi properly, you can get Faker using pip or easy install to your command prompt:
1 |
pip install Faker |
Don’t forget to put the path where your Faker library installed, to the System Environment Variables:
System Environment Variable Examples
1 2 3 |
C:/Users/YOUR_USERNAME/AppData/Local/Programs/Python/Python38/Lib/site-packages C:/Users/YOUR_USERNAME/AppData/Local/Programs/Python/Python38/Scripts C:/Users/YOUR_USERNAME/AppData/Local/Programs/Python/Python38 |
The following is the code example of Faker and Python4Delphi to generate real-world example: Complex data with nine variables and 1000 rows (Run this inside the lower Memo of Python4Delphi Demo01 GUI):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import pandas from faker import Factory import random from datetime import datetime faker = Factory.create() status = 'created,delivered,returned'.split(',') def date_between(d1, d2): f = '%b%d-%Y' return faker.date_time_between_dates(datetime.strptime(d1, f), datetime.strptime(d2, f)) def fakerecord(): return {'awb': faker.numerify('######'), # random number eg:235533 'destination_city': faker.city(), # random cities 'product': 'random_product', # different products 'product_category': 'random_category', # different categories 'origin_city': faker.city(), # random metro cities 'logistics_provider_id': faker.numerify('##'), # id's eg:1,20,28,27 'dispatch_date': date_between('mar01-2015', 'mar15-2015'), # datetime between mar01-2015 to mar15-2015 'final_delivery_status': random.choice(status), # created,delivered,returned 'actual_delivery_date': date_between('mar16-2015', 'mar30-2015'), # datetime between mar16-2015 to mar30-2015 'promised_delivery_date': date_between('mar25-2015', 'apr06-2015'), # datetime between mar25-2015 to Apr6-2015 } example_dummy_data = pandas.DataFrame([fakerecord() for _ in range(1000)]) # Export to CSV example_dummy_data.to_csv('fakerExample.csv', index=False) |
Here is the Faker output in the Python GUI:
![Faker Demo with Python4Delphi in Windows | Embarcadero RAD Studio Delphi C++Builder Blogs 6 Simple Ways to Generate Dummy Data for Your Windows Apps Faker Demo with Python4Delphi in Windows](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/demo01_Faker2-2809487.png?resize=547%2C774&ssl=1)
The code above will generate dummy data with various Python data types and 1000 rows of observations in total, and export it to .CSV file with this look:
![demo01Faker2output | Embarcadero RAD Studio Delphi C++Builder Blogs 6 Simple Ways to Generate Dummy Data for Your Windows Apps here is the demo output](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/demo01_Faker2output-6829855.png?resize=750%2C401&ssl=1)
To plot the data generated using TChart, read this article to learn how:
2. How to use FauxFactory to Generate Dummy Data?
FauxFactory generates random data for your automated tests easily!
There are times when you’re writing tests for your application when you need to pass random, non-specific data to the areas you are testing. For these scenarios, when all you need is a random string, numbers, dates, times, email address, IP, etc, then FauxFactory can help!
First, here is how you can get FauxFactory:
1 |
pip install fauxfactory |
The following code is the implementation of FauxFactory to generate a random string, numeric, date, datetime, and email:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import fauxfactory import datetime string = fauxfactory.gen_string('alphanumeric', 15) print(string) print(string.isalnum()) print(len(string)) numeric = fauxfactory.gen_string('numeric', 5) print(numeric) print(numeric.isnumeric()) print(len(numeric)) date = fauxfactory.gen_date() print(date) datetime = fauxfactory.gen_datetime() print(datetime) email = fauxfactory.gen_email(domain='embarcadero') print(email) print('@embarcadero' in email) |
Here are the FauxFactory examples in the Python GUI
![FauxFactory Demo with Python4Delphi in Windows | Embarcadero RAD Studio Delphi C++Builder Blogs FauxFactory Demo with Python4Delphi in Windows](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/demo02_FauxFactory-5948978.png?resize=547%2C698&ssl=1)
3. How do I use lipsum to generate dummy data?
lipsum is a Python simple Lorem Ipsum generator library that can be easily used in your Python applications. Note that this library only generates randomized Lorem Ipsum strings (words, sentences, and paragraphs).
By default, lipsum takes its source text from Cicero’s De finibus bonorum et malorum, but you can specify your own source text if you want (which must be greater than 100kB in size).
First, here is how you can get lipsum:
1 |
pip install lipsum |
Below is the code for generating random 100 words using lipsum (Run the following code inside the lower Memo of Python4Delphi Demo01 GUI):
1 2 3 4 |
import lipsum # Randomly grab 100 words print(lipsum.generate_words(100)) |
lipsum Python4Delphi Results
![lipsum Demo with Python4Delphi in Windows | Embarcadero RAD Studio Delphi C++Builder Blogs 6 Simple Ways to Generate Dummy Data for Your Windows Apps lipsum Demo with Python4Delphi in Windows](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/demo03_lipsum-5216801.png?resize=682%2C497&ssl=1)
When generating the content, lipsum will automatically attempt to append punctuation to the end of your sentences and capitalize the first letter of new sentences.
4. How to use Mimesis to generate dummy data?
Mimesis is a high-performance fake data generator for Python, which provides data for a variety of purposes in a variety of languages. The fake data could be used to populate a testing database, create fake API endpoints, create JSON and XML files of arbitrary structure, anonymize data taken from production, etc.
These are the key features of Mimesis:
- Performance: The fastest data generator available for Python.
- Extensibility: You can create your own data providers and use them with Mimesis.
- Generic data provider: The simplified access to all the providers from a single object.
- Multilingual: Supports data for a lot of languages.
- Data variety: Supports a lot of data providers for a variety of purposes.
- Schema-based generators: Provides an easy mechanism to generate data by the schema of any complexity.
- Country-specific data providers: Provides data specific only for some countries.
First, here is how you can get Mimesis:
1 |
pip install mimesis |
Run these simple examples of Mimesis code, to introduce you to generate person full name with different gender and nationality, generate email address, and more inside the lower Memo of Python4Delphi Demo01 GUI:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
from mimesis import Person from mimesis.enums import Gender person = Person('en') print(person.full_name()) email = person.email(domains=['embarcadero.com']) print(email) phone = person.telephone(mask='1-3##-5##-7##9') print(phone) # Localizations & Genders de = Person('de') deFemale = de.full_name(gender=Gender.FEMALE) deMale = de.full_name(gender=Gender.MALE) print(deFemale) print(deMale) en = Person('en') enFemale = en.full_name(gender=Gender.FEMALE) enMale = en.full_name(gender=Gender.MALE) print(enFemale) print(enMale) ru = Person('ru') ruFemale = ru.full_name(gender=Gender.FEMALE) ruMale = ru.full_name(gender=Gender.MALE) print(ruFemale) print(ruMale) |
Mimesis Simple yet Powerful Examples:
![Mimesis Demo with Python4Delphi in Windows | Embarcadero RAD Studio Delphi C++Builder Blogs 6 Simple Ways to Generate Dummy Data for Your Windows Apps Mimesis Demo with Python4Delphi in Windows](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/demo04_mimesis-2585986.png?resize=547%2C843&ssl=1)
5. How to Generate Numeric Dummy Data with pandas?
pandas is a Python package that provides fast, flexible, and expressive data structures designed to make working with “relational” or “labeled” data both easy and intuitive. It aims to be the fundamental high-level building block for doing practical, real-world data analysis in Python. Additionally, it has the broader goal of becoming the most powerful and flexible open-source data analysis/manipulation tool available in any language. It is already well on its way towards this goal.
Here is how you can install pandas:
1 |
pip install pandas |
Here is the easiest way to create numerical dummy data using pandas, and export them to CSV:
1 2 3 4 5 6 |
import pandas as pd # Create dummy data pandasDummy = pd.util.testing.makeDataFrame() # Export the data to .CSV file pandasDummy.to_csv('pandasExample.csv') |
Here is the pandas Demo Result in the Python GUI
![pandas Demo with Python4Delphi in Windows | Embarcadero RAD Studio Delphi C++Builder Blogs 6 Simple Ways to Generate Dummy Data for Your Windows Apps pandas Demo with Python4Delphi in Windows](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/demo05_Pandas00-4722184.png?resize=546%2C475&ssl=1)
By default, it will create 30 rows with 4 columns called A, B, C, and D and the index alpha-numeric. Here is the result:
![| Embarcadero RAD Studio Delphi C++Builder Blogs 6 Simple Ways to Generate Dummy Data for Your Windows Apps data in speadsheet](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/demo05_Pandas-2523300.png?resize=750%2C400&ssl=1)
Read this article to learn how to use Pandas for data analysis:
6. How do we use radar to generate dummy test data?
radar (RAndom DAte geneRation) is a Python library to generate random date.
Here is how you can install radar:
1 |
pip install radar |
The following code is the basic usage of radar:
1 2 3 4 5 6 7 8 9 10 11 12 |
import radar import datetime # Basic usage print(radar.random_datetime()) # Specify date range specifiedDate = radar.random_date( start = datetime.datetime(year=2000, month=5, day=24), stop = datetime.datetime(year=2013, month=5, day=24) ) print(specifiedDate) |
radar with Python4Delphi Results
![radar Demo with Python4Delphi in Windows | Embarcadero RAD Studio Delphi C++Builder Blogs 6 Simple Ways to Generate Dummy Data for Your Windows Apps radar Demo with Python4Delphi in Windows](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/demo06_radar-4423933.png?resize=547%2C554&ssl=1)
Are you ready to try these dummy data generators?
We have demonstrated 6 powerful Python libraries for creating dummy or test data – Faker, FauxFactory, lipsum, Mimesis, pandas, and radar. All of them are wrapped well inside a powerful GUI provided by Python4Delphi. We can’t wait to see what you build with Python4Delphi!
Want to know some more? Then check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition