Skip to content

Commit df21c1f

Browse files
committed
README
1 parent 8042a81 commit df21c1f

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
![Example](/etc/convert.png)
99

1010
json2python-models is a [Python](https://www.python.org/) tool that can generate Python models classes
11-
(dataclasses, attrs) from JSON dataset.
11+
(dataclasses, [attrs](https://github.com/python-attrs/attrs)) from JSON dataset.
1212

1313
## Features
1414

@@ -23,7 +23,7 @@ json2python-models is a [Python](https://www.python.org/) tool that can generate
2323
* **CLI** tool
2424

2525
## Example
26-
[*skip to **Installation***](#installation)
26+
[*skip up to **Installation***](#installation)
2727

2828
```
2929
[
@@ -122,9 +122,28 @@ python setup.py install
122122

123123
### CLI
124124

125-
> Coming soon
125+
For regular usage CLI tool is a best option. After you install this package you could use it as `json2models`
126+
or `python -m json_to_models`.
126127

127-
### Low level
128+
Arguments:
129+
130+
| Key | Format | Description | Example | Note |
131+
| --- | --- | --- | --- | --- |
132+
| `-h, -help` | - | show help message and exit | | |
133+
| `-m, --model` | `-m <Model name> [<JSON files> ...]` | Model name and its JSON data as path or unix-like path pattern. `*`, `**` or `?` patterns symbols are supported. | `-m Car audi.json reno.json` or `-m Car audi.json -m Car reno.json` (results will be the same) | |
134+
| `-l, --list` | `-l <Model name> <JSON key> <JSON file>` | Like `-m` but given json file should contain list of model data (dataset). If this file contains dict with nested list than you can pass `<JSON key>` to lookup. Deep lookups are supported by dot-separated path. If no lookup needed pass '-' as <JSON key> | `-l Car - cars.json -l Person fetch_results.items.persons result.json` | Models names under `-l` arguments should be unique |
135+
| `-f, --framework` | `-f {base,attrs,dataclasses,custom}` | Model framework for which python code is generated. 'base' (default) mean no framework so code will be generated without any decorators and additional meta-data. | `-f attrs` | Default: `-f base` |
136+
| `-s , --structure` | `-s {nested, flat}` | Models composition style. | `-s flat` | Default: `-s nested` |
137+
| `--datetime` | - | Enable datetime/date/time strings parsing. Warn.: This can lead to 6-7 times slowdown on large datasets. Be sure that you really need this option. | | Default: disabled |
138+
| `--merge`| `--merge MERGE_POLICY [MERGE_POLICY ...]` | Merge policy settings. Possible values are: `percent[_<percent>]` - two models had a certain percentage of matched field names. Custom value could be i.e. `percent_95`. `number[_<number>]` - two models had a certain number of matched field names. `exact` - two models should have exact same field names to merge. | `--merge percent_95 number_20` - merge if 95% of fields match or 20 fields match | Default: `--merge percent_70 number_10` |
139+
| `--dict-keys-regex, --dkr` | `--dkr RegEx [RegEx ...]` | List of regular expressions (Python syntax). If all keys of some dict are match one of them then this dict will be marked as dict field but not nested model. | `--dkr node_\d+ \d+_\d+_\d+` | `^` and `$` (string borders) tokens will be added automatically but you have escape to other special characters manually. | Optional |
140+
| `--dict-keys-fields, --dkf` | `--dkf FIELD_NAME [FIELD_NAME ...]` | List of model fields names that will be marked as dict fields | `--dkf "dict_data" "mapping"` | Optional |
141+
| `--code-generator` | `--code-generator CODE_GENERATOR` | Absolute import path to GenericModelCodeGenerator subclass. | `-f mypackage.mymodule.DjangoModelsGenerator` | Is ignored without `-f custom` but is required with it |
142+
| `--code-generator-kwargs` | `--code-generator-kwargs [NAME=VALUE [NAME=VALUE ...]]` | List of GenericModelCodeGenerator subclass arguments (for `__init__` method, see docs of specific subclass). Each argument should be in following format: `argument_name=value` or `"argument_name=value with space"`. Boolean values should be passed in JS style: `true` or `false` | `--code-generator-kwargs kwarg1=true kwarg2=10 "kwarg3=It is string with spaces"` | Optional |
143+
144+
One of model arguments (`-m` or `-l`) is required.
145+
146+
### Low level API
128147

129148
> Coming soon (Wiki)
130149
@@ -148,10 +167,6 @@ Each file contains functions to download data from some online API (references i
148167
`main` function that generates and prints code. Some examples may print debug data before actual code.
149168
Downloaded data will be saved at `testing_tools/real_apis/<name of example>/<dataset>.json`
150169

151-
## API docs
152-
153-
> Coming soon (Wiki)
154-
155170
## Built With
156171

157172
* [python-dateutil](https://github.com/dateutil/dateutil) - Datetime parsing

etc/convert.png

56 Bytes
Loading

0 commit comments

Comments
 (0)