$ pip install -r requirements.txtIf you use poetry or any other modern dependency packaging tool you can install
packages using pyproject.toml:
$ poetry installTests are located under tests folder. To run it use pytest:
$ pytest$ python -m nest.py nesting_level_1 nesting_level_2 ... nesting_level_nJSON data reads from stdin after required levels:
$ cat tests/fixtures/input.json | python -m nest currency country cityIt could be done manually by ending input with control + D:
$ python -m nest currency
[{"country": "US", "city": "Boston", "currency": "USD"}]
{
"USD": [
{
"country": "US",
"city": "Boston"
}
]
}
For better display, you can adjust the number of spaces to indent:
$ python -m nest currency country city --indent 4Run server with uvicorn for instance:
$ uvicorn server:appCode for API endpoint is located in the file server.py.
Server provide the only single API endpoint /nest.
This the API can only be used by the admin.
Keys for nesting should be placed in params and input data sends as POST json body.
$ curl "http://127.0.0.1:8000/nest/?keys=currency&keys=country&keys=city" \
-X POST \
--user admin:admin \
-H "Content-Type: application/json" \
-d @tests/fixtures/input.json