mimeograph


Namemimeograph JSON
Version 1.0.4 PyPI version JSON
download
home_page
SummaryGenerate NoSQL data based on a simple template
upload_time2023-06-27 07:07:28
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT License Copyright (c) 2023 Tomasz Aniołowski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords mimeograph mimeo generate generator data xml json nosql
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Mimeo (Mimeograph)

[![License](https://img.shields.io/github/license/TomaszAniolowski/mimeo?label=License&style=plastic)](https://github.com/TomaszAniolowski/mimeo/blob/develop/LICENSE)
[![Version](https://img.shields.io/pypi/v/mimeograph?color=blue&label=PyPI&style=plastic)](https://pypi.org/project/mimeograph/)
[![Python](https://img.shields.io/pypi/pyversions/mimeograph?label=Python&style=plastic)](https://www.python.org/)  
[![Build](https://img.shields.io/github/actions/workflow/status/TomaszAniolowski/mimeo/test.yml?color=brightgreen&label=Test%20Mimeo&style=plastic)](https://github.com/TomaszAniolowski/mimeo/actions/workflows/test.yml?query=branch%3Amain)
[![Code Coverage](https://img.shields.io/badge/Code%20Coverage-100%25-brightgreen?style=plastic)](https://github.com/TomaszAniolowski/mimeo/actions/workflows/coverage_badge.yml?query=branch%3Amain)

[Mimeo](https://github.com/TomaszAniolowski/mimeo) is a command line tool and a python library generating NoSQL data based on a template.
It can be used by developers, testers or business analysts in their daily work.


## Installation

Install Mimeo with pip

```sh
pip install mimeograph
```


## Usage/Examples

### Mimeo Configuration

Prepare Mimeo Configuration first

<table>
    <tr>
        <th>JSON</th>
        <th>XML</th>
    </tr>
    <tr>
        <td valign="top">

```json
{
  "_templates_": [
    {
      "count": 30,
      "model": {
        "SomeEntity": {
          "@xmlns": "http://mimeo.arch.com/default-namespace",
          "@xmlns:pn": "http://mimeo.arch.com/prefixed-namespace",
          "ChildNode1": 1,
          "ChildNode2": "value-2",
          "ChildNode3": true
        }
      }
    }
  ]
}
```
</td>
        <td valign="top">

```xml
<mimeo_configuration>
    <_templates_>
        <_template_>
            <count>30</count>
            <model>

                <SomeEntity
                    xmlns="http://mimeo.arch.com/default-namespace"
                    xmlns:pn="http://mimeo.arch.com/prefixed-namespace">
                    <ChildNode1>1</ChildNode1>
                    <pn:ChildNode2>value-2</pn:ChildNode2>
                    <ChildNode3>true</ChildNode3>
                </SomeEntity>

            </model>
        </_template_>
    </_templates_>
</mimeo_configuration>
```
</td>
  </tr>
</table>


_You can find more configuration examples in the `examples` folder._

### Data generation

The Mimeo Configuration above will produce 2 files:

```xml
<!-- mimeo-output/mimeo-output-1.xml-->
<SomeEntity xmlns="http://mimeo.arch.com/default-namespace" xmlns:pn="http://mimeo.arch.com/prefixed-namespace">
    <ChildNode1>1</ChildNode1>
    <pn:ChildNode2>value-2</pn:ChildNode2>
    <ChildNode3>true</ChildNode3>
</SomeEntity>
```
```xml
<!-- mimeo-output/mimeo-output-2.xml-->
<SomeEntity xmlns="http://mimeo.arch.com/default-namespace" xmlns:pn="http://mimeo.arch.com/prefixed-namespace">
    <ChildNode1>1</ChildNode1>
    <pn:ChildNode2>value-2</pn:ChildNode2>
    <ChildNode3>true</ChildNode3>
</SomeEntity>
```

When we would configure output format as `json` then it would produce JSON nodes:

```json
{
  "SomeEntity": {
    "@xmlns": "http://mimeo.arch.com/default-namespace",
    "@xmlns:pn": "http://mimeo.arch.com/prefixed-namespace",
    "ChildNode1": 1,
    "pn:ChildNode2": "value-2",
    "ChildNode3": true
  }
}
```
```json
{
  "SomeEntity": {
    "@xmlns": "http://mimeo.arch.com/default-namespace",
    "@xmlns:pn": "http://mimeo.arch.com/prefixed-namespace",
    "ChildNode1": 1,
    "pn:ChildNode2": "value-2",
    "ChildNode3": true
  }
}
```

```sh
mimeo SomeEntity-config.json
mimeo SomeEntity-config.xml
```


### Mimeo Utils

Mimeo exposes several functions for data generation that will make it more useful for testing purposes.
To see all Mimeo Utils, go to the documentation below.

**Template**
```json
{
  "count": 2,
  "model": {
    "SomeEntity": {
      "id": "{auto_increment}",
      "randomstring": "{random_str}",
      "randomint": "{random_int}"
    }
  }
}
```
```xml
<_template_>
    <count>2</count>
    <model>
        
        <SomeEntity>
            <id>{auto_increment}</id>
            <randomstring>{random_str}</randomstring>
            <randomint>{random_int}</randomint>
        </SomeEntity>
        
    </model>
</_template_>
```

**XML Data**
```xml
<SomeEntity>
    <id>00001</id>
    <randomstring>mCApsYZprayYkmKnYWxe</randomstring>
    <randomint>8</randomint>
</SomeEntity>
```
```xml
<SomeEntity>
    <id>00002</id>
    <randomstring>ceaPUqARUkFukZIPeuqO</randomstring>
    <randomint>99</randomint>
</SomeEntity>
```

**JSON Data**
```json
{
  "SomeEntity": {
    "id": "00001",
    "randomstring": "mCApsYZprayYkmKnYWxe",
    "randomint": 8
  }
}
```
```json
{
  "SomeEntity": {
    "id": "00002",
    "randomstring": "ceaPUqARUkFukZIPeuqO",
    "randomint": 99
  }
}
```


## Documentation

### Mimeo CLI

#### Mimeo Configuration arguments

When using Mimeo command line tool you can overwrite Mimeo Configuration properties:

| Short option | Long option         | Description                                                                    |
|:------------:|:--------------------|:-------------------------------------------------------------------------------|
|     `-F`     | `--format`          | overwrite the `output/format` property                                         |
|     `-o`     | `--output`          | overwrite the `output/direction` property                                      |
|     `-x`     | `--xml-declaration` | overwrite the `output/xml_declaration` property                                |
|     `-i`     | `--indent`          | overwrite the `output/indent` property                                         |
|     `-d`     | `--directory`       | overwrite the `output/directory_path` property                                 |
|     `-f`     | `--file`            | overwrite the `output/file_name` property                                      |
|     `-H`     | `--http-host`       | overwrite the `output/host` property                                           |
|     `-p`     | `--http-port`       | overwrite the `output/port` property                                           |
|     `-E`     | `--http-endpoint`   | overwrite the `output/endpoint` property                                       |
|     `-U`     | `--http-user`       | overwrite the `output/username` property                                       |
|     `-P`     | `--http-password`   | overwrite the `output/password` property                                       |
|              | `--http-method`     | overwrite the `output/method` property                                         |
|              | `--http-protocol`   | overwrite the `output/protocol` property                                       |
|     `-e`     | `--http-env`        | overwrite the output http properties using a mimeo env configuration           |
|              | `--http-envs-file`  | use a custom environments file (by default: mimeo.envs.json)                   |
|              | `--raw`             | same as `-o stdout`<br />overwrite the `output/direction` property to `stdout` |

#### Logging arguments

| Short option | Long option | Description       |
|:------------:|:------------|:------------------|
|              | `--silent`  | disable INFO logs |
|              | `--debug`   | enable DEBUG mode |
|              | `--fine`    | enable FINE mode  |

#### Other arguments

| Short option | Long option      | Description                                     |
|:------------:|:-----------------|:------------------------------------------------|
|              | `--sequentially` | process Mimeo Configurations in a single thread |

### Mimeo Configuration

Mimeo configuration is defined in a JSON file using internal settings and data templates.

| Key                      |  Level   |      Required      |     Supported values     |    Default     | Description                                                                                                                                             |
|:-------------------------|:--------:|:------------------:|:------------------------:|:--------------:|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| `output`                 |  Config  |        :x:         |          object          |      ---       | Defines output details on how it will be consumed                                                                                                       |
| `output/direction`       |  Config  |        :x:         | `file`, `stdout`, `http` |     `file`     | Defines how output will be consumed                                                                                                                     |
| `output/format`          |  Config  |        :x:         |      `xml`, `json`       |     `xml`      | Defines output data format                                                                                                                              |
| `output/indent`          |  Config  |        :x:         |         integer          |     `null`     | Defines indent applied in output data                                                                                                                   |
| `output/xml_declaration` |  Config  |        :x:         |         boolean          |    `false`     | Indicates whether an xml declaration should be added to output data                                                                                     |
| `output/directory_path`  |  Config  |        :x:         |          string          | `mimeo-output` | For `file` direction - defines an output directory                                                                                                      |
| `output/file_name`       |  Config  |        :x:         |          string          | `mimeo-output` | For `file` direction - defines an output file name                                                                                                      |
| `output/method`          |  Config  |        :x:         |      `POST`, `PUT`       |     `POST`     | For `http` direction - defines a request method                                                                                                         |
| `output/protocol`        |  Config  |        :x:         |     `http`, `https`      |     `http`     | For `http` direction - defines a url protocol                                                                                                           |
| `output/host`            |  Config  | :heavy_check_mark: |          string          |      ---       | For `http` direction - defines a url host                                                                                                               |
| `output/port`            |  Config  |        :x:         |         integer          |     `null`     | For `http` direction - defines a url port (can be empty)                                                                                                |
| `output/endpoint`        |  Config  | :heavy_check_mark: |          string          |      ---       | For `http` direction - defines a url endpoint                                                                                                           |
| `output/username`        |  Config  | :heavy_check_mark: |          string          |      ---       | For `http` direction - defines a username                                                                                                               |
| `output/password`        |  Config  | :heavy_check_mark: |          string          |      ---       | For `http` direction - defines a password                                                                                                               |
| `vars`                   |  Config  |        :x:         |          object          |      ---       | Defines variables to be used in a Mimeo Template (read more in next section)                                                                            |
| `_templates_`            |  Config  | :heavy_check_mark: |          array           |      ---       | Stores templates for data generation                                                                                                                    |
| `count`                  | Template | :heavy_check_mark: |         integer          |      ---       | Indicates number of copies                                                                                                                              |
| `model`                  | Template | :heavy_check_mark: |          object          |      ---       | Defines data template to be copied                                                                                                                      |
| `context`                |  Model   |        :x:         |          object          |      ---       | Defines a context name that is internally used e.g. using `curr_iter()` and `get_key()` mimeo utils (by default model name is used as the context name) |

#### Mimeo Environment

To make `http` output directory easier to use, mimeo allows you to configure Mimeo Environments.
They are configured in a JSON file (by default: mimeo.envs.json) and support the following output details:
- `protocol`
- `host`
- `port`
- `username`
- `password`

Example
```json
{
    "local": {
        "host": "localhost",
        "port": 8000,
        "username": "admin",
        "password": "admin"
    },
    "dev": {
        "protocol": "https",
        "host": "11.111.11.111",
        "port": 8000,
        "username": "some-user",
        "password": "some-password"
    }
}
```

To use a specific Mimeo Environment you can use the following commands:
```sh
mimeo SomeEntity-config.json -e dev
mimeo SomeEntity-config.json -e dev --http-envs-file environments.json
```

#### Mimeo Vars

Mimeo allows you to define a list of variables.
You can use them in your Mimeo Config by wrapping them in curly brackets [`{VARIABLE}`].

There are only 2 rules for variable names:
- Variable name can include upper-cased letters \[`A-Z`\], underscore \[`_`\] and digits \{`0-9`\} only
- Variable name must start with a letter

Variable can be defined with:
- any atomic value
- any other variable defined
- any Mimeo Util

You can use Mimeo Vars as partial values (unless they are defined as Mimeo Utils).

Example:
```json
{
  "vars": {
    "CUSTOM_VAR_1": "custom-value-1",
    "CUSTOM_VAR_2": 1,
    "CUSTOM_VAR_3": true,
    "CUSTOM_VAR_4": "{CUSTOM_VAR_2}",
    "CUSTOM_VAR_5": "{auto_increment}",
    "CUSTOM_VAR_6": {
      "_mimeo_util": {
        "_name": "random_int",
        "limit": 99
      }
    }
  },
  "_templates_": [
    {
      "count": 5,
      "model": {
        "SomeEntity": {
          "ChildNode1": "{CUSTOM_VAR_1}",
          "ChildNode2": "{CUSTOM_VAR_2}",
          "ChildNode3": "{CUSTOM_VAR_3}",
          "ChildNode4": "{CUSTOM_VAR_4}",
          "ChildNode5": "{CUSTOM_VAR_5}",
          "ChildNode6": "{CUSTOM_VAR_6}",
          "ChildNode7": "{CUSTOM_VAR_1}-with-suffix"
        }
      }
    }
  ]
}
```

#### Mimeo Special Fields

In Mimeo Template you can use so-called _special fields_.
Every field in a template can be stored in memory (_provided_) and used later as a value of other fields (_injected_).
To provide a special field, wrap its name with colons: [`:SomeField:`]. To inject, use additionally curly braces to
let interpreter know it should be rendered [`{:SomeField:}`].
They can be injected as partial values, similarly to Mimeo Vars.

Example
```json
{
  "_templates_": [
    {
      "count": 5,
      "model": {
        "SomeEntity": {
          ":ChildNode1:": "custom-value",
          "ChildNode2": "{:ChildNode1:}",
          "ChildNode3": "{:ChildNode1:}-with-suffix"
        }
      }
    }
  ]
}
```

#### Mimeo Utils

You can use several predefined functions to generate data. They can be used in a _raw_ format or _parametrized_.

##### Random String

Generates a random string value.

| Parameter | Supported values | Default |
|:---------:|:----------------:|:-------:|
|  length   |      `int`       |  `20`   |

###### Raw

Uses the default length: 20 characters.

```json
{
  "randomstring": "{random_str}"
}
```

###### Parametrized

Uses the customized length.

```json
{
  "randomstring": {
    "_mimeo_util": {
      "_name": "random_str",
      "length": 5
    }
  }
}
```

##### Random Integer

Generates a random integer value between `start` and `limit` parameters (inclusive).

| Parameter | Supported values | Default |
|:---------:|:----------------:|:-------:|
|   start   |      `int`       |   `1`   |
|   limit   |      `int`       |  `100`  |

###### Raw

Uses the default start (1) and limit (100) values.

```json
{
  "randominteger": "{random_int}"
}
```

###### Parametrized

Uses the customized limit.

```json
{
  "randominteger1": {
    "_mimeo_util": {
      "_name": "random_int",
      "start": 0
    }
  },
  "randominteger2": {
    "_mimeo_util": {
      "_name": "random_int",
      "limit": 5
    }
  },
  "randominteger3": {
    "_mimeo_util": {
      "_name": "random_int",
      "start": 0,
      "limit": 5
    }
  }
}
```

##### Random Item

Generates a random value from items provided.  
NOTICE: The raw form of this Mimeo Util will generate a blank string value (as same as no items parametrized).

| Parameter | Supported values | Default |
|:---------:|:----------------:|:-------:|
|   items   |      `list`      | `[""]`  |

###### Parametrized

```json
{
  "random": {
    "_mimeo_util": {
      "_name": "random_item",
      "items": ["value", 1, true]
    }
  }
}
```

##### Date

Generates a date value in format `YYYY-MM-DD`.

| Parameter  | Supported values | Default |
|:----------:|:----------------:|:-------:|
| days_delta |      `int`       |   `0`   |

###### Raw

Uses the today's date.

```json
{
  "Today": "{date}"
}
```

###### Parametrized

Uses the customized days delta.

```json
{
  "Yesterday": {
    "_mimeo_util": {
      "_name": "date",
      "days_delta": -1
    }
  },
  "Tomorrow": {
    "_mimeo_util": {
      "_name": "date",
      "days_delta": 1
    }
  }
}
```

##### Date Time

Generates a date time value in format `YYYY-MM-DD'T'HH:mm:SS`.

|   Parameter   | Supported values | Default |
|:-------------:|:----------------:|:-------:|
|  days_delta   |      `int`       |   `0`   |
|  hours_delta  |      `int`       |   `0`   |
| minutes_delta |      `int`       |   `0`   |
| seconds_delta |      `int`       |   `0`   |

###### Raw

Uses the current timestamp.

```json
{
  "Now": "{date_time}"
}
```

###### Parametrized

Uses the customized deltas.

```json
{
  "TomorrowThreeHoursLaterTwentyMinutesAgoTwoSecondsLater": {
    "_mimeo_util": {
      "_name": "date_time",
      "days_delta": 1,
      "hours_delta": 3,
      "minutes_delta": -20,
      "seconds_delta": 2
    }
  }
}
```

##### Auto Increment

Generates a next integer in context of a model (in nested templates it will use a separated context).

| Parameter | Supported values | Default  |
|:---------:|:----------------:|:--------:|
|  pattern  |      `str`       | `{:05d}` |

###### Raw

Uses a default pattern: **{:05d}** (an integer with 5 leading zeros).

```json
{
  "ID": "{auto_increment}"
}
```

###### Parametrized

Uses the string pattern provided.

```json
{
  "ID": {
    "_mimeo_util": {
      "_name": "auto_increment",
      "pattern": "MY_ID_{:010d}"
    }
  }
}
```

##### Current Iteration

Generates a value of the current iteration in a Mimeo Template context.

| Parameter | Supported values |      Default      |
|:---------:|:----------------:|:-----------------:|
|  context  |      `str`       | a current context |

###### Raw

Uses the current context.

```json
{
  "ID": "{curr_iter}"
}
```

###### Parametrized

Uses a specific Mimeo Model context (model name when `context` is not configured).

```json
{
  "Parent": {
    "_mimeo_util": {
      "_name": "curr_iter",
      "context": "SomeEntity"
    }
  }
}
```

##### Key

Generates a key unique across all Mimeo Models and being the same within a single Mimeo Model context.

| Parameter | Supported values |              Default               |
|:---------:|:----------------:|:----------------------------------:|
|  context  |      `str`       |         a current context          |
| iteration |      `int`       | a current iteration of the context |

###### Raw

Uses a key from the current context and iteration.

```json
{
  "ID": "{key}"
}
```

###### Parametrized

Uses a key from the specific context and iteration.  
When context is indicated and iteration is not, then the current iteration **of the indicated context** is being used.

```json
{
  "SomeEntity2": {
    "_mimeo_util": {
      "_name": "key",
      "context": "SomeEntity",
      "iteration": "{curr_iter}"
    }
  }
}
```

##### City

Generates a city name.

| Parameter | Supported values | Default |
|:---------:|:----------------:|:-------:|
|  unique   |      `bool`      | `True`  |
|  country  |      `str`       | `None`  |

###### Raw

By default city names will be unique across a Mimeo Context.

```json
{
  "City": "{city}"
}
```

###### Parametrized

Uses country (name, iso2, iso3) and `unique` flag to generate a city name.

```json
{
  "CityWithDuplicates": {
    "_mimeo_util": {
      "_name": "city",
      "unique": false
    }
  },
  "CityOfCountryName": {
    "_mimeo_util": {
      "_name": "city",
      "country": "United Kingdom"
    }
  },
  "CityOfCountryISO2": {
    "_mimeo_util": {
      "_name": "city",
      "country": "GB"
    }
  },
  "CityOfCountryISO3": {
    "_mimeo_util": {
      "_name": "city",
      "country": "GBR"
    }
  },
  "CityOfCountryWithDuplicates": {
    "_mimeo_util": {
      "_name": "city",
      "country": "United Kingdom",
      "unique": false
    }
  }
}
```

##### Country

Generates a country name (by default), iso2 or iso3.

| Parameter |       Supported values       | Default  |
|:---------:|:----------------------------:|:--------:|
|  unique   |            `bool`            |  `True`  |
|   value   | `"name"`, `"iso3"`, `"iso2"` | `"name"` |
|  country  |            `str`             |  `None`  |

###### Raw

By default country names will be unique across a Mimeo Context.

```json
{
  "Country": "{country}"
}
```

###### Parametrized

It can generate:
- country iso3 or iso 2 instead of name
- country with duplicates
- country name for a provided iso3 or iso2
- country iso2 for a provided name or iso3
- country iso3 for a provided name or iso2

When the `country` param is provided then the `unique` flag is ignored.

```json
{
  "CountryNameWithDuplicates": {
    "_mimeo_util": {
      "_name": "country",
      "unique": false
    }
  },
  "CountryISO2": {
    "_mimeo_util": {
      "_name": "country",
      "value": "iso2"
    }
  },
  "CountryISO3": {
    "_mimeo_util": {
      "_name": "country",
      "value": "iso3"
    }
  },
  "CountryNameForISO3": {
    "_mimeo_util": {
      "_name": "country",
      "country": "GBR"
    }
  },
  "CountryISO2ForName": {
    "_mimeo_util": {
      "_name": "country",
      "value": "iso2",
      "country": "United Kingdom"
    }
  }
}
```

##### Currency

Generates a currency code (by default) or name.

| Parameter |  Supported values  | Default  |
|:---------:|:------------------:|:--------:|
|  unique   |       `bool`       | `False`  |
|   value   | `"code"`, `"name"` | `"code"` |
|  country  |       `str`        |  `None`  |

###### Raw

By default city names will _NOT_ be unique across a Mimeo Context.

```json
{
  "Currency": "{currency}"
}
```

###### Parametrized

It can generate:
- unique currencies
- currency name instead of code
- currency code or name of a specific country (using iso3, iso2 or name)

When the `country` param is provided then the `unique` flag is ignored.

```json
{
  "UniqueCurrencyCode": {
    "_mimeo_util": {
      "_name": "currency",
      "unique": true
    }
  },
  "CurrencyName": {
    "_mimeo_util": {
      "_name": "currency",
      "value": "name"
    }
  },
  "CurrencyCodeForCountryISO3": {
    "_mimeo_util": {
      "_name": "currency",
      "country": "GBR"
    }
  },
  "CurrencyNameForCountryISO2": {
    "_mimeo_util": {
      "_name": "currency",
      "value": "name",
      "country": "GB"
    }
  },
  "CurrencyNameForCountryName": {
    "_mimeo_util": {
      "_name": "currency",
      "value": "name",
      "country": "United Kingdom"
    }
  }
}
```

##### First Name

Generates a first name.

| Parameter |      Supported values      | Default  |
|:---------:|:--------------------------:|:--------:|
|  unique   |           `bool`           |  `True`  |
|    sex    | `M`, `Male`, `F`, `Female` |  `None`  |

###### Raw

By default first names will be unique across a Mimeo Context.

```json
{
  "FirstName": "{first_name}"
}
```

###### Parametrized

Uses sex (`M` / `Male` / `F` / `Female`) and `unique` flag to generate a first name.

```json
{
  "FirstNameWithDuplicates": {
    "_mimeo_util": {
      "_name": "first_name",
      "unique": false
    }
  },
  "MaleFirstName": {
    "_mimeo_util": {
      "_name": "first_name",
      "sex": "M"
    }
  },
  "FemaleFirstName": {
    "_mimeo_util": {
      "_name": "first_name",
      "sex": "F"
    }
  },
  "MaleFirstNameWithDuplicates": {
    "_mimeo_util": {
      "_name": "first_name",
      "sex": "M",
      "unique": false
    }
  }
}
```

##### Last Name

Generates a last name.

| Parameter | Supported values | Default  |
|:---------:|:----------------:|:--------:|
|  unique   |      `bool`      |  `True`  |

###### Raw

By default last names will be unique across a Mimeo Context.

```json
{
  "LastName": "{last_name}"
}
```

###### Parametrized

Uses `unique` flag to generate a last name.

```json
{
  "LastNameWithDuplicates": {
    "_mimeo_util": {
      "_name": "last_name",
      "unique": false
    }
  }
}
```

### Python Lib

To generate data using Mimeo as a python library you need 3 classes:
* `MimeoConfig` (A python representation of a Mimeo Configuration)
* `MimeoConfigFactory` (A factory parsing a Mimeo Configuration)
* `Mimeograph` (a class generating and consuming data from a Mimeo Configuration)

#### Parsing Mimeo Configuration

##### `MimeoConfig`

The `MimeoConfig` class takes a dictionary as a parameter and initializes all settings.

```python
from mimeo import MimeoConfig

config = {
  "_templates_": [
    {
      "count": 30,
      "model": {
        "SomeEntity": {
          "@xmlns": "http://mimeo.arch.com/default-namespace",
          "@xmlns:pn": "http://mimeo.arch.com/prefixed-namespace",
          "ChildNode1": 1,
          "ChildNode2": "value-2",
          "ChildNode3": True
        }
      }
    }
  ]
}
mimeo_config = MimeoConfig(config)
```

##### `MimeoConfigFactory`

To easily parse Mimeo Configuration you can use the `MimeoConfigFactory`.
It allows you to provide a raw config as:
* a dictionary
* a stringified XML node
* a file path

<table>
    <tr>
        <th></th>
        <th>JSON</th>
        <th>XML</th>
    </tr>
    <tr>
        <td><b>Raw data</b></td>
        <td valign="top">

```python
from mimeo import MimeoConfigFactory

config = {
  "_templates_": [
    {
      "count": 30,
      "model": {
        "SomeEntity": {
          "@xmlns": "http://mimeo.arch.com/default-namespace",
          "@xmlns:pn": "http://mimeo.arch.com/prefixed-namespace",
          "ChildNode1": 1,
          "ChildNode2": "value-2",
          "ChildNode3": True
        }
      }
    }
  ]
}
mimeo_config = MimeoConfigFactory.parse(config)
```
</td>
    <td valign="top">

```python
from mimeo import MimeoConfigFactory

config = (
    '<mimeo_configuration>'
    '    <_templates_>'
    '        <_template_>'
    '            <count>30</count>'
    '            <model>'
    ''
    '                <SomeEntity'
    '                    xmlns="http://mimeo.arch.com/default-namespace"'
    '                    xmlns:pn="http://mimeo.arch.com/prefixed-namespace">'
    '                    <ChildNode1>1</ChildNode1>'
    '                    <pn:ChildNode2>value-2</pn:ChildNode2>'
    '                    <ChildNode3>true</ChildNode3>'
    '                </SomeEntity>'
    ''
    '            </model>'
    '        </_template_>'
    '    </_templates_>'
    '</mimeo_configuration>')
mimeo_config = MimeoConfigFactory.parse(config)
```
</td>
  </tr>
    <tr>
        <td><b>File path</b></td>
        <td valign="top">

```python
from mimeo import MimeoConfigFactory

config = "SomeEntity-config.json"
mimeo_config = MimeoConfigFactory.parse(config)
```
</td>
    <td valign="top">

```python
from mimeo import MimeoConfigFactory

config = "SomeEntity-config.xml"
mimeo_config = MimeoConfigFactory.parse(config)
```
</td>
  </tr>
</table>

#### Processing Mimeo Configuration

Using the Mimeo as a python library you can use 2 processing approaches:
* sequential processing
* processing in parallel (used by default in Mimeo CLI)

Both need the `Mimeograph` class.


##### Sequential processing

Sequential processing is pretty straightforward and can be done without `Mimeograph` instantiation.

###### Processing

To simply process data from a Mimeo Configuration you can use the `Mimeograph.process()` method:
```python
from mimeo import MimeoConfigFactory, Mimeograph

config_path = "examples/1-introduction/01-basic.json"
mimeo_config = MimeoConfigFactory.parse(config_path)
Mimeograph.process(mimeo_config)
```

It will generate data and consume it immediately.

###### Generating only

If you're going to generate data and use it as a python representation
(`dict`, `xml.etree.ElementTree.Element`) - use `Mimeograph.generate()` method:
```python
from mimeo import MimeoConfigFactory, Mimeograph

config_path = "examples/1-introduction/01-basic.json"
mimeo_config = MimeoConfigFactory.parse(config_path)
data = Mimeograph.generate(mimeo_config)
```

###### Generating and consuming in 2 stages

In case you would like to somehow modify generated data before it will be consumed,
use `Mimeograph.generate()` and `Mimeograph.consume()` methods.
```python
from mimeo import MimeoConfigFactory, Mimeograph

config_path = "examples/1-introduction/01-basic.json"
mimeo_config = MimeoConfigFactory.parse(config_path)
data = Mimeograph.generate(mimeo_config)
# ... your modifications ...
Mimeograph.consume(mimeo_config, data)
```

##### Processing in parallel

When you're going to process data (generate and consume) from several Mimeo Configurations
processing in parallel is more performant way. To do that, you need use the `Mimeograph` as a Context Manager
and submit configs together with some kind of identifier (e.g. config path). Thanks to that you will know
which config has failed (if so).

```python
from mimeo import MimeoConfigFactory, Mimeograph

config_paths = [
    "examples/1-introduction/01-basic.json",
    "examples/1-introduction/02-complex.json",
    "examples/1-introduction/03-output-format-xml.json",
    "examples/1-introduction/04-output-format-json.json",
]
with Mimeograph() as mimeo:
    for config_path in config_paths:
        mimeo_config = MimeoConfigFactory.parse(config_path)
        mimeo_config.output.direction = "stdout"
        mimeo.submit((config_path, mimeo_config))
```

## License

MIT


## Authors

- [@TomaszAniolowski](https://www.github.com/TomaszAniolowski)


## Acknowledgements

 - [SimpleMaps.com](https://simplemaps.com/data/world-cities) (Cities & countries data)
 - [@hadley/data-baby-names](https://github.com/hadley/data-baby-names/) (Forenames data)
 - [@fivethirtyeigh/data/most-common-name](https://github.com/fivethirtyeight/data/tree/master/most-common-name) (Surnames data)
 - [@datasets/currency-codes](https://github.com/datasets/currency-codes/) (Currencies data)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "mimeograph",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "mimeograph,mimeo,generate,generator,data,xml,json,nosql",
    "author": "",
    "author_email": "\"T.A. Programming Svcs.\" <tomasz.maciej.aniolowski@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/c9/f9/123a4f84b49d741fe00284f07e0396edea14f9ea72acbebf42639c8e0645/mimeograph-1.0.4.tar.gz",
    "platform": null,
    "description": "# Mimeo (Mimeograph)\n\n[![License](https://img.shields.io/github/license/TomaszAniolowski/mimeo?label=License&style=plastic)](https://github.com/TomaszAniolowski/mimeo/blob/develop/LICENSE)\n[![Version](https://img.shields.io/pypi/v/mimeograph?color=blue&label=PyPI&style=plastic)](https://pypi.org/project/mimeograph/)\n[![Python](https://img.shields.io/pypi/pyversions/mimeograph?label=Python&style=plastic)](https://www.python.org/)  \n[![Build](https://img.shields.io/github/actions/workflow/status/TomaszAniolowski/mimeo/test.yml?color=brightgreen&label=Test%20Mimeo&style=plastic)](https://github.com/TomaszAniolowski/mimeo/actions/workflows/test.yml?query=branch%3Amain)\n[![Code Coverage](https://img.shields.io/badge/Code%20Coverage-100%25-brightgreen?style=plastic)](https://github.com/TomaszAniolowski/mimeo/actions/workflows/coverage_badge.yml?query=branch%3Amain)\n\n[Mimeo](https://github.com/TomaszAniolowski/mimeo) is a command line tool and a python library generating NoSQL data based on a template.\nIt can be used by developers, testers or business analysts in their daily work.\n\n\n## Installation\n\nInstall Mimeo with pip\n\n```sh\npip install mimeograph\n```\n\n\n## Usage/Examples\n\n### Mimeo Configuration\n\nPrepare Mimeo Configuration first\n\n<table>\n    <tr>\n        <th>JSON</th>\n        <th>XML</th>\n    </tr>\n    <tr>\n        <td valign=\"top\">\n\n```json\n{\n  \"_templates_\": [\n    {\n      \"count\": 30,\n      \"model\": {\n        \"SomeEntity\": {\n          \"@xmlns\": \"http://mimeo.arch.com/default-namespace\",\n          \"@xmlns:pn\": \"http://mimeo.arch.com/prefixed-namespace\",\n          \"ChildNode1\": 1,\n          \"ChildNode2\": \"value-2\",\n          \"ChildNode3\": true\n        }\n      }\n    }\n  ]\n}\n```\n</td>\n        <td valign=\"top\">\n\n```xml\n<mimeo_configuration>\n    <_templates_>\n        <_template_>\n            <count>30</count>\n            <model>\n\n                <SomeEntity\n                    xmlns=\"http://mimeo.arch.com/default-namespace\"\n                    xmlns:pn=\"http://mimeo.arch.com/prefixed-namespace\">\n                    <ChildNode1>1</ChildNode1>\n                    <pn:ChildNode2>value-2</pn:ChildNode2>\n                    <ChildNode3>true</ChildNode3>\n                </SomeEntity>\n\n            </model>\n        </_template_>\n    </_templates_>\n</mimeo_configuration>\n```\n</td>\n  </tr>\n</table>\n\n\n_You can find more configuration examples in the `examples` folder._\n\n### Data generation\n\nThe Mimeo Configuration above will produce 2 files:\n\n```xml\n<!-- mimeo-output/mimeo-output-1.xml-->\n<SomeEntity xmlns=\"http://mimeo.arch.com/default-namespace\" xmlns:pn=\"http://mimeo.arch.com/prefixed-namespace\">\n    <ChildNode1>1</ChildNode1>\n    <pn:ChildNode2>value-2</pn:ChildNode2>\n    <ChildNode3>true</ChildNode3>\n</SomeEntity>\n```\n```xml\n<!-- mimeo-output/mimeo-output-2.xml-->\n<SomeEntity xmlns=\"http://mimeo.arch.com/default-namespace\" xmlns:pn=\"http://mimeo.arch.com/prefixed-namespace\">\n    <ChildNode1>1</ChildNode1>\n    <pn:ChildNode2>value-2</pn:ChildNode2>\n    <ChildNode3>true</ChildNode3>\n</SomeEntity>\n```\n\nWhen we would configure output format as `json` then it would produce JSON nodes:\n\n```json\n{\n  \"SomeEntity\": {\n    \"@xmlns\": \"http://mimeo.arch.com/default-namespace\",\n    \"@xmlns:pn\": \"http://mimeo.arch.com/prefixed-namespace\",\n    \"ChildNode1\": 1,\n    \"pn:ChildNode2\": \"value-2\",\n    \"ChildNode3\": true\n  }\n}\n```\n```json\n{\n  \"SomeEntity\": {\n    \"@xmlns\": \"http://mimeo.arch.com/default-namespace\",\n    \"@xmlns:pn\": \"http://mimeo.arch.com/prefixed-namespace\",\n    \"ChildNode1\": 1,\n    \"pn:ChildNode2\": \"value-2\",\n    \"ChildNode3\": true\n  }\n}\n```\n\n```sh\nmimeo SomeEntity-config.json\nmimeo SomeEntity-config.xml\n```\n\n\n### Mimeo Utils\n\nMimeo exposes several functions for data generation that will make it more useful for testing purposes.\nTo see all Mimeo Utils, go to the documentation below.\n\n**Template**\n```json\n{\n  \"count\": 2,\n  \"model\": {\n    \"SomeEntity\": {\n      \"id\": \"{auto_increment}\",\n      \"randomstring\": \"{random_str}\",\n      \"randomint\": \"{random_int}\"\n    }\n  }\n}\n```\n```xml\n<_template_>\n    <count>2</count>\n    <model>\n        \n        <SomeEntity>\n            <id>{auto_increment}</id>\n            <randomstring>{random_str}</randomstring>\n            <randomint>{random_int}</randomint>\n        </SomeEntity>\n        \n    </model>\n</_template_>\n```\n\n**XML Data**\n```xml\n<SomeEntity>\n    <id>00001</id>\n    <randomstring>mCApsYZprayYkmKnYWxe</randomstring>\n    <randomint>8</randomint>\n</SomeEntity>\n```\n```xml\n<SomeEntity>\n    <id>00002</id>\n    <randomstring>ceaPUqARUkFukZIPeuqO</randomstring>\n    <randomint>99</randomint>\n</SomeEntity>\n```\n\n**JSON Data**\n```json\n{\n  \"SomeEntity\": {\n    \"id\": \"00001\",\n    \"randomstring\": \"mCApsYZprayYkmKnYWxe\",\n    \"randomint\": 8\n  }\n}\n```\n```json\n{\n  \"SomeEntity\": {\n    \"id\": \"00002\",\n    \"randomstring\": \"ceaPUqARUkFukZIPeuqO\",\n    \"randomint\": 99\n  }\n}\n```\n\n\n## Documentation\n\n### Mimeo CLI\n\n#### Mimeo Configuration arguments\n\nWhen using Mimeo command line tool you can overwrite Mimeo Configuration properties:\n\n| Short option | Long option         | Description                                                                    |\n|:------------:|:--------------------|:-------------------------------------------------------------------------------|\n|     `-F`     | `--format`          | overwrite the `output/format` property                                         |\n|     `-o`     | `--output`          | overwrite the `output/direction` property                                      |\n|     `-x`     | `--xml-declaration` | overwrite the `output/xml_declaration` property                                |\n|     `-i`     | `--indent`          | overwrite the `output/indent` property                                         |\n|     `-d`     | `--directory`       | overwrite the `output/directory_path` property                                 |\n|     `-f`     | `--file`            | overwrite the `output/file_name` property                                      |\n|     `-H`     | `--http-host`       | overwrite the `output/host` property                                           |\n|     `-p`     | `--http-port`       | overwrite the `output/port` property                                           |\n|     `-E`     | `--http-endpoint`   | overwrite the `output/endpoint` property                                       |\n|     `-U`     | `--http-user`       | overwrite the `output/username` property                                       |\n|     `-P`     | `--http-password`   | overwrite the `output/password` property                                       |\n|              | `--http-method`     | overwrite the `output/method` property                                         |\n|              | `--http-protocol`   | overwrite the `output/protocol` property                                       |\n|     `-e`     | `--http-env`        | overwrite the output http properties using a mimeo env configuration           |\n|              | `--http-envs-file`  | use a custom environments file (by default: mimeo.envs.json)                   |\n|              | `--raw`             | same as `-o stdout`<br />overwrite the `output/direction` property to `stdout` |\n\n#### Logging arguments\n\n| Short option | Long option | Description       |\n|:------------:|:------------|:------------------|\n|              | `--silent`  | disable INFO logs |\n|              | `--debug`   | enable DEBUG mode |\n|              | `--fine`    | enable FINE mode  |\n\n#### Other arguments\n\n| Short option | Long option      | Description                                     |\n|:------------:|:-----------------|:------------------------------------------------|\n|              | `--sequentially` | process Mimeo Configurations in a single thread |\n\n### Mimeo Configuration\n\nMimeo configuration is defined in a JSON file using internal settings and data templates.\n\n| Key                      |  Level   |      Required      |     Supported values     |    Default     | Description                                                                                                                                             |\n|:-------------------------|:--------:|:------------------:|:------------------------:|:--------------:|---------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `output`                 |  Config  |        :x:         |          object          |      ---       | Defines output details on how it will be consumed                                                                                                       |\n| `output/direction`       |  Config  |        :x:         | `file`, `stdout`, `http` |     `file`     | Defines how output will be consumed                                                                                                                     |\n| `output/format`          |  Config  |        :x:         |      `xml`, `json`       |     `xml`      | Defines output data format                                                                                                                              |\n| `output/indent`          |  Config  |        :x:         |         integer          |     `null`     | Defines indent applied in output data                                                                                                                   |\n| `output/xml_declaration` |  Config  |        :x:         |         boolean          |    `false`     | Indicates whether an xml declaration should be added to output data                                                                                     |\n| `output/directory_path`  |  Config  |        :x:         |          string          | `mimeo-output` | For `file` direction - defines an output directory                                                                                                      |\n| `output/file_name`       |  Config  |        :x:         |          string          | `mimeo-output` | For `file` direction - defines an output file name                                                                                                      |\n| `output/method`          |  Config  |        :x:         |      `POST`, `PUT`       |     `POST`     | For `http` direction - defines a request method                                                                                                         |\n| `output/protocol`        |  Config  |        :x:         |     `http`, `https`      |     `http`     | For `http` direction - defines a url protocol                                                                                                           |\n| `output/host`            |  Config  | :heavy_check_mark: |          string          |      ---       | For `http` direction - defines a url host                                                                                                               |\n| `output/port`            |  Config  |        :x:         |         integer          |     `null`     | For `http` direction - defines a url port (can be empty)                                                                                                |\n| `output/endpoint`        |  Config  | :heavy_check_mark: |          string          |      ---       | For `http` direction - defines a url endpoint                                                                                                           |\n| `output/username`        |  Config  | :heavy_check_mark: |          string          |      ---       | For `http` direction - defines a username                                                                                                               |\n| `output/password`        |  Config  | :heavy_check_mark: |          string          |      ---       | For `http` direction - defines a password                                                                                                               |\n| `vars`                   |  Config  |        :x:         |          object          |      ---       | Defines variables to be used in a Mimeo Template (read more in next section)                                                                            |\n| `_templates_`            |  Config  | :heavy_check_mark: |          array           |      ---       | Stores templates for data generation                                                                                                                    |\n| `count`                  | Template | :heavy_check_mark: |         integer          |      ---       | Indicates number of copies                                                                                                                              |\n| `model`                  | Template | :heavy_check_mark: |          object          |      ---       | Defines data template to be copied                                                                                                                      |\n| `context`                |  Model   |        :x:         |          object          |      ---       | Defines a context name that is internally used e.g. using `curr_iter()` and `get_key()` mimeo utils (by default model name is used as the context name) |\n\n#### Mimeo Environment\n\nTo make `http` output directory easier to use, mimeo allows you to configure Mimeo Environments.\nThey are configured in a JSON file (by default: mimeo.envs.json) and support the following output details:\n- `protocol`\n- `host`\n- `port`\n- `username`\n- `password`\n\nExample\n```json\n{\n    \"local\": {\n        \"host\": \"localhost\",\n        \"port\": 8000,\n        \"username\": \"admin\",\n        \"password\": \"admin\"\n    },\n    \"dev\": {\n        \"protocol\": \"https\",\n        \"host\": \"11.111.11.111\",\n        \"port\": 8000,\n        \"username\": \"some-user\",\n        \"password\": \"some-password\"\n    }\n}\n```\n\nTo use a specific Mimeo Environment you can use the following commands:\n```sh\nmimeo SomeEntity-config.json -e dev\nmimeo SomeEntity-config.json -e dev --http-envs-file environments.json\n```\n\n#### Mimeo Vars\n\nMimeo allows you to define a list of variables.\nYou can use them in your Mimeo Config by wrapping them in curly brackets [`{VARIABLE}`].\n\nThere are only 2 rules for variable names:\n- Variable name can include upper-cased letters \\[`A-Z`\\], underscore \\[`_`\\] and digits \\{`0-9`\\} only\n- Variable name must start with a letter\n\nVariable can be defined with:\n- any atomic value\n- any other variable defined\n- any Mimeo Util\n\nYou can use Mimeo Vars as partial values (unless they are defined as Mimeo Utils).\n\nExample:\n```json\n{\n  \"vars\": {\n    \"CUSTOM_VAR_1\": \"custom-value-1\",\n    \"CUSTOM_VAR_2\": 1,\n    \"CUSTOM_VAR_3\": true,\n    \"CUSTOM_VAR_4\": \"{CUSTOM_VAR_2}\",\n    \"CUSTOM_VAR_5\": \"{auto_increment}\",\n    \"CUSTOM_VAR_6\": {\n      \"_mimeo_util\": {\n        \"_name\": \"random_int\",\n        \"limit\": 99\n      }\n    }\n  },\n  \"_templates_\": [\n    {\n      \"count\": 5,\n      \"model\": {\n        \"SomeEntity\": {\n          \"ChildNode1\": \"{CUSTOM_VAR_1}\",\n          \"ChildNode2\": \"{CUSTOM_VAR_2}\",\n          \"ChildNode3\": \"{CUSTOM_VAR_3}\",\n          \"ChildNode4\": \"{CUSTOM_VAR_4}\",\n          \"ChildNode5\": \"{CUSTOM_VAR_5}\",\n          \"ChildNode6\": \"{CUSTOM_VAR_6}\",\n          \"ChildNode7\": \"{CUSTOM_VAR_1}-with-suffix\"\n        }\n      }\n    }\n  ]\n}\n```\n\n#### Mimeo Special Fields\n\nIn Mimeo Template you can use so-called _special fields_.\nEvery field in a template can be stored in memory (_provided_) and used later as a value of other fields (_injected_).\nTo provide a special field, wrap its name with colons: [`:SomeField:`]. To inject, use additionally curly braces to\nlet interpreter know it should be rendered [`{:SomeField:}`].\nThey can be injected as partial values, similarly to Mimeo Vars.\n\nExample\n```json\n{\n  \"_templates_\": [\n    {\n      \"count\": 5,\n      \"model\": {\n        \"SomeEntity\": {\n          \":ChildNode1:\": \"custom-value\",\n          \"ChildNode2\": \"{:ChildNode1:}\",\n          \"ChildNode3\": \"{:ChildNode1:}-with-suffix\"\n        }\n      }\n    }\n  ]\n}\n```\n\n#### Mimeo Utils\n\nYou can use several predefined functions to generate data. They can be used in a _raw_ format or _parametrized_.\n\n##### Random String\n\nGenerates a random string value.\n\n| Parameter | Supported values | Default |\n|:---------:|:----------------:|:-------:|\n|  length   |      `int`       |  `20`   |\n\n###### Raw\n\nUses the default length: 20 characters.\n\n```json\n{\n  \"randomstring\": \"{random_str}\"\n}\n```\n\n###### Parametrized\n\nUses the customized length.\n\n```json\n{\n  \"randomstring\": {\n    \"_mimeo_util\": {\n      \"_name\": \"random_str\",\n      \"length\": 5\n    }\n  }\n}\n```\n\n##### Random Integer\n\nGenerates a random integer value between `start` and `limit` parameters (inclusive).\n\n| Parameter | Supported values | Default |\n|:---------:|:----------------:|:-------:|\n|   start   |      `int`       |   `1`   |\n|   limit   |      `int`       |  `100`  |\n\n###### Raw\n\nUses the default start (1) and limit (100) values.\n\n```json\n{\n  \"randominteger\": \"{random_int}\"\n}\n```\n\n###### Parametrized\n\nUses the customized limit.\n\n```json\n{\n  \"randominteger1\": {\n    \"_mimeo_util\": {\n      \"_name\": \"random_int\",\n      \"start\": 0\n    }\n  },\n  \"randominteger2\": {\n    \"_mimeo_util\": {\n      \"_name\": \"random_int\",\n      \"limit\": 5\n    }\n  },\n  \"randominteger3\": {\n    \"_mimeo_util\": {\n      \"_name\": \"random_int\",\n      \"start\": 0,\n      \"limit\": 5\n    }\n  }\n}\n```\n\n##### Random Item\n\nGenerates a random value from items provided.  \nNOTICE: The raw form of this Mimeo Util will generate a blank string value (as same as no items parametrized).\n\n| Parameter | Supported values | Default |\n|:---------:|:----------------:|:-------:|\n|   items   |      `list`      | `[\"\"]`  |\n\n###### Parametrized\n\n```json\n{\n  \"random\": {\n    \"_mimeo_util\": {\n      \"_name\": \"random_item\",\n      \"items\": [\"value\", 1, true]\n    }\n  }\n}\n```\n\n##### Date\n\nGenerates a date value in format `YYYY-MM-DD`.\n\n| Parameter  | Supported values | Default |\n|:----------:|:----------------:|:-------:|\n| days_delta |      `int`       |   `0`   |\n\n###### Raw\n\nUses the today's date.\n\n```json\n{\n  \"Today\": \"{date}\"\n}\n```\n\n###### Parametrized\n\nUses the customized days delta.\n\n```json\n{\n  \"Yesterday\": {\n    \"_mimeo_util\": {\n      \"_name\": \"date\",\n      \"days_delta\": -1\n    }\n  },\n  \"Tomorrow\": {\n    \"_mimeo_util\": {\n      \"_name\": \"date\",\n      \"days_delta\": 1\n    }\n  }\n}\n```\n\n##### Date Time\n\nGenerates a date time value in format `YYYY-MM-DD'T'HH:mm:SS`.\n\n|   Parameter   | Supported values | Default |\n|:-------------:|:----------------:|:-------:|\n|  days_delta   |      `int`       |   `0`   |\n|  hours_delta  |      `int`       |   `0`   |\n| minutes_delta |      `int`       |   `0`   |\n| seconds_delta |      `int`       |   `0`   |\n\n###### Raw\n\nUses the current timestamp.\n\n```json\n{\n  \"Now\": \"{date_time}\"\n}\n```\n\n###### Parametrized\n\nUses the customized deltas.\n\n```json\n{\n  \"TomorrowThreeHoursLaterTwentyMinutesAgoTwoSecondsLater\": {\n    \"_mimeo_util\": {\n      \"_name\": \"date_time\",\n      \"days_delta\": 1,\n      \"hours_delta\": 3,\n      \"minutes_delta\": -20,\n      \"seconds_delta\": 2\n    }\n  }\n}\n```\n\n##### Auto Increment\n\nGenerates a next integer in context of a model (in nested templates it will use a separated context).\n\n| Parameter | Supported values | Default  |\n|:---------:|:----------------:|:--------:|\n|  pattern  |      `str`       | `{:05d}` |\n\n###### Raw\n\nUses a default pattern: **{:05d}** (an integer with 5 leading zeros).\n\n```json\n{\n  \"ID\": \"{auto_increment}\"\n}\n```\n\n###### Parametrized\n\nUses the string pattern provided.\n\n```json\n{\n  \"ID\": {\n    \"_mimeo_util\": {\n      \"_name\": \"auto_increment\",\n      \"pattern\": \"MY_ID_{:010d}\"\n    }\n  }\n}\n```\n\n##### Current Iteration\n\nGenerates a value of the current iteration in a Mimeo Template context.\n\n| Parameter | Supported values |      Default      |\n|:---------:|:----------------:|:-----------------:|\n|  context  |      `str`       | a current context |\n\n###### Raw\n\nUses the current context.\n\n```json\n{\n  \"ID\": \"{curr_iter}\"\n}\n```\n\n###### Parametrized\n\nUses a specific Mimeo Model context (model name when `context` is not configured).\n\n```json\n{\n  \"Parent\": {\n    \"_mimeo_util\": {\n      \"_name\": \"curr_iter\",\n      \"context\": \"SomeEntity\"\n    }\n  }\n}\n```\n\n##### Key\n\nGenerates a key unique across all Mimeo Models and being the same within a single Mimeo Model context.\n\n| Parameter | Supported values |              Default               |\n|:---------:|:----------------:|:----------------------------------:|\n|  context  |      `str`       |         a current context          |\n| iteration |      `int`       | a current iteration of the context |\n\n###### Raw\n\nUses a key from the current context and iteration.\n\n```json\n{\n  \"ID\": \"{key}\"\n}\n```\n\n###### Parametrized\n\nUses a key from the specific context and iteration.  \nWhen context is indicated and iteration is not, then the current iteration **of the indicated context** is being used.\n\n```json\n{\n  \"SomeEntity2\": {\n    \"_mimeo_util\": {\n      \"_name\": \"key\",\n      \"context\": \"SomeEntity\",\n      \"iteration\": \"{curr_iter}\"\n    }\n  }\n}\n```\n\n##### City\n\nGenerates a city name.\n\n| Parameter | Supported values | Default |\n|:---------:|:----------------:|:-------:|\n|  unique   |      `bool`      | `True`  |\n|  country  |      `str`       | `None`  |\n\n###### Raw\n\nBy default city names will be unique across a Mimeo Context.\n\n```json\n{\n  \"City\": \"{city}\"\n}\n```\n\n###### Parametrized\n\nUses country (name, iso2, iso3) and `unique` flag to generate a city name.\n\n```json\n{\n  \"CityWithDuplicates\": {\n    \"_mimeo_util\": {\n      \"_name\": \"city\",\n      \"unique\": false\n    }\n  },\n  \"CityOfCountryName\": {\n    \"_mimeo_util\": {\n      \"_name\": \"city\",\n      \"country\": \"United Kingdom\"\n    }\n  },\n  \"CityOfCountryISO2\": {\n    \"_mimeo_util\": {\n      \"_name\": \"city\",\n      \"country\": \"GB\"\n    }\n  },\n  \"CityOfCountryISO3\": {\n    \"_mimeo_util\": {\n      \"_name\": \"city\",\n      \"country\": \"GBR\"\n    }\n  },\n  \"CityOfCountryWithDuplicates\": {\n    \"_mimeo_util\": {\n      \"_name\": \"city\",\n      \"country\": \"United Kingdom\",\n      \"unique\": false\n    }\n  }\n}\n```\n\n##### Country\n\nGenerates a country name (by default), iso2 or iso3.\n\n| Parameter |       Supported values       | Default  |\n|:---------:|:----------------------------:|:--------:|\n|  unique   |            `bool`            |  `True`  |\n|   value   | `\"name\"`, `\"iso3\"`, `\"iso2\"` | `\"name\"` |\n|  country  |            `str`             |  `None`  |\n\n###### Raw\n\nBy default country names will be unique across a Mimeo Context.\n\n```json\n{\n  \"Country\": \"{country}\"\n}\n```\n\n###### Parametrized\n\nIt can generate:\n- country iso3 or iso 2 instead of name\n- country with duplicates\n- country name for a provided iso3 or iso2\n- country iso2 for a provided name or iso3\n- country iso3 for a provided name or iso2\n\nWhen the `country` param is provided then the `unique` flag is ignored.\n\n```json\n{\n  \"CountryNameWithDuplicates\": {\n    \"_mimeo_util\": {\n      \"_name\": \"country\",\n      \"unique\": false\n    }\n  },\n  \"CountryISO2\": {\n    \"_mimeo_util\": {\n      \"_name\": \"country\",\n      \"value\": \"iso2\"\n    }\n  },\n  \"CountryISO3\": {\n    \"_mimeo_util\": {\n      \"_name\": \"country\",\n      \"value\": \"iso3\"\n    }\n  },\n  \"CountryNameForISO3\": {\n    \"_mimeo_util\": {\n      \"_name\": \"country\",\n      \"country\": \"GBR\"\n    }\n  },\n  \"CountryISO2ForName\": {\n    \"_mimeo_util\": {\n      \"_name\": \"country\",\n      \"value\": \"iso2\",\n      \"country\": \"United Kingdom\"\n    }\n  }\n}\n```\n\n##### Currency\n\nGenerates a currency code (by default) or name.\n\n| Parameter |  Supported values  | Default  |\n|:---------:|:------------------:|:--------:|\n|  unique   |       `bool`       | `False`  |\n|   value   | `\"code\"`, `\"name\"` | `\"code\"` |\n|  country  |       `str`        |  `None`  |\n\n###### Raw\n\nBy default city names will _NOT_ be unique across a Mimeo Context.\n\n```json\n{\n  \"Currency\": \"{currency}\"\n}\n```\n\n###### Parametrized\n\nIt can generate:\n- unique currencies\n- currency name instead of code\n- currency code or name of a specific country (using iso3, iso2 or name)\n\nWhen the `country` param is provided then the `unique` flag is ignored.\n\n```json\n{\n  \"UniqueCurrencyCode\": {\n    \"_mimeo_util\": {\n      \"_name\": \"currency\",\n      \"unique\": true\n    }\n  },\n  \"CurrencyName\": {\n    \"_mimeo_util\": {\n      \"_name\": \"currency\",\n      \"value\": \"name\"\n    }\n  },\n  \"CurrencyCodeForCountryISO3\": {\n    \"_mimeo_util\": {\n      \"_name\": \"currency\",\n      \"country\": \"GBR\"\n    }\n  },\n  \"CurrencyNameForCountryISO2\": {\n    \"_mimeo_util\": {\n      \"_name\": \"currency\",\n      \"value\": \"name\",\n      \"country\": \"GB\"\n    }\n  },\n  \"CurrencyNameForCountryName\": {\n    \"_mimeo_util\": {\n      \"_name\": \"currency\",\n      \"value\": \"name\",\n      \"country\": \"United Kingdom\"\n    }\n  }\n}\n```\n\n##### First Name\n\nGenerates a first name.\n\n| Parameter |      Supported values      | Default  |\n|:---------:|:--------------------------:|:--------:|\n|  unique   |           `bool`           |  `True`  |\n|    sex    | `M`, `Male`, `F`, `Female` |  `None`  |\n\n###### Raw\n\nBy default first names will be unique across a Mimeo Context.\n\n```json\n{\n  \"FirstName\": \"{first_name}\"\n}\n```\n\n###### Parametrized\n\nUses sex (`M` / `Male` / `F` / `Female`) and `unique` flag to generate a first name.\n\n```json\n{\n  \"FirstNameWithDuplicates\": {\n    \"_mimeo_util\": {\n      \"_name\": \"first_name\",\n      \"unique\": false\n    }\n  },\n  \"MaleFirstName\": {\n    \"_mimeo_util\": {\n      \"_name\": \"first_name\",\n      \"sex\": \"M\"\n    }\n  },\n  \"FemaleFirstName\": {\n    \"_mimeo_util\": {\n      \"_name\": \"first_name\",\n      \"sex\": \"F\"\n    }\n  },\n  \"MaleFirstNameWithDuplicates\": {\n    \"_mimeo_util\": {\n      \"_name\": \"first_name\",\n      \"sex\": \"M\",\n      \"unique\": false\n    }\n  }\n}\n```\n\n##### Last Name\n\nGenerates a last name.\n\n| Parameter | Supported values | Default  |\n|:---------:|:----------------:|:--------:|\n|  unique   |      `bool`      |  `True`  |\n\n###### Raw\n\nBy default last names will be unique across a Mimeo Context.\n\n```json\n{\n  \"LastName\": \"{last_name}\"\n}\n```\n\n###### Parametrized\n\nUses `unique` flag to generate a last name.\n\n```json\n{\n  \"LastNameWithDuplicates\": {\n    \"_mimeo_util\": {\n      \"_name\": \"last_name\",\n      \"unique\": false\n    }\n  }\n}\n```\n\n### Python Lib\n\nTo generate data using Mimeo as a python library you need 3 classes:\n* `MimeoConfig` (A python representation of a Mimeo Configuration)\n* `MimeoConfigFactory` (A factory parsing a Mimeo Configuration)\n* `Mimeograph` (a class generating and consuming data from a Mimeo Configuration)\n\n#### Parsing Mimeo Configuration\n\n##### `MimeoConfig`\n\nThe `MimeoConfig` class takes a dictionary as a parameter and initializes all settings.\n\n```python\nfrom mimeo import MimeoConfig\n\nconfig = {\n  \"_templates_\": [\n    {\n      \"count\": 30,\n      \"model\": {\n        \"SomeEntity\": {\n          \"@xmlns\": \"http://mimeo.arch.com/default-namespace\",\n          \"@xmlns:pn\": \"http://mimeo.arch.com/prefixed-namespace\",\n          \"ChildNode1\": 1,\n          \"ChildNode2\": \"value-2\",\n          \"ChildNode3\": True\n        }\n      }\n    }\n  ]\n}\nmimeo_config = MimeoConfig(config)\n```\n\n##### `MimeoConfigFactory`\n\nTo easily parse Mimeo Configuration you can use the `MimeoConfigFactory`.\nIt allows you to provide a raw config as:\n* a dictionary\n* a stringified XML node\n* a file path\n\n<table>\n    <tr>\n        <th></th>\n        <th>JSON</th>\n        <th>XML</th>\n    </tr>\n    <tr>\n        <td><b>Raw data</b></td>\n        <td valign=\"top\">\n\n```python\nfrom mimeo import MimeoConfigFactory\n\nconfig = {\n  \"_templates_\": [\n    {\n      \"count\": 30,\n      \"model\": {\n        \"SomeEntity\": {\n          \"@xmlns\": \"http://mimeo.arch.com/default-namespace\",\n          \"@xmlns:pn\": \"http://mimeo.arch.com/prefixed-namespace\",\n          \"ChildNode1\": 1,\n          \"ChildNode2\": \"value-2\",\n          \"ChildNode3\": True\n        }\n      }\n    }\n  ]\n}\nmimeo_config = MimeoConfigFactory.parse(config)\n```\n</td>\n    <td valign=\"top\">\n\n```python\nfrom mimeo import MimeoConfigFactory\n\nconfig = (\n    '<mimeo_configuration>'\n    '    <_templates_>'\n    '        <_template_>'\n    '            <count>30</count>'\n    '            <model>'\n    ''\n    '                <SomeEntity'\n    '                    xmlns=\"http://mimeo.arch.com/default-namespace\"'\n    '                    xmlns:pn=\"http://mimeo.arch.com/prefixed-namespace\">'\n    '                    <ChildNode1>1</ChildNode1>'\n    '                    <pn:ChildNode2>value-2</pn:ChildNode2>'\n    '                    <ChildNode3>true</ChildNode3>'\n    '                </SomeEntity>'\n    ''\n    '            </model>'\n    '        </_template_>'\n    '    </_templates_>'\n    '</mimeo_configuration>')\nmimeo_config = MimeoConfigFactory.parse(config)\n```\n</td>\n  </tr>\n    <tr>\n        <td><b>File path</b></td>\n        <td valign=\"top\">\n\n```python\nfrom mimeo import MimeoConfigFactory\n\nconfig = \"SomeEntity-config.json\"\nmimeo_config = MimeoConfigFactory.parse(config)\n```\n</td>\n    <td valign=\"top\">\n\n```python\nfrom mimeo import MimeoConfigFactory\n\nconfig = \"SomeEntity-config.xml\"\nmimeo_config = MimeoConfigFactory.parse(config)\n```\n</td>\n  </tr>\n</table>\n\n#### Processing Mimeo Configuration\n\nUsing the Mimeo as a python library you can use 2 processing approaches:\n* sequential processing\n* processing in parallel (used by default in Mimeo CLI)\n\nBoth need the `Mimeograph` class.\n\n\n##### Sequential processing\n\nSequential processing is pretty straightforward and can be done without `Mimeograph` instantiation.\n\n###### Processing\n\nTo simply process data from a Mimeo Configuration you can use the `Mimeograph.process()` method:\n```python\nfrom mimeo import MimeoConfigFactory, Mimeograph\n\nconfig_path = \"examples/1-introduction/01-basic.json\"\nmimeo_config = MimeoConfigFactory.parse(config_path)\nMimeograph.process(mimeo_config)\n```\n\nIt will generate data and consume it immediately.\n\n###### Generating only\n\nIf you're going to generate data and use it as a python representation\n(`dict`, `xml.etree.ElementTree.Element`) - use `Mimeograph.generate()` method:\n```python\nfrom mimeo import MimeoConfigFactory, Mimeograph\n\nconfig_path = \"examples/1-introduction/01-basic.json\"\nmimeo_config = MimeoConfigFactory.parse(config_path)\ndata = Mimeograph.generate(mimeo_config)\n```\n\n###### Generating and consuming in 2 stages\n\nIn case you would like to somehow modify generated data before it will be consumed,\nuse `Mimeograph.generate()` and `Mimeograph.consume()` methods.\n```python\nfrom mimeo import MimeoConfigFactory, Mimeograph\n\nconfig_path = \"examples/1-introduction/01-basic.json\"\nmimeo_config = MimeoConfigFactory.parse(config_path)\ndata = Mimeograph.generate(mimeo_config)\n# ... your modifications ...\nMimeograph.consume(mimeo_config, data)\n```\n\n##### Processing in parallel\n\nWhen you're going to process data (generate and consume) from several Mimeo Configurations\nprocessing in parallel is more performant way. To do that, you need use the `Mimeograph` as a Context Manager\nand submit configs together with some kind of identifier (e.g. config path). Thanks to that you will know\nwhich config has failed (if so).\n\n```python\nfrom mimeo import MimeoConfigFactory, Mimeograph\n\nconfig_paths = [\n    \"examples/1-introduction/01-basic.json\",\n    \"examples/1-introduction/02-complex.json\",\n    \"examples/1-introduction/03-output-format-xml.json\",\n    \"examples/1-introduction/04-output-format-json.json\",\n]\nwith Mimeograph() as mimeo:\n    for config_path in config_paths:\n        mimeo_config = MimeoConfigFactory.parse(config_path)\n        mimeo_config.output.direction = \"stdout\"\n        mimeo.submit((config_path, mimeo_config))\n```\n\n## License\n\nMIT\n\n\n## Authors\n\n- [@TomaszAniolowski](https://www.github.com/TomaszAniolowski)\n\n\n## Acknowledgements\n\n - [SimpleMaps.com](https://simplemaps.com/data/world-cities) (Cities & countries data)\n - [@hadley/data-baby-names](https://github.com/hadley/data-baby-names/) (Forenames data)\n - [@fivethirtyeigh/data/most-common-name](https://github.com/fivethirtyeight/data/tree/master/most-common-name) (Surnames data)\n - [@datasets/currency-codes](https://github.com/datasets/currency-codes/) (Currencies data)\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Tomasz Anio\u0142owski  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Generate NoSQL data based on a simple template",
    "version": "1.0.4",
    "project_urls": {
        "GitHub": "https://github.com/TomaszAniolowski/mimeo"
    },
    "split_keywords": [
        "mimeograph",
        "mimeo",
        "generate",
        "generator",
        "data",
        "xml",
        "json",
        "nosql"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5d3792706440333b9125baddcabb23b594b9e15f4c6ceaeb359dd34b9e2fcfd4",
                "md5": "1186c1a58d02513ad39183595a3a3caf",
                "sha256": "e515814d85671eb4374d4868a0a23de7fa001131115e7c8730d7bb47a08dbb7a"
            },
            "downloads": -1,
            "filename": "mimeograph-1.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1186c1a58d02513ad39183595a3a3caf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 1033319,
            "upload_time": "2023-06-27T07:07:18",
            "upload_time_iso_8601": "2023-06-27T07:07:18.198260Z",
            "url": "https://files.pythonhosted.org/packages/5d/37/92706440333b9125baddcabb23b594b9e15f4c6ceaeb359dd34b9e2fcfd4/mimeograph-1.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c9f9123a4f84b49d741fe00284f07e0396edea14f9ea72acbebf42639c8e0645",
                "md5": "670d782cde0691f54b2c20c747850db4",
                "sha256": "1e4af693051bc3a7cb5b82f18990ebecd3d4ab45b36388b0781ee1941a056cf3"
            },
            "downloads": -1,
            "filename": "mimeograph-1.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "670d782cde0691f54b2c20c747850db4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 1028890,
            "upload_time": "2023-06-27T07:07:28",
            "upload_time_iso_8601": "2023-06-27T07:07:28.508530Z",
            "url": "https://files.pythonhosted.org/packages/c9/f9/123a4f84b49d741fe00284f07e0396edea14f9ea72acbebf42639c8e0645/mimeograph-1.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-27 07:07:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TomaszAniolowski",
    "github_project": "mimeo",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "mimeograph"
}
        
Elapsed time: 0.09446s