Skip to main content

Generate random CSV files

Project description

OmbroCSV

pip install ombrocsv

A fast random CSV generator with a powerful yet simple template system that can be used either as a standalone Command line tool or easily integrated into any codebase.

Schema

The schema is basically the "template" of the CSV you are generating, it's a list of dictionaries (each dict represents a column). Here's how it should look:

[
    {
            "type": {see types for valid types}
            "header": {header name (optional)}
    },
    {
            "type": {see types for valid types}
            "header": {header name (optional)}
    },
    ...
]

the order in which the columns appear in the schema will be the order in which they will appear in the generated CSV.

Types

Here are the supported types with a brief description:

  • "bit" - random integer value between 1 and 0.
  • "phone_prefix" random 4-digit integer value.
  • "phone_number" random 10-digit number.
  • "phone_complete" random 14-digit number.
  • "string" - completely random string.
  • "name" - random string that loosely resembles a name.
  • "email" - random email
  • "number" - random integer number
  • "id" - incremental id that starts from 0
  • "date" - random date

Note: Any non recognized type will be treated as a string

Custom Types

you can easily override the default types by passing a different RandUtils in the constructor of CsvGenerator, just make sure that your custom RandUtils inherits from the base one and that every new type you add inherits from RandomBase.

Both RandUtils and RandomBase can be found in random_utils.py

To use your custom types then simply write the name it has been registered with in your custom RandUtils class in the "type" field when passing the schema.

Example

adding CustomType to code:

Class CustomType(RandomBase):
    ...


Class CustomRandUtils(RandUtils):

    def __init__():
        super().__init__()
        self.custom_type = CustomType()

Using CustomType in the Schema:

[
    {
            "type": "custom_type"
    },
    ...
]

Usage

This section details how to use the Package in both it's intended use cases.

As a Command Line Tool

Create a config file and use this package as a convenient way to generate CSV files on the fly.

Generate file and output to terminal

ombrocsv [config file] [number of lines to generate]

Generate file and output to file

ombrocsv [config file] [number of lines to generate] [output file]

Config file

{
    "schema": [
        {
            "type": {see types for valid types}
            "header": {header name (optional)}
        },
        ...
    ],
    "separator": {separator character (optional, default = ;)},
    "delimiter": {delimiter character (optional, default = ")},
    "headers": {true/false (optional, default = true)},
    "delimit all": {true/false (optional, default = false)}
}
Example
{
  "schema": [{
      "type": "email",
      "header": "Email"
    }, {
      "type": "name",
      "header": "Name"
    }, {
      "type": "name",
      "header": "Surname"
    }, {
      "type": "date",
      "header": "DateOfBirth"
    }, {
      "type": "CustomerID",
      "header": "string"
    }
  ],
  "separator": "|",
  "delimiter": "'"
}

As a Package

Just import CsvGenerator, initialize it with the required parameters and generate your CSV files.

Example

schema = [
    {
        "type": "email",
        "header": "Email"
    },
    {
        "type": "name",
        "header": "Name"
    },
    {
        "type": "name",
        "header": "Surname"
    },
    {
        "type": "date",
        "header": "DateOfBirth"
    },
    {
        "type": "CustomerID",
        "header": "string"
    }
]
generator = CsvGenerator(";", "\"", True, schema)
generator.generate(10)
generator.write(sys.stdout.buffer)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ombrocsv-1.0.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

ombrocsv-1.0.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file ombrocsv-1.0.0.tar.gz.

File metadata

  • Download URL: ombrocsv-1.0.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for ombrocsv-1.0.0.tar.gz
Algorithm Hash digest
SHA256 900505f9de8c4efbfa6d1d1ae0141d4d8e675679102e8c9db41975e35e548cc8
MD5 66ad28b1a30ad6ee472cdb90b8e4b8dd
BLAKE2b-256 6da5a1343394a48814daedb4691458e1f6677755e57498d2e2025a370c5ec5f2

See more details on using hashes here.

File details

Details for the file ombrocsv-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ombrocsv-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

File hashes

Hashes for ombrocsv-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65ddb0b2bbd42d55336c24e081fba4715530d25167480db819a39ac50173f5ff
MD5 da758e3636c6e691456e9f42755ec11d
BLAKE2b-256 7f6168b6418a0f38eee9a133814d84a02e91d3b24525416dc3651354b9f14141

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page