🐍 FastAPI built-in API docs

FastAPI has two documentations: by swagger-ui (yourfastapiurl:port/docs) by redoc (yourfastapiurl:port/redoc) from fastapi import FastAPI app = FastAPI() @app.get("/") async def root(): return {"result": "It's working"} @app.get("/ise/{mac_address}") async def ise_search_mac_address(mac_address): return {"Search MAC": mac_address} @app.get("/{mode}/ise") async def ise_mode(mode): if mode == 'dev': return {'result': "Working with Dev ISE"} return {'result': "Working with Prod ISE"} Also you can try it right there: And for sure, great FastAPI Documentation itself: here

November 4, 2022 · 1 min · Dmitry Golovach

🐍 FastAPI Parameters

A quick note about how to pass parameters @app.get("/ise/{mac_address}") async def ise_search_mac_address(mac_address): return {"Search MAC": mac_address} Another example: @app.get("/{mode}/ise") async def ise_mode(mode): if mode == 'dev': return {'result': "Working with Dev ISE"} return {'result': "Working with Prod ISE"}

November 1, 2022 · 1 min · Dmitry Golovach

🐍 FastAPI Quick Start

Short and easy FastAPI startup for a quick playground and testing. pip install fastapi pip install uvicorn – main.py – from fastapi import FastAPI app = FastAPI() @app.get("/") def read_root(): return {"Hello": "World"} @app.get("/hello") def read_root(): return {"Hello": "Hello"} To start using uvicorn: uvicorn app.main:app --host --port 8089

October 31, 2022 · 1 min · Dmitry Golovach

🐍 FastAPI Background Tasks

Nice, useful, and easy-to-use feature in FastAPI. It allows responding to the client and doing whatever needs to be done after the request, the client doesn’t have to wait for the operation to complete. For example, get an API request, respond to the client right away, do the job and send a notification once it’s done as a separate event.

October 28, 2022 · 1 min · Dmitry Golovach

Python Unit Test

Unit Test A unit test verifies that one specific aspect of a function’s behavior is correct. If we have a main file with functions or just a file with functions we want to test different use cases, it is easier to use unittest rather then change the script and run it every time. Here us a function func_to_print_full_name in the func_file.py file: def func_to_print_full_name(first, last): full_name = first + ' ' + last return full_name Create a file (test_func....

December 16, 2021 · 2 min · Dmitry Golovach

Web: HTML - Select vs Datalist

Just found an interesting tag - , which allows to provide the list with options for user to select. I remember while building my web application I used select options and generated the list from some source. How it works with : <form> <div> <input name="country" list="countries" placeholder="Country"> <datalist id="countries"> <option value="Afghanistan"> <option value="Albania"> <option value="Algeria"> <option value="Andorra"> ... </datalist> </div> </form> Found the explanation: element - user must select one of the provided options element - it’s only the list with suggestions, but user can enter anything With <datalist> I can enter anything in there:...

December 8, 2020 · 1 min · Dmitry Golovach

\U0001F40D Python Logging

I decided to take a look into Python Logging and start using it instead of print(). Everything is here: Logging HOWTO. Task you want to perform The best tool for the task Display console output for ordinary usage of a command line script or program print() Report events that occur during normal operation of a program (e.g. for status monitoring or fault investigation) logging.info() (or logging.debug() for very detailed output for diagnostic purposes)...

May 26, 2020 · 3 min · Dmitry Golovach

Linux on Windows, Python IDE, and VirtualEnv

Linux on Windows For some tasks, it is still easier to use Windows (Cisco IP Communicator, UCCX Script Editor, CUCM RTMT, etc.), but there is an option to include Linux into the workflow. Recently I discovered the WLS: Windows Subsystem for Linux (WSL), which allows us to install and run sort of Linux on Windows10 side-by-side. Go to Microsoft Store and search for Linux: Get, Install and Launch: Set username and password and you are in Linux:)...

January 2, 2020 · 2 min · Dmitry Golovach

Python: Script structure

I decided to make some Python notes. Since there is a ton of information about Python, these notes will be mostly for my reference but if they help anyone - it will be great. The best way to understand it - try it and make a note:) starting with the basic script structure: starting with the basic script structure: #!/usr/bin/env python # """Module docstring.""" # Imports import time import sys # Module Constants CONSTANT_VARIABLE = "Variables that Probably shouldn't be changed" # Module "Global" Variables global_variable_file = "file....

December 31, 2019 · 4 min · Dmitry Golovach

Python: Simple Email Gmail

Sometimes it is very useful to have the script that sends notification, when finishes executing, has come to an error or just needs to send some data to you.This script is used to send a simple email from a gmail account (can be configured for other email servers). I was working on the task, that involved Cisco ISE, guest portal and python - love it. This part will cover only Python and send email feature....

September 24, 2019 · 1 min · Dmitry Golovach