Package: pyostra
Pyostra PackageCustom terminal colored logging system developed for theAdvanced NFTs Generatorand maintained for future projects.PyPI for releases|Github for sourceInstallationDeveloped for Python 3.9, normally supports CPython 2.7 => 3.10 | Pypy 2.7 and 3.6.Only requirement other than the standard library isColorama, this package have the same Python / platform requirements.pip install pyostraDescriptionPyostra is the main central library used for my own projects such as theAdvanced NFTs Generator. This library allows custom colored and formatted outputs in the Terminal.
The goal is to simplify all the interactions with the terminal by the developers such as try / except errors etc..Note that this library will later include many other general functions, it is not specifically made for Terminal outputs only but to centralize all of the general functions that I'm using in my projects instead of copying the code everytime. I still decided to make it public so people can use it too if they want.LogTypes classThis class contains all the log types for thepyprint()function.It contains all of these log types by default:CRITICALERRORWARNSUCCESSSILENTREADYDATAINFOA log type can also be created by using thenew_log_type()function, it returns a dict with the right format.The dict used for a log type is pretty simply:DATA={# The default name used by the log messages'longName':'DATA',# Check the set_short() function doc below to understand'shortName':'DATA',# The color of the log type at the start'typeColor':Fore.LIGHTCYAN_EX,# The color of the log message'msgColor':Fore.LIGHTCYAN_EX}pyprint() functionDefault format of a Pyprint log, using the default log types:frompyostraimportLogTypes,pyprintdefmain():pyprint(LogTypes.CRITICAL,'THIS IS A TEST')pyprint(LogTypes.ERROR,'THIS IS A TEST')pyprint(LogTypes.WARN,'THIS IS A TEST')pyprint(LogTypes.SUCCESS,'THIS IS A TEST')pyprint(LogTypes.SILENT,'THIS IS A TEST')pyprint(LogTypes.READY,'THIS IS A TEST')pyprint(LogTypes.DATA,'THIS IS A TEST')pyprint(LogTypes.INFO,'THIS IS A TEST')main()Notice thatCRITICAL,ERRORandWARNlog types also returns the calling function name,
it can be disabled by using the optionaldisable_function_nameargument for every log where you don't want the calling function name to show.set_short() functionThis function allows you to reduce the log type length to 4 chars, it can be used if you have a lot of logs at the same time, for better readability. It uses theshortNamestring key inside a log type dict.importpyostrapyostra.set_short(True)If not clear, all the correspondances with the full log types can be found inside the pyprint/set_short function docstring.set_verbose() functionThis function allows to you to reduce the amount of logs inside the Terminal by ignoring some log types.frompyostraimportLogTypes,pyprint,set_verboseset_verbose(False)defmain():pyprint(LogTypes.CRITICAL,'THIS IS A TEST')pyprint(LogTypes.ERROR,'THIS IS A TEST')pyprint(LogTypes.WARN,'THIS IS A TEST')pyprint(LogTypes.SUCCESS,'THIS IS A TEST')pyprint(LogTypes.SILENT,'THIS IS A TEST')# IGNOREDpyprint(LogTypes.READY,'THIS IS A TEST')# IGNOREDpyprint(LogTypes.DATA,'THIS IS A TEST')# IGNORED# IGNORED BY DEFAULT BUT FORCED WITH THE force_verbose ARGpyprint(LogTypes.INFO,'THIS IS A TEST',force_verbose=True)main()By setting the verbose to False, onlyCRITICAL,ERROR,WARNandSUCCESSlog types will be printed, the other ones are ignored.In addition to that, the optional argument calledforce_verboseinside thepyprint()function allows to you print other log types even when the verbose debugging is turned off.new_section() functionThis simple function allows you to separate different types of log by printing a title with a bunch of separators.This function contains only optional args:section_title (str, optional): The title of the current section.skip_line (bool, optional): If True, skip a line before the title.section_title_color (str, optional): Use Colorama for that.separator_char (str, optional): The character used by the section title.separators_amount (int, optional): The amount of separators for the title.frompyostraimportLogTypes,new_section,pyprintdefmain():new_section('TEST SECTION',separators_amount=10)pyprint(LogTypes.CRITICAL,'TEST')extime() functionThis function uses thetimecore library, specifically thetime.perf_counter_ns()function to measure the performances.
It prints the final message into the Terminal by using thepyprint()function (LogTypes.SUCCESStype).This function contains a bunch of args:timer_name (str): Name of the timer.perf_counter_ns_value (int): Using time.perf_counter_ns() to get the starting value of the timer.multiply_timer (int, optional): Multiply the time by a value (To estimate time for x iterations).approximated_value (bool, optional): If True, adds the "~" character to show that it's an approximation.Themultiply_timerand theapproximated_valueargs can be used to estimate the time that it takes to execute a function.
As an example, inside theAdvanced NFTs Generator, I'm generating an NFT 5 times in a row (for a better estimation) to measure the time that it takes, then, I set themultiply_timervalue to the amount of NFTs that needs to be generated (divided by 5 as the measured time is for 5 NFTs). Then I set theapproximated_valuevalue to True, it adds the little~char to show that it is an estimation.frompyostraimportextimeimporttimetimer=time.perf_counter_ns()a=0foriinrange(10000):a+=1extime('Loop execution time',timer)Changelogv0.1.4 (03/06/2022):Complete refactoring.README doc fully written.Main pyprint functions added.Now supports short log types.Logging system using dictionaries.Functions docstring added.Extime function refactored.Arguments & docstring refactoring.v0.1.1 (03/05/2022):Package setup updated.Required packages updated.General refactoring.v0.0.1 (03/05/2022):First release of the pyostra package.