Generator real fake data for testing
Project description
baraqda-lib
Library to generate fake data that reflects real data in society.
How to run
Install library from pip
pip install baraqda-lib
Check if everything is working by simple code below:
from baraqdalib import Person
from baraqdalib import Addresses
from baraqdalib import Generator
if __name__ == '__main__':
abba = Addresses()
print(abba.generate()) # print generated address
abba = Person()
abba.set() # Generate person attributes
print(abba.get()) # print generated person attributes
abba = Generator()
print(abba.generate('PL', 'male_first_name', 100, sep='\t')) # generate one attribute from provided data
How to use
For generating address use:
Addresses.generate()
Library does not save generated data.
If you want to generate more addresses or change country, define this parameters when callinf function.
Addresses.generate(counter = 100, lang = 'PL')
For generating person attributes use:
Person.set()
Person.get()
If you want to generate more person attributes put above code in loop.
If you don't want generating the whole person but only one attribuite use Generator class. Example:
Generator.generate('PL', 'female_first_name', 100, sep='\t'))
This code provides list of 100 female first name.
List of available attribuites to generate for Polsih person.
- age,
- blood_type,
- cities_pops,
- eyes,
- female_first_name,
- female_second_name,
- female_surname,
- hair,
- male_first_name,
- male_second_name,
- male_surname
Generating data
Generating data take place in class Generator(). Instance of this class provide function to read data, store data,
display data that was read from files and most import make a toss. Generating address and person took place in class Addresses and Person.
Functions in Generator()
Generator.draw(lang: str, data_type: str, count: int = 1, sep: str = ' ') -> List[str]
Drawing a results from given file, returning list with len(list) = counter
Parameters:
lang (str): Two letters shortcut for country.
data_type (str): Name of file from which data should be generated.
count (int): How many records should be generated, Default is 1.
sep (str): Set separators for columns in files. Default is single space.
Returns:
list: Returning list of generated data.
Generator.search_files(path, sep, lang) -> None
Running this function erase all stored data and read it again. Use with caution!
Parameters:
sep (str): separator of columns in files
lang (str): Two letters shortcut for country
Returns: None
Generator.read_files(filepath, separator, lang, filename) -> None
Reading files into class variable self._data
Parameters:
filepath (str): Filepath for a file
separator (str): Separator of columns in files
lang (str): Two letters shortcut for country
filename (str): Filename
Returns: None
"""
Generator.generate(lang: str, data_type: str, counter: int = 1, sep: str = ' ') -> List[str]
Generating data with reading files. This is recommended way of using generator.
Parameters:
lang (str): two letters shortcut for country
data_type (str): name of file from which data should be generated
counter (int): default is 1. How many records should be generated
sep (str): default is single space. Set separators for columns in files
Returns:
list: Returning list of generated data.
"""
Generator.access_data(lang: str, data_type: str) -> Dict[str, list]
Access data which are readed from files. Helpful when you want to make sure that your files are in correct format
Parameters:
lang (str): Two letters shortcut for country
data_type (str): Name of file from which data should be generated
Returns:
Dict: Returning dictionary with loaded data in class instance
Generate polish person and address
To generate person and address we can use class Person and class Addresses This two class generate only fake polish person.
Library generate only person nat
Functions in Addresses()
Addresses._set_codes(self):
Get postal codes from file postal_codes.csv and save in self._postal_code list
Parameters : None
Returns: None
Addresses._set_cities(self):
Get cities names from file cities.csv and save in self._cities list
Parameters : None
Returns: None
Addresses._set_streets(self):
Get street names from file streets.csv and save in self._streets list
Parameters : None
Returns: None
Addresses.generate(self, counter: int = 1, lang: str = 'PL')
Generating address with city, street, street number, and postal code
Parameters:
counter (int): Default is 1. You can specify how much addreses you want to generate
lang (str): Default is 'PL'. By this argument you can choose from wchich country addresses should be generated.
Returns:
Dict(Dict()): returning generated addresses in nested dictionary for easy access
Addresses.get_code(self, city: str)
Search and return postal code for a given city
Parameters:
city (str): Name of the city
Returns:
str: Returns postal code
Addresses.get_sym_city(self, city: str)
Searching for city in cities and returning sym (indentificator)
Parameters:
city (str): name of city for searching
Returns:
str : return sym for searching city
Addresses.get_streets(self, city_sym: int)
Generate random street for given city sym (identificator) that is in this city.
Parameters:
city_sym (int): number of city syn
Returns:
str: returns random street
Functions in Person()
Generating attributes for Polish person. For simple use set() and get() to generate one record, for more make for loop with these two functions.
Person.toss(self)
Parameters: None
Returns:
int: return random value of 0 or 1 which determines gender
Person.set_date_of_birth(self, nr_of_years)
Create date of brith using generated number of years.
Parameters:
nr_of_years (int): number of years of generated person
Returns:
str: returns calculated date of birth
Person.set_pesel(self, date_of_birth, female_or_male)
Create polish identifacation number, PESEL
Parameters:
date_of_birth (str):
female_or_male (int): determines gender
Returns:
str: returning calculated PESEL
Person.set(self)
Generating parameters for a person based on
Parameters: None
Returns: None
Person.get(self)
Print generated attribiutes
Parameters: None
Returns: None
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file baraqda-lib-0.0.12.tar.gz.
File metadata
- Download URL: baraqda-lib-0.0.12.tar.gz
- Upload date:
- Size: 7.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b4e5274ad717cef3bbf1e62492bb052f7ecbe5616be3d6fa7e1da97fee93a69
|
|
| MD5 |
202c4f1724d281dc0862e3ca05500eb9
|
|
| BLAKE2b-256 |
4061c140265dc5dd052771db8320bb7659ea2cb989176759f74981ad4761c5a0
|
File details
Details for the file baraqda_lib-0.0.12-py3-none-any.whl.
File metadata
- Download URL: baraqda_lib-0.0.12-py3-none-any.whl
- Upload date:
- Size: 7.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
505da182939be0fd810f639e505c06fb71ca7eaa8aeb2f8c79cdf933e0e286ac
|
|
| MD5 |
f163da52d7acd36f34a250b8da651782
|
|
| BLAKE2b-256 |
338912190615858d26f460094ba2b976d626703384ed444eecec49044828b6f2
|