Package: pylib-0xe
pylibA python library that helps writing py projects much easier and faster.Table of contentsThis library covers multiple aspects, including:Table of contentsInstallationDocumentationBuffer IODataDebug ToolsConfigFileJsonPathArgumentStringAlgorithmsGraphMathParadigmsString ProcessingTreesInstallationYou can simply install this library through pip, via following commad:python3-mpipinstallpylib-0xeDocumentationBuffer IOThis module provides several ways to read, write and edit buffers.
You can definefile,strandstandard-inputbuffers.BufferBufferReaderBufferWriterStandardInputBufferFileBufferStringBufferfor example you can simply read a whole file like this:reader=BufferReader(FileBuffer(file_path))whilenotreader.end_of_buffer():line=reader.next_line()or you can define a string as a buffer and treat it in the same way:reader=BufferReader(StringBuffer('some awesome text'))whilenotreader.end_of_buffer():a,b,c=reader.next_int(),reader.next_string(),reader.next_char()DataDataTransferObject:
A tool for converting dictionaries to objects. example:obj=DataTransferObject.from_dict({'a':123})print(obj.a)#  123VariableTypeModifier:
Converting types by casting it in a better way.Debug Toolsdebug_text: Alternative way to debuging
the code via prints into the stderr. example:debug_text('%B%USome Object%E[%c#%%E] ->%r%%E',12,{"a":34})[Some Object[#12] -> {'a': 34}]list of options:%c: cyan color%r: red color%b: blue color%g: green color%y: yellow color%H: alternative color%B: bold text%U: underlined text%E: clear modifiersTerminalProcess:
A neat progress bar for long tasks.ConfigConfig: A facade class to read
json config files easily. I'ts so powerful when you
provide your configs in the hierarchical pattern.
example usage:
under theconfigsfolder, you have several .json config files,
or folders containing configs. Let's assume we want to accesshumans.male.heightattribute frommammals.json.
We have two approaches to achieve it:Config('mammals').get('humans.male.height)Config.read('mammals.humans.male.height)It could have default value if there is no correspond
attribute was found. like we could have writtenConfig.read(..., default=180)FileFile: A class that contains some useful
functions to deal with files. Some of them are:read_json(file_path)read_csv(file_path)append_to_file(file_path, string)get_all_files(directory_path, extension)JsonJsonHelper: With this class, you can read,
write and mergejsonfiles with dot notations.
Selector example (forfile.json):{"a":{"b":{"c":{"f":"g"}},"d":[1,2],"e":{}}}json_file=File.read_json('file.json')JsonHelper.selector_get_value(json_file,'a.b.c.f')# gJsonHelper.selector_get_value(json_file,'a.d')# [1, 2]PathPathHelper:
Provides absolute pathing for the project. Then you can
use releative pathing after reaching the project root. As an example:path=PathHelper.from_root(__file__,'assets','imgs','1.png')It will construct the path from the root of the project to the desired file,
for this specific example, the file should be accessible under this path:$project_root/assets/imgs/1.png.
This function tries to go back from__file__directory to reach therootdirectory. The default root directories aresrcandroot. You can
specify the root directory name by passing theroot_name=YOUR_ROOT_DIR_NAMEas a kwarg.
Then the above example could be rewritten as something like this:path=PathHelper.from_root(...,root_name="custom_name")The best practice to use it with custom root directory is to write a new PathHelper
class that extends this class and apply your customroot_nameto it. It should
be implemented like this:frompylib_0xe.path.path_helperimportPathHelperasPHclassPathHelper(PH):@classmethoddeffrom_root(cls,*path:str)->str:returncls.from_root(__file__,*path,root_name="custom_name")ArgumentArgumentParser:
Useful tool to reading arguments passed to a python program executed via command line interface (terminal).
for example if you run your program as follow:python3 main.py --color green --size 2 --fast --O2you can access the arguments through:ArgumentParser.get_value('color')->greenArgumentParser.get_value('size')->2ArgumentParser.is_option('O2')->trueStringStringHelperHashGeneratorAlgorithmsGraphflows: provides algorithms in max-flow problem, including:MaxFlowMSTTSPMathGeometry: A neat implemented 2d-geometry
library. Some of the usefull functions that it provides are:translate(expression, *points): recieves arithmatic expression and
the points afterwards. Returns the answer of the expression. example:translate('* + *.', p1, p2, p3, scalar)=((p1 * p2) + p3) *. scalarside_sign(p1, p2, p3): Returns in which side of the p1->p2 line, p3 is located.inside_polygon(points, p)segment_intersection(l1, l2)ParadigmsDevideAndConquer:
Implementation of D&D algorithmic paradigm.String ProcessingLIS: Longest Increasing Subsequence implementation.TreesAvlTree