Skip to main content

dummy flat text/csv file generator

Project description

dummy_file_generator

version 1.0.3

a dummy csv or flat text files generator written in Python 3.7

This tool is able to generate dummy csv or flat txt files based on the configuration settings you setup for your project(s). It consumes arguments defining:

  • projectname (mandatory argument, based on the projectname, the specific settings from config.json file are loaded ),

  • absolutepath (mandatory argument) defining the full output file path to the file you wish to generate

  • filesize (optional argument) defining the desired size (in kBs) of the output file

  • rowcount (optional argument) defining the desired row count of the output file

  • logging_level (optional argument) defining the Python logging level

  • default_rowcount (optional argument) defining the rowcount fallback value when neither row_count,neither file_size set

  • file_encoding (optional argument) defining the generated files encoding

  • file_line_ending (optional argument) defining the file line ending

  • csv_value_separator (optional argument) defining the .csv file value separator

these arguments are needed when running as an importable library:

  • data_files_location (optional argument) defining the path to the source .txt data files
  • config_json_path (optional argument) defining the custom path to your config.json file

How to install and run the program as CLI

How to install and run the program as a importable library

How to setup a new dummy file generator project

How to add a new source dataset for your project

Pytest testing

How to install and run the program as CLI

To install:

git clone https://github.com/datahappy1/dummy_file_generator c:\dummy_file_generator\

cd c:\dummy_file_generator\dummy_file_generator

python.exe __main__.py -pn my_project -ap c:\dummy1file.txt -rc 256

To run:

You need to set the required arguments : projectname -pn
absolutepath -ap

The optional arguments are : filesize -fs (in kB)
rowcount -rc

*Note if you do NOT specify the filesize and do NOT specify the rowcount, the default row_count value ( set to 100 ) from settings.py will be used ( or the value you provide in the default_rowcount optional argument)

Run these commands to execute:

  • with the -fs argument to set the desired filesize of 256 kB :
    cd c:\dummy_file_generator\dummy_file_generator
    python c:\dummy_file_generator\dummy_file_generator\__main__.py -pn dummy1 -ap c:\myfiles\dummy1file.csv -fs 256
  • with the -rc argument to set the desired rowcount of 1000 rows :
    cd c:\dummy_file_generator\dummy_file_generator
    python c:\dummy_file_generator\dummy_file_generator\__main__.py -pn dummy1 -ap c:\myfiles\dummy1file.csv -rc 1000

*You are strongly encouraged to use Python virtual environment

How to install and run the program as a importable library

To install:

pip install dummy-file-generator

To run:

You need to set these arguments as an Python dictionary for example: kwargs = {"project_name": "dummy1", "absolute_path": "C:\\scrap_files\dummy1.csv", "file_size": 1024, "logging_level": "DEBUG", "data_files_location": "c:\\dummy_file_generator\dummy_file_generator\data_files", "config_json_path": "c:\\dummy_file_generator\dummy_file_generator\configurables\config.json", }

*Note if you do NOT specify the filesize and do NOT specify the rowcount, the default row_count value ( set to 100 ) from settings.py will be used ( or the value you provide in the default_rowcount optional argument)

Run from within a function in your project for example:

from dummy_file_generator import DummyFileGenerator as DFG

def generate_dummy_file():
    kwargs = {"project_name": "dummy1", "absolute_path": "C:\\x\dfxx.csv",
              "file_size": 1024,
              "logging_level": "DEBUG",
              "data_files_location": "c:\\dummy_file_generator\dummy_file_generator\data_files",
              "config_json_path": "c:\\dummy_file_generator\dummy_file_generator\configurables\config.json",
              }

    obj = DFG(**kwargs)
    DFG.executor(obj)

generate_dummy_file()

How to setup a new dummy file generator project

Let's say you need to generate dummy files based on the content of the text files in your "data_files" folder, and these text files are looking like this:

- How to generate a .csv file

Let's say you need to generate a dummy .csv file containing 3 columns for Names, Dates and IDs. The project element in your config.json would need to be setup like:

{
  "project_name":"dummy1",
  "file_type":"csv",
  "header":true,
  "columns":[
    {
      "column_name":"Name",
      "datafile":"firstnames.txt"
    },
    {
      "column_name":"Date",
      "datafile":"dates.txt"
    },
    {
      "column_name":"ID",
      "datafile":"IDs.txt"
    }      
  ]
}

- How to generate a .txt flat file:

Let's say you need to generate a dummy .txt flat file containing 3 columns for Names, Dates and IDs with specific column lengths defined. The project element in your config.json would need to be setup like:

{
  "project_name":"dummy1",
  "file_type":"flat",
  "header":true,
  "columns":[
    {
      "column_name":"Name",
      "column_len":6,
      "datafile":"firstnames.txt"
    },
    {
      "column_name":"Date",
      "column_len":10,
      "datafile":"dates.txt"
    },
    {
      "column_name":"ID",
      "column_len":9,
      "datafile":"IDs.txt"
    }      
  ]
}

How to add a new source dataset for your project

Whenever you need to add a new source .txt file in the data_files folder, just add it to your data_files folder. If running as a standalone CLI tool, the data_files folder is located here:

When running as an importable library, the data_files folder is where you set it in the argument data_files_location. Now you can use this new data file in your project setup in config.json file.

Pytest testing

Pytest unit and performance tests are also a part of this tool. You can install Pytest with pip install pytest
To run tests:
cd c:\dummy_file_generator\dummy_file_generator
pytest

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

dummy-file-generator-1.0.4.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

dummy_file_generator-1.0.4-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file dummy-file-generator-1.0.4.tar.gz.

File metadata

  • Download URL: dummy-file-generator-1.0.4.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.0

File hashes

Hashes for dummy-file-generator-1.0.4.tar.gz
Algorithm Hash digest
SHA256 dc52f7e1b3beaa3b6c94fb2ecb85958556742bf183a33298c5d3830219ad2577
MD5 c53d76048188d32cdfe2a01b8c051247
BLAKE2b-256 52274c679e6511adab5930f4a4093d15a02ab4de78a720d154f3d1ddabf4eb97

See more details on using hashes here.

File details

Details for the file dummy_file_generator-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: dummy_file_generator-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.0

File hashes

Hashes for dummy_file_generator-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4bfaf40cdb04b67b2d2bc0f7daca045846870d26205fd3e37efaaca208342042
MD5 8434ae2bf090e31539488ad34cc47e60
BLAKE2b-256 42946cf6464e24ae1d1f59ca43856533dfaaa3a733c51fa341c56f7118e314f2

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