Home Applications iris-python-faker

iris-python-faker

by Dmitry Maslennikov on behalf of CaretDev
This application is not supported by InterSystems Corporation. Please be notified that you use it at your own risk.
5
1 reviews
2
Awards
704
Views
71
IPM installs
4
0
Details
Releases
Reviews  (1)
Awards  (2)
Issues
Articles  (2)
This app has a demo View
Python Faker from InterSystems IRIS

What's new in this version

Updated readme, fixed some issues

iris-python-faker

Python Faker library through Embedded Python support in InterSystems IRIS with UI

Online Demo

What is Faker

Faker helps to generate some fake data, but similar to real data. While InterSystems’s Populate can only generate only very random text just from letters or numbers. Faker has many realizations for some other languages, such as NodeJS, PHP, Perl, Ruby. And this project uses Python’s realization with embedded Python feature in IRIS.

Python Faker has

  • 80+ locales, so, generated data, can be almost any language English, Russian, Chineese. Person names, Addresses and many other values can be localized
  • 20+ providers for many different types of data. Not everything is implemented in this project, yet, just some basic ones.
  • community providers can be added later as well

screenshot

Prerequisites

Installation

Clone/git pull the repo into any local directory

git clone https://github.com/caretdev/iris-python-faker.git

Open the terminal in this directory and run the command to build and run IRIS container:

DOCKER_BUILDKIT=1 docker-compose up --build -d

Check the port selected for web by Docker with command

docker-compose ps

And open in the browser http://localhost:52773/faker/index.html (Replace 52773 port with port from ps’s output). Or from menu in VSCode.

menu

Install with ZPM

The package is available to be installed with zpm.

zpm "install python-faker"

It requires IRIS version with Python Embedded feature (2021.2+) and package faker installed with python-pip.

Usage UI

Add rows to table, as many as many columns you need in generating table. Select datatypes from the list of available types, and enter name for colummn.

select-datatype

On the bottom toolbar, you can select Locale, and change the amount of preview rows to be generated on each change.

select-locales

Generate button, will open a dialog, where you will be able to enter how many rows to generate and desired class name. If you wish to add data to an existing class uncheck Create class. In case of any errors happend on the server side during generation, it will show the error message.

generate-failed

generate-success

Usage programmatical

It is also possible to generate new data programmatically

  Set params = {
    "rows": 3,                // How many rows generate
    "className": (className), // Where to store generated data
    "locale": "en",           // Select Locale for generated data
    "columns": [{
      "type": "person_name",
      "name": "name"
    }, {
      "type": "date_of_birth",
      "name": "dob"
    }, {
      "type": "boolean",
      "name": "flag"
    }]
  }
  Set faker = ##class("caretdev.Faker.Main").%New()
  Do faker.%JSONImport(params)
  Quit:'$$$AssertStatusOK(faker.GenerateClass())
  Do $ClassMethod(className, "%KillExtent")

Set result = faker.Generate()
If $Extract(result)=0 Do $system.OBJ.DisplayError(result)
Write !,"Rows created",result.created

Or just generate without saving to class

  Set params = {
    "previewRows": 3,         // How many items generate
    "locale": "en",           // Select Locale for generated data
    "columns": [{
      "type": "person_name",
      "name": "name"
    }, {
      "type": "date_of_birth",
      "name": "dob"
    }, {
      "type": "boolean",
      "name": "flag"
    }]
  }
  Set faker = ##class("caretdev.Faker.Main").%New()
  Do faker.%JSONImport(params)

Set result = faker.Generate()
If $Extract(result)=0 Do $system.OBJ.DisplayError(result)
Set items = result."getitem"("items")
Set count = items."len"()
For i=0:1:count-1 {
Set item = items."getitem"(i)
Set name = item."getitem"("name")
Set dob = item."getitem"("dob")
Set flag = item."getitem"("flag")
}

Made with
Install
zpm install python-faker download archive
Version
0.0.231 Mar, 2022
ObjectScript quality test
Category
Technology Example
Works with
InterSystems IRIS
First published
08 Jan, 2022
Last checked by moderator
27 Jun, 2023Works