arjuna.tpi.data.generator module¶
- class arjuna.tpi.data.generator.DataLocale¶
Bases:
object
Data Locale object.
When this object is passed where relevant to Random class methods, it localizes the data generated.
To create a specific locale object, you can use the dot notation.
locale.en locale.fr
For list of supported locales, check Supported locales. You also use the following code to get all supported locale names:
locale.supported
- property supported¶
- class arjuna.tpi.data.generator.Random¶
Bases:
object
Provides methods to create random strings and numbers of different kinds.
- classmethod address(*, locale='en', calling_code=None, city=None, country=None, country_code=None, latitude=None, longitude=None, postal_code=None, state=None, street_name=None, street_number=None, street_suffix=None)¶
Create an Address Data Entity object.
All individual fields are automatically randomly generated based on locale. If provided, the corresponding values are overriden.
Note
All individual fields are randomly generated. Don’t expect correct correlation e.g. correct postal code for the generated city.
- Keyword Arguments
locale – Approprite Random.locale.<local_name> object. Default is Random.locale.EN
calling_code – Calling Code
city – City
country – Country Name
country_code – Country Code
latitude – Latitude
longitude – Longitde
postal_code – Postal Code
state – State
street_name – Street Name
Number (street_number Street) –
street_suffix – Street Suffix
- classmethod alphabet(*, locale='en', lower_case=False)¶
Generate a random integer.
- Keyword Arguments
locale – (Optional) Locale for data
lower_case – (inclusive) If true lower case alphabet is returned where applicable.
- Returns
A list of alphabet characters.
- classmethod city(*, locale='en') str ¶
Generate a city name.
- Keyword Arguments
locale – (Optional) locale for generating city name
- Returns
A generated city name
- classmethod color(*, locale='en') str ¶
Generate a random color string.
- Keyword Arguments
locale – (Optional) locale for generating street name
- Returns
A generated color
- classmethod country(*, locale='en') str ¶
Generate a country name
- Keyword Arguments
locale – (Optional) locale for generating country name
- Returns
A generated country name
- classmethod email(*, locale='en', name=None, domain=None) str ¶
Generate an email address.
- Keyword Arguments
locale – (Optional) locale for generating email address
name – (Optional) If provided, then email address is created as <provided name>@<generated domain>
domain – (Optional) If provided, then email address is created as <generated name>@<provided domain>
- Returns
A generated email address
- classmethod first_name(*, locale='en') str ¶
Generate a first name.
- Keyword Arguments
locale – (Optional) locale for generating first name
- Returns
A generated first name
- classmethod fixed_length_number(*, length) int ¶
Generate a fixed length number
- Keyword Arguments
length – Number of digits in generated number.
- Returns
A generated fixed length number
Note
A number of minimum length 1 is always generated.
- classmethod fixed_length_str(*, length) str ¶
Generate a fixed length string
- Keyword Arguments
length – Number of chracters in generated number.
- Returns
A generated fixed length string
Note
A number of minimum length 1 is always generated.
- classmethod hex_color() str ¶
Generate a hex color code.
- Returns
A generated hex color code string
- classmethod house_number(*, locale='en', prefix='') str ¶
Generate a house number
- Keyword Arguments
locale – (Optional) locale for generating house number
prefix – (Optional) prefix to be added to the generated house number. Space is used as delimited between prefix and generated house number.
- Returns
A generated house number
- classmethod int(*, end, begin=0) int ¶
Generate a random integer.
- Keyword Arguments
end – (inclusive) upper limit for the integer
begin – (inclusive) lower limit for the integer. Default is 0.
- Returns
A generated integer
- classmethod last_name(*, locale='en') str ¶
Generate a last name.
- Keyword Arguments
locale – (Optional) locale for generating last name
- Returns
A generated last name
- classmethod name(*, locale='en') str ¶
Generate a full name (first name and last name).
- Keyword Arguments
locale – (Optional) locale for generating phone number
- Returns
A generated full name
- classmethod person(*, locale='en', qualification=None, age=None, blood_type=None, email=None, first_name=None, last_name=None, gender=None, height=None, id=None, language=None, nationality=None, occupation=None, phone=None, title=None, university=None, weight=None, work_experience=None)¶
Create an Person Data Entity object.
All individual fields are automatically randomly generated based on locale. If provided, the corresponding values are overriden.
Note
All individual fields are randomly generated. Don’t expect correct correlation e.g. correct postal code for the generated city.
- Keyword Arguments
locale – Approprite Random.locale.<local_name> object. Default is Random.locale.EN
qualification – Educational Qualification
age – Age
blood_type – Blood type
email – Email address
first_name – First name
last_name – Last name
gender – Gender
height – Height
id – Identifier
language – Language
nationality – Nationality
occupation – Occupation
phone – Phone number
title – Title
university – University
weight – Weight
work_experience – Work Experience
- classmethod phone(*, locale='en') str ¶
Generate a phone number.
- Keyword Arguments
locale – (Optional) locale for generating phone number
- Returns
A generated phone number
- classmethod postal_code(*, locale='en') str ¶
Generate a postal code
- Keyword Arguments
locale – (Optional) locale for generating postal code
- Returns
A generated postal code
- classmethod rgb_color() tuple ¶
Generate an rgb color tuple.
- Returns
RGB tuple
- classmethod sentence(*, locale='en') str ¶
Generate a sentence
- Keyword Arguments
locale – (Optional) locale for generating sentence
- Returns
A generated sentence
- classmethod street_name(*, locale='en') str ¶
Generate a street name
- Keyword Arguments
locale – (Optional) locale for generating street name
- Returns
A generated street name
- classmethod street_number(*, locale='en', prefix='') str ¶
Generate a street number
- Keyword Arguments
locale – (Optional) locale for generating street number
prefix – (Optional) prefix to be added to the generated street number. Space is used as delimited between prefix and generated street number.
- Returns
A generated street number
- classmethod ustr(*, prefix: Optional[str] = None, maxlen: Optional[int] = None, minlen: Optional[int] = None, delim: str = '-', strict=False) str ¶
Generate a unique UUID string. If minlen/maxlen are specified in a manner that leads to uuid truncation, uniqueness is not enforced. Base string length is prefix length + delim length + 36 (length of uuid4) Different arguments tweak the length of generated string by appending uuid one or more times fully or partially.
- Keyword Arguments
prefix – (Optional) prefix to be added to the generated UUID string.
minlen – (Optional) Minimum length of the retuned string (inclusive of prefix + delim). Default is base string length.
maxlen – (Optional) Maximum length of the retuned string (inclusive of prefix + delim). Should be greater than minlen. Default is calculated as: * if minlen > half of base string length, then default maxlen is 2 * minlen * if minlen < half of base string length, then default maxlen is base string length
delim – (Optional) Delimiter between prefix and generated string. Default is “-”. Ignored if prefix is not specified.
strict – (Optional) If True uniqueness of string is enforced which means full generated uuid must be used atleast once. This means length of generated string must be >= base string length, else an exception is thrown.
- Returns
A string that is unique for current session.
- class arjuna.tpi.data.generator.composer(callable, *args, **kwargs)¶
Bases:
object
Combines data in an iterable by calling the provided callable with provided arguments.
- Parameters
callable – The callable to be called in composing.
*args – Arbitrary positional args to be passed to the callable.
- Keyword Arguments
**kwargs – Arbitrary keyword arguments to tbe passed to the callable.
- compose(data_iter)¶
Combine data in the provided iterable by calling the callable with arguments provided in constructor.
- Parameters
data_iter – Data iterable
- class arjuna.tpi.data.generator.composite(*generators_or_data, composer=<function _same>)¶
Bases:
arjuna.tpi.data.generator._gen
Composite Data Generator.
Generate data by composing the output of all generators, callables or static data.
- Parameters
*generators_or_data – Arbitrary generators, functions or static data objects.
- Keyword Arguments
composer – This callable is called after data sequence is generated by passing generated data sequence as argument. Useful for data transformation of any kind.
- generate()¶
Generate data by composing the output of all generators, callables or static data.
The composer callable is called after data sequence is generated by passing generated data sequence as argument. Useful for data transformation of any kind.
- class arjuna.tpi.data.generator.generator(callable, *args, processor=<function _same>, **kwargs)¶
Bases:
arjuna.tpi.data.generator._gen
Generate data by calling the provided callable with provided arguments.
- Parameters
callable – The callable to be called in composing. By default, same generated object is returned.
*args – Arbitrary positional args to be passed to the callable.
- Keyword Arguments
processor – This callable is called after data is generated by passing generated data as argument. Useful for data transformation of any kind. If its type is string, it is assumed to be a method of the data which the data callable generated.
**kwargs – Arbitrary keyword arguments to tbe passed to the callable.
- generate()¶
Generate data by calling the callable with arguments provided in constructor.
After generation the coverter callable is called with this data before returning the data.
- class arjuna.tpi.data.generator.processor(callable, *args, **kwargs)¶
Bases:
object
Processes data by calling the provided callable with provided arguments.
- Parameters
callable – The callable to be called in processing.
*args – Arbitrary positional args to be passed to the callable.
- Keyword Arguments
**kwargs – Arbitrary keyword arguments to tbe passed to the callable.
- process(data)¶
Processes data in the provided data object by calling the callable with arguments provided in constructor.
- Parameters
data – Data object