🐍 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 127.0.0.1 --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

Go meets Cisco using SSH

More of Go I have already migrated some scripts from python to go, mostly with API. Decided to check how to SSH into network devices and run some commands. Of course, I used the well-known cisco always-on sandbox. note: using some code as a core and as an example (link in the comments Everything is pretty straightforward here: var ( User string = "developer" Password string = "C1sco12345" hosts = []string{"sandbox-iosxe-latest-1....

July 6, 2022 · 3 min · Dmitry Golovach

How long did the function run in Go

Go (Golang) is fast. This phrase is everywhere. It’s always interesting how long it takes a function to finish its operation. Here is an example of a helper function, that could be used to check and log the timing: func TimeTrack(start time.Time, name string) { elapsed := time.Since(start) log.Printf("%s took %s", name, elapsed) } It takes a start time and the name (could be a function name) as parameters. Use it with the “defer” statement inside the functions:...

July 1, 2022 · 1 min · Dmitry Golovach

Postman Environment Variables

Using Environment in Postman is one of the best things that we can use during the testing and while playing around with API. Postman makes this development phase much easier. API is getting more to the token-centric authentication and Environment Variable becomes handy. I will use Cisco Sandbox for my examples, that is one of the great ways to get some practice with Cisco products API. Setting up Postman Environment Variables:...

February 3, 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