@@ -22,10 +22,112 @@ json2python-models is a [Python](https://www.python.org/) tool that can generate
2222* Specifying when dictionaries should be processed as is
2323* CLI tool
2424
25+ ## Examples
26+ [ * skip* ] ( #installation )
27+
28+ ``` json
29+ [
30+ {
31+ "season" : " 2019" ,
32+ "round" : " 3" ,
33+ "DriverStandings" : [
34+ {
35+ "position" : " 1" ,
36+ "positionText" : " 1" ,
37+ "points" : " 68" ,
38+ "wins" : " 2" ,
39+ "Driver" : {
40+ "driverId" : " hamilton" ,
41+ "permanentNumber" : " 44" ,
42+ "code" : " HAM" ,
43+ "url" : " http://en.wikipedia.org/wiki/Lewis_Hamilton" ,
44+ "givenName" : " Lewis" ,
45+ "familyName" : " Hamilton" ,
46+ "dateOfBirth" : " 1985-01-07" ,
47+ "nationality" : " British"
48+ },
49+ "Constructors" : [
50+ {
51+ "constructorId" : " mercedes" ,
52+ "url" : " http://en.wikipedia.org/wiki/Mercedes-Benz_in_Formula_One" ,
53+ "name" : " Mercedes" ,
54+ "nationality" : " German"
55+ }
56+ ]
57+ },
58+ {
59+ "position" : " 2" ,
60+ "positionText" : " 2" ,
61+ "points" : " 62" ,
62+ "wins" : " 1" ,
63+ "Driver" : {
64+ "driverId" : " bottas" ,
65+ "permanentNumber" : " 77" ,
66+ "code" : " BOT" ,
67+ "url" : " http://en.wikipedia.org/wiki/Valtteri_Bottas" ,
68+ "givenName" : " Valtteri" ,
69+ "familyName" : " Bottas" ,
70+ "dateOfBirth" : " 1989-08-28" ,
71+ "nationality" : " Finnish"
72+ },
73+ "Constructors" : [
74+ {
75+ "constructorId" : " mercedes" ,
76+ "url" : " http://en.wikipedia.org/wiki/Mercedes-Benz_in_Formula_One" ,
77+ "name" : " Mercedes" ,
78+ "nationality" : " German"
79+ }
80+ ]
81+ }
82+ ]
83+ }
84+ ]
85+ ```
86+
87+ ``` python
88+ import attr
89+ from json_to_models.dynamic_typing import IntString, IsoDateString
90+ from typing import List
91+
92+
93+ @attr.s
94+ class DriverStandings :
95+ @attr.s
96+ class DriverStanding :
97+ @attr.s
98+ class Driver :
99+ driver_id: str = attr.ib()
100+ permanent_number: IntString = attr.ib(converter = IntString)
101+ code: str = attr.ib()
102+ url: str = attr.ib()
103+ given_name: str = attr.ib()
104+ family_name: str = attr.ib()
105+ date_of_birth: IsoDateString = attr.ib(converter = IsoDateString)
106+ nationality: str = attr.ib()
107+
108+ @attr.s
109+ class Constructor :
110+ constructor_id: str = attr.ib()
111+ url: str = attr.ib()
112+ name: str = attr.ib()
113+ nationality: str = attr.ib()
114+
115+ position: IntString = attr.ib(converter = IntString)
116+ position_text: IntString = attr.ib(converter = IntString)
117+ points: IntString = attr.ib(converter = IntString)
118+ wins: IntString = attr.ib(converter = IntString)
119+ driver: ' Driver' = attr.ib()
120+ constructors: List[' Constructor' ] = attr.ib()
121+
122+ season: IntString = attr.ib(converter = IntString)
123+ round : IntString = attr.ib(converter = IntString)
124+ driver_standings: List[' DriverStanding' ] = attr.ib()
125+ ```
126+
25127## Installation
26128
27- | ** Be ware** : it supports only ` python3.7 ` and higher. |
28- | --- |
129+ | ** Be ware** : this project supports only ` python3.7 ` and higher. |
130+ | --- |
29131
30132To install Requests, use ` pip ` :
31133
@@ -39,6 +141,15 @@ cd json2python-models
39141python setup.py install
40142```
41143
144+ ## Usage
145+
146+ ### CLI
147+
148+ > Coming soon
149+
150+ ### Low level
151+
152+ > Coming soon (Wiki)
42153
43154## Tests
44155
@@ -47,19 +158,23 @@ To run tests you should clone project and install `pytest` and `requests` (to do
47158```
48159git clone https://github.com/bogdandm/json2python-models.git
49160cd json2python-models
50- pip install pytest>=4.4.0
51161
52- python setup.py test -a '<pytest arguments>'
53- or
54- pytest tests
162+ python setup.py test -a '<pytest additional arguments>'
55163```
56164
57- Also I would recommend you to install ` pytest-xdist ` for parallel execution
58- and ` pytest-sugar ` for pretty printing test results
165+ Also I would recommend you to install ` pytest-sugar ` for pretty printing test results
59166
60167### Test examples
61168
62- >
169+ You can find out some examples of usage of this project at [ testing_tools/real_apis/...] ( /testing_tools/real_apis )
170+
171+ Each file contains functions to download data from some online API (references included at the top of file) and
172+ ` main ` function that generate and print code. Some examples may print debug data before actual code.
173+ Downloaded data will be saved at ` testing_tools/real_apis/<name of example>/<dataset>.json `
174+
175+ ## API docs
176+
177+ > Coming soon (Wiki)
63178
64179## Built With
65180
@@ -72,11 +187,12 @@ and `pytest-sugar` for pretty printing test results
72187## Contributing
73188
74189Feel free to open pull requests with new features or bug fixes. Just follow few rules:
190+
751911 . Always use some code formatter ([ black] ( https://github.com/ambv/black ) or PyCharm built-in)
761922 . Keep code coverage above 95-98%
77- 3 . All existing tests should be passed (including test examples)
193+ 3 . All existing tests should be passed (including test examples from ` testing_tools/real_apis ` )
781944 . Use ` typing ` module
79- 5 . Fix [ codacy] ( https://app.codacy.com/project/bogdandm/json2python-models/dashboard ) issues
195+ 5 . Fix [ codacy] ( https://app.codacy.com/project/bogdandm/json2python-models/dashboard ) issues from your PR
80196
81197## License
82198
0 commit comments