# dataclass_wizard.wizard_cli package

## Submodules

## dataclass_wizard.wizard_cli.cli module

Entry point for the Wizard CLI tool.

class dataclass_wizard.wizard_cli.cli.FileTypeWithExt(mode='r', ext=None, bufsize=-1, encoding=None, errors='ignore')

  Bases: `FileType`

  Extends `argparse.FileType` to add a default file extension if the provided file name is missing one.

dataclass_wizard.wizard_cli.cli.gen_py_schema(args)

  Entry point for the wiz gen-schema (gs) command.

dataclass_wizard.wizard_cli.cli.get_div(out_file, char='_', line_width=50)

  Returns a formatted line divider to print.

  Parameters:

    out_file (TextIO)

dataclass_wizard.wizard_cli.cli.main(args=None)

  A companion CLI tool for the Dataclass Wizard, which simplifies interaction with the Python dataclasses module.

dataclass_wizard.wizard_cli.cli.parser: ArgumentParser

dataclass_wizard.wizard_cli.cli.setup_parser()

  Sets up the Wizard CLI parser.

## dataclass_wizard.wizard_cli.schema module

Generates a Python (dataclass) schema, given a JSON input. The entry point for this module is the gen-schema subcommand.

This JSON to Dataclass conversion tool was inspired by the following projects:

> - https://github.com/mischareitsma/json2dataclass

> - https://github.com/russbiggs/json2dataclass

> - https://github.com/mholt/json-to-go

The parser supports the full JSON spec, so both list and dict as the root type are properly handled as expected.

A few important notes on the behavior of JSON parsing:

> - Lists with multiple dictionaries will have all the keys and type definitions merged into a single model dataclass, as the dictionary objects are considered homogenous in this case.

> - Nested lists within the above structure (e.g. list -> dict -> list) should similarly merge all list elements with the list for that same key in each sibling dict object. For example, assuming the below input:

>       ... [{"d1": [1, {"k": "v"}]}, {"d1": [{"k": 2}, {"k2": "v2"}, True]}]

>   This should result in a single, merged type definition for “d1”::

>     … List[Union[int, dataclass(k: Union[str, int], k2: str), bool]]

> - Any nested dictionaries within lists will have their Model class name generated with the singular form of the key containing the model definition – for example, {“Items”:[{“key”:”value”}]} will result in a model class named Item. In the case a dictionary is nested within a list, it will have the class name auto-incremented with a common prefix – for example, Data1, Data2, etc.

The implementation below uses regex code in the rules.english module from the library Python-Inflector (https://github.com/bermi/Python-Inflector).

This library is available under the BSD license, which can be obtained from https://opensource.org/licenses.

The library Python-Inflector contains the following attribution notices:

> Copyright (c) 2006 Bermi Ferrer Martinez bermi a-t bermilabs - com

See the end of this file for the original BSD-style license from this library.

class dataclass_wizard.wizard_cli.schema.PyCodeGenerator(file_name=None, file_contents=None, force_strings=None, experimental=None)

  Bases: `object`

  This is the main class responsible for generating Python code that leverages dataclasses, given a JSON object as an input data.

  Parameters:

    - file_name (dataclasses.InitVar[str])

    - file_contents (dataclasses.InitVar[str])

    - force_strings (dataclasses.InitVar[bool])

    - experimental (dataclasses.InitVar[bool])

  data: `Union`[`list`[`Any`], `dict`[`str`, `Any`]]
  experimental: `InitVar` = None
  file_contents: `InitVar` = None
  file_name: `InitVar` = None
  force_strings: `InitVar` = None
  parser: `JSONRootParser`
  property py_code: str

## Module contents