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:
Installation
You can simply install this library through pip, via following commad:
python3 -m pip install pylib-0xe
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
.
This function tries to go back from current directory to reach the root
directory. The defaults root directories are src
and root
. You can
specify the root dir name by passing the root_name=YOUR_ROOT_DIR_NAME
as a kwarg.
Then the above example could be rewritten as something like this:
path = PathHelper.from_root(..., root_name="custom_name")
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
File details
Details for the file pylib_0xe-0.0.3.tar.gz
.
File metadata
- Download URL: pylib_0xe-0.0.3.tar.gz
- Upload date:
- Size: 25.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4618dc33d920e00e725af927f6077a7488d3e932dbccb1fc242c1e6a4cea5d9 |
|
MD5 | 0ec3912e655f6407b5db6c3f153d8759 |
|
BLAKE2b-256 | 8fd962aadef93ce0c39234c533b6136f0055a69c8be894361371f03107d5fa5f |
File details
Details for the file pylib_0xe-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: pylib_0xe-0.0.3-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56f11be05f1b35014a9297f0b47394516d211f9abcc8477dcff9c8568d6ab035 |
|
MD5 | ff4d6441a783b0fdf23ea7d411e41c33 |
|
BLAKE2b-256 | a823d78029ae2dc98568bb3dd17ca483d0e0309f7c39ba984b2c461352931e86 |