This is introductory task in the summer School of Backend Development of Yandex 2022.
__ __ __
/\ \ /\ \ /\ \
\ `\`\/'/ __ ___ \_\ \ __ __ _
`\ `\ /' /'__`\ /' _ `\ /'_` \ /'__`\/\ \/'\
`\ \ \/\ \L\.\_/\ \/\ \/\ \L\ \/\ __/\/> </
\ \_\ \__/.\_\ \_\ \_\ \___,_\ \____\/\_/\_\
\/_/\/__/\/_/\/_/\/_/\/__,_ /\/____/\//\/_/
______ __
/\ _ \ /\ \
\ \ \L\ \ ___ __ \_\ \ __ ___ ___ __ __
\ \ __ \ /'___\ /'__`\ /'_` \ /'__`\/' __` __`\/\ \/\ \
\ \ \/\ \/\ \__//\ \L\.\_/\ \L\ \/\ __//\ \/\ \/\ \ \ \_\ \
\ \_\ \_\ \____\ \__/.\_\ \___,_\ \____\ \_\ \_\ \_\/`____ \
\/_/\/_/\/____/\/__/\/_/\/__,_ /\/____/\/_/\/_/\/_/`/___/> \
/\___/
\/__/
This is the second task in the process of selection to the School of Backend Development. And this is my take on it.
The description of the task is in the Task.md.
Open console in the root folder and run
$ pip install .
After installation just run in the console
$ python -m SBDY_app
or run the python code
from SBDY_app import run
run()
Run
$ python -m SBDY_app -h
to see what arguments run
/CLI takes
If you visit the folder SBDY_app
or specifically SBDY_app/README.md
, you can see an overview of how the app works.
Run the app and then go to http://<host>/docs
or http://<host>/redoc
to see and play with an interactive documentation page (both are diffetren)
Click on the button "Try it out", it allows you to fill the parameters and directly interact with the API
Visit the folder tests
or specifically tests/README.md
for documentation
I chose the FastAPI Python Web framework for handling the REST API requests.
Among
many other nice things it's performant and asynchronous.
In the role of ASGI server, I chose uvicorn as it seems like the lib used inside of FastAPI.
Also see Choosing the Right ASGI Server for Deploying FastAPI
.
Pytest is my favorite testing framework for Python, it's simple and pythonic.
In addition to this, FastAPI recommends using it, so don't mind me if I do ;)
To import and use the given openapi.yaml
for additional site documentation
I used PyYAML
.
It seems to be the most popular library for yaml parsing in python, and I don't need anything special, so great choice!
Also I needed to restrictively parse the ISO 8601 formatted strings.
I could not use pydantic
s datetime
validator because it allows too much.
I settled down on ciso8601
, it's fast and strict.
Also see the folder
tests
or specificallytests/README.md
for documentation on how to run app appropriately for profiling
Open a terminal in the root of the repository and run the commands
$ python -m cProfile -o profile.pstats SBDY_app/__main__.py
to generate a profiling output and run (gprof2dot
requeued)
$ python -m gprof2dot -f pstats profile.pstats > profile.gv
to generate a dot file that visualizes the profiling output
or (snakeviz
requeued)
$ python -m snakeviz profile.pstats
to dynamically look through the table of the profiling results