Yet Another Python Library
Project description
pylib
A python library that helps writing py projects much easier and faster.
Table of contents
This library covers multiple aspects, including:
Documentation
Buffer IO
This module provides several ways to read, write and edit buffers. You can define file
, str
and standard-input
buffers.
for example you can simply read a whole file like this:
reader = BufferReader(FileBuffer(file_path))
while not reader.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'))
while not reader.end_of_buffer():
a, b, c = reader.next_int(), reader.next_string(), reader.next_char()
Data
- DataTransferObject: A tool for converting dictionaries to objects. example:
obj = DataTransferObject.from_dict({'a': 123})
print(obj.a)
# 123
- VariableTypeModifier: Converting types by casting it in a better way.
Debug Tools
- debug_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 modifiers
-
TerminalProcess: A neat progress bar for long tasks.
Config
-
Config: 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 the
configs
folder, you have several .json config files, or folders containing configs. Let's assume we want to accesshumans.male.height
attribute 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 written
Config.read(..., default=180)
File
- File: 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)
Json
- JsonHelper: With this class, you can read, write and merge
json
files 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') # g
JsonHelper.selector_get_value(json_file, 'a.d') # [1, 2]
Path
- PathHelper: Provides absolute pathing for the project. Then you can use releative pathing after reaching the project root. As an example:
path = PathHelper.from_root('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
.
You can also provide how much this function should go back inorder to reach the root of the project. By default, it's assumed this library is been placed in 2 layers away from the root of the project. Something like $project_root/libs/pylib
. If you placed it rather than 2 layers away, you can specify the exact amount of layers it sould went back to reach the root as an backward_times
argument. Then the above example could be rewritten as something like this:
path = PathHelper.from_root(..., backward_times=4)
Argument
- ArgumentParser: 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 --O2
you can access the arguments through:
ArgumentParser.get_value('color') -> green
ArgumentParser.get_value('size') -> 2
ArgumentParser.is_option('O2') -> true
String
Algorithms
Graph
Math
- Geometry: 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) *. scalar
side_sign(p1, p2, p3)
: Returns in which side of the p1->p2 line, p3 is located.inside_polygon(points, p)
segment_intersection(l1, l2)
Paradigms
- DevideAndConquer: Implementation of D&D algorithmic paradigm.
String Processing
- LIS: Longest Increasing Subsequence implementation.
Trees
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pylib_0xe-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ef1910e93020875b5817a089314bfbaf01ba45249cf89d5b5c0fcccaea85951 |
|
MD5 | f661e6296829489c81f19a8cd1180446 |
|
BLAKE2b-256 | c7193011c8e663286bce681ba40c4b9d35e8f0682c8ff603329135ebcdf6a906 |