Skip to main content

Yet Another Python Library

Project description

pylib

pylib

                 Python License

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

obj = DataTransferObject.from_dict({'a': 123})
print(obj.a)
#  123

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:

    1. %c: cyan color
    2. %r: red color
    3. %b: blue color
    4. %g: green color
    5. %y: yellow color
    6. %H: alternative color
    7. %B: bold text
    8. %U: underlined text
    9. %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 access humans.male.height attribute from mammals.json. We have two approaches to achieve it:

    1. Config('mammals').get('humans.male.height)
    2. 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 (for file.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(__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 the root directory. The default root directories are src and root. You can specify the root directory 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")

The best practice to use it with custom root directory is to write a new PathHelper class that extends this class and apply your custom root_name to it. It should be implemented like this:

from pylib_0xe.path.path_helper import PathHelper as PH


class PathHelper(PH):
  @classmethod
  def from_root(cls, *path: str) -> str:
    return cls.from_root(__file__, *path, 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

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

pylib_0xe-0.0.4.tar.gz (26.3 kB view details)

Uploaded Source

Built Distribution

pylib_0xe-0.0.4-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file pylib_0xe-0.0.4.tar.gz.

File metadata

  • Download URL: pylib_0xe-0.0.4.tar.gz
  • Upload date:
  • Size: 26.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pylib_0xe-0.0.4.tar.gz
Algorithm Hash digest
SHA256 09100e5db1da9a60a5cc21b910ea1c55357891f64e63c0e8678aa23155c118b1
MD5 3396223dbe7342579857fdb15bff6e64
BLAKE2b-256 787c4dc2067ac77b3cdf63af610ae04a5173dff27f43b0fda420515984f8d168

See more details on using hashes here.

File details

Details for the file pylib_0xe-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pylib_0xe-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 29.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pylib_0xe-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cefbe5412604c3d4dccc097a5a289006779df51c38628269445f12de9a719105
MD5 ab5824da93099e4a4c5a6376fcaaee91
BLAKE2b-256 c0087a30da56a8205182d9e4320fde5444b06daf97fbac15ef76b454da1b3485

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page