plazy


Nameplazy JSON
Version 0.1.6 PyPI version JSON
download
home_pagehttps://github.com/kyzas/plazy
SummaryUtilities for lazy Python developers
upload_time2023-09-24 19:46:35
maintainerkyzas
docs_urlNone
authorkyzas
requires_python<4,>=3.5
licenseMIT
keywords
VCS
bugtrack_url
requirements scake sphinx sphinx_rtd_theme
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src='https://img.shields.io/pypi/l/plazy.svg'> <img src='https://codecov.io/gh/kyzas/plazy/branch/master/graph/badge.svg'> <img src='https://img.shields.io/pypi/pyversions/plazy.svg'> <img src='https://img.shields.io/pypi/v/plazy.svg'> <img src='https://img.shields.io/pypi/dm/plazy.svg'> <img src='https://img.shields.io/badge/code%20style-black-000000.svg'> <img src='https://readthedocs.org/projects/plazy/badge/?version=latest&style=plastic'>

# plazy
Utilities for lazy Python developers

```
pip install plazy
```

# Index

- [Coding](#coding)
  - [plazy.random_string(size=6, digit=True, lower=True, upper=True)](#random_string)  
  - [plazy.setattr_from_dict(obj, kv, override=True)](#setattr_from_dict)
  - [@plazy.auto_assign](#auto_assign)
  - [@plazy.auto_assign_strict](#auto_assign_strict)
  - [@plazy.cloneable](#cloneable)
  - [plazy.tic(&#42;names)](#tic)
  - [plazy.toc(&#42;names, default=0)](#toc)
  - [plazy.ts2dt(ts, format="%Y/%m/%d %H:%M:%S.%f")](#ts2dt)
  - [plazy.dt2ts(dt, format="%Y/%m/%d %H:%M:%S.%f")](#dt2ts)
- [Data](#data)
  - [plazy.b64encode(value, pretty=False)](#b64encode)
  - [plazy.b64decode(value)](#b64decode)
  - [plazy.is_number(s)](#is_number)
  - [plazy.unique(seq, sort=False, reverse=False)](#unique)
- [File](#file)
  - [plazy.read_txt(path, line_func=None, skip_empty_line=False)](#read_txt)
  - [plazy.write_txt(path, lines, mode="w", cat_str="\n")](#write_txt)
  - [plazy.list_files(root, filter_func=None, is_include_root=False)](#list_files)

# PLAZY FEATURES

## Coding

### random_string

Plazy version: 0.1.2+

Generate random string.

**plazy.random_string(**

- size: length of random string. Default: 6
- digit: random string may contains digits. Default: True
- lower: random string may contains lowercases. Default: True
- upper: random string may contains uppercases. Default: True

**)**

``` python
import plazy

if __name__ == "__main__":
    rstring = plazy.random_string() # iVr3FY
    rstring = plazy.random_string(upper=False) # mzvn7b
    rstring = plazy.random_string(size=8) # XqVDuu5R
    rstring = plazy.random_string(size=6, digit=True, lower=False, upper=False) # 763099
    rstring = plazy.random_string(size=6, digit=False, lower=True, upper=False) # djzcch
    rstring = plazy.random_string(size=6, digit=False, lower=False, upper=True) # BGBMQN
```

[:link: Back to Index](#index)

### setattr_from_dict

Plazy version: 0.1.4+

Dynamically set object attributes from dictionary at runtime

**plazy.setattr_from_dict(**

- **obj**: object
- **kv**: dictionary of new attributes. Eg: {"name": "Peter", "age": 14}
- override: override old attribute(s). Default: True

**)**

``` python
import plazy

# Our custom class
class Person(object):
    def __init__(self, name):
        self.name = name

if __name__ == "__main__":
    p1 = Person(name="plazy") # init a Person object
    plazy.setattr_from_dict(obj=p1, kv={
        "name": "yzalp",
        "age": 28,
    })
    print(p1.name) # "yzalp"
    print(p1.age)  # 28

    # set "override" to False
    p2 = Person(name="plazy") # init a Person object
    plazy.setattr_from_dict(obj=p2,
                            override=False,
                            kv={
                                "name": "yzalp",
                                "age": 28,
                            })
    print(p1.name) # "plazy" <- no overriding the pre-existed attribute due to "override=False"
    print(p1.age)  # 28

```

[:link: Back to Index](#index)

### auto_assign

Plazy version: 0.1.5+

Assign attributes of class with the passed arguments automatically.



**@plazy.auto_assign**

``` python
import plazy

class Cat(object):
    @plazy.auto_assign
    def __init__(self, name, owner='Kyzas'):
        # no variable assignment needed
        pass

    def get_age(self):
        return self.age if hasattr(self, "age") else None

    def get_type(self):
        return self.type if hasattr(self, "type") else None

if __name__ == "__main__":
    mydict = {"type": "pet"}
    my_cat = Cat('Kittie', age=10, **mydict) # "age" and "type" is unexpected arguments
    print(my_cat.name)          # Kittie
    print(my_cat.owner)         # Kyzas
    print(my_cat.get_age())     # 10
    print(my_cat.get_type())    # pet
```

[:link: Back to Index](#index)

### auto_assign_strict

Plazy version: 0.1.5+

Assign attributes of class with the passed arguments automatically, strictly check the parameters passed to the function.

**@plazy.auto_assign_strict**

``` python
import plazy

class Cat(object):
    @plazy.auto_assign_strict
    def __init__(self, name, owner='Kyzas'):
        pass

if __name__ == "__main__":
    my_cat = Cat('Kittie', 'Minh')
    print(my_cat.name)      # Kittie
    print(my_cat.owner)     # Minh
    his_cat = Cat('Lulu', 'Peter', 'Mary')  # TypeError
    her_cat = Cat('Kittie', age=10)         # TypeError
```

[:link: Back to Index](#index)

### cloneable

Plazy version: 0.1.5+

Mark constructor of class as being cloneable. Method "clone" is used to clone a new instance, its arguments are the same with the constructor.

**@plazy.cloneable**

``` python
import plazy

class Cat(object):
    @plazy.cloneable
    def __init__(self, name, owner='Kyzas'):
        self.name = name
        self.owner = owner
        pass

    def get_info(self):
        return {"name": self.name, "owner": self.owner}

class Dog(object):
    # combine auto_assign and cloneable decorators
    @plazy.cloneable
    @plazy.auto_assign
    def __init__(self, name, owner='Kyzas'):
        pass

    def get_info(self):
        result = {"name": self.name, "owner": self.owner}
        if hasattr(self, "age"):
            result["age"] = self.age
        else:
            result["age"] = -1
        return result

if __name__ == "__main__":
    cat_template = Cat('<Cat Name>', '<Owner Name>')
    his_cat = cat_template.clone('Lulu', 'Peter')
    her_cat = cat_template.clone(name='Jessie')
    print(his_cat.get_info()) # {'name': 'Lulu', 'owner': 'Peter'}
    print(her_cat.get_info()) # {'name': 'Jessie', 'owner': '<Owner Name>'}

    dog_template = Dog(name="<Dog Name>", owner="<Owner Name>", age=10) # age=10 by default
    his_dog = dog_template.clone(owner='James')
    her_dog = dog_template.clone(name="Husky", owner="Bella", age=5, note="Super Cute")
    print(his_dog.get_info()) # {'name': '<Dog Name>', 'owner': 'James', 'age': 10}
    print(her_dog.get_info()) # {'name': 'Husky', 'owner': 'Bella', 'age': 5}
    print(her_dog.note)       # Super Cute
```

[:link: Back to Index](#index)

### tic

Plazy version: 0.1.5+

Start timer

**plazy.tic(**

- **&#42;names**: name (list)

**)**

``` python
import plazy

def foo():
    total = 0
    for _ in range(100000):
        total += 1
    return total

if __name__ == "__main__":
    plazy.tic()                 # T1
    plazy.tic("B")              # T2
    plazy.tic("C", "D", "E")    # T3
    foo()
    dt1 = plazy.toc()           # elapsed time since T1
    dt2 = plazy.toc("B")        # elapsed time since T2
    dt3 = plazy.toc("C", "D")   # elapsed time since T3
    foo()
    dt4 = plazy.toc("E")        # elapsed time since T3
    dt5 = plazy.toc("B")        # elapsed time since T2
    print(dt1)                  # 0.009924173355102539
    print(dt2)                  # 0.009925603866577148
    print(dt3)                  # [0.00992727279663086, 0.00992727279663086]
    print(dt4)                  # 0.020497798919677734
    print(dt5)                  # 0.020506620407104492
```

[:link: Back to Index](#index)

### toc

Plazy version: 0.1.5+

Get elapsed time(s) by name(s)

**plazy.toc(**

- **&#42;names**: name (list)
- **default**: default value if name not found. Default: 0

**)**

``` python
import plazy

def foo():
    total = 0
    for _ in range(100000):
        total += 1
    return total

if __name__ == "__main__":
    plazy.tic()
    foo()
    elapsed_seconds = plazy.toc()                   # 0.0098724365234375
    elapsed_invalid = plazy.toc("B", default=-1)    # -1 (name "B" does not exist, return default value)
```

[:link: Back to Index](#index)

### ts2dt

Plazy version: 0.1.5+

Convert timestamp to datetime string

**plazy.ts2dt(**

- **ts**: timestamp string
- **format**: datetime format. Default: "%Y/%m/%d %H:%M:%S.%f"

**)**

``` python
import time
import plazy

if __name__ == "__main__":
    res = plazy.ts2dt(time.time()) # 2021/08/28 08:48:05.451271
```

[:link: Back to Index](#index)

### dt2ts

Plazy version: 0.1.5+

Convert datetime object / datetime string to timestamp

**plazy.dt2ts(**

- **dt**: datetime object or datetime string
- **format**: datetime format. Default: "%Y/%m/%d %H:%M:%S.%f"

**)**

``` python
import time
import plazy

if __name__ == "__main__":
    res = plazy.dt2ts("2021/08/28 08:48:05.451271") # 1630140485.451271
    print(res)
```

[:link: Back to Index](#index)

## Data

### b64encode

### b64decode

Plazy version: 0.1.3+

Base64 encode and decode for string.

**plazy.b64encode(**

- **value**: value to encode base64
- pretty: remove "=" character at the end after encoding. Default: False

**)**

**plazy.b64decode(**

- **value**: encoded base64 value to decode

**)**

``` python
import plazy

if __name__ == "__main__":
    encoded_val = plazy.b64encode('plazy') # cGxhenk=
    encoded_val = plazy.b64encode('plazy', pretty=True) # cGxhenk => Note: this string cannot be decoded!
    original_val = plazy.b64decode('cGxhenk=') # plazy
```

[:link: Back to Index](#index)

### is_number

Plazy version: 0.1.4+

Check whether string is a number

**plazy.is_number(**

- **s**: string to check

**)**

``` python
import plazy

if __name__ == "__main__":
    is_number = plazy.is_number("1")         # True
    is_number = plazy.is_number("0.234")     # True
    is_number = plazy.is_number("-0.234")    # True
    is_number = plazy.is_number("1e3")       # True
    is_number = plazy.is_number("plazy")     # False
    is_number = plazy.is_number("1.23k9")    # False
    is_number = plazy.is_number("x.3253254") # False
```

[:link: Back to Index](#index)

### unique

Plazy version: 0.1.3+

Turn list or tuple into unique list/tuple, keep order or sort the list/tuple.

**plazy.unique(**

- **seq**: sequence to process. Eg: [1, 3, 1, 2], (2, 5, 5, 1, 2), ...
- sort: Sort result. Default: False
- reverse: Reverse result. Default: False

**)**

``` python
import plazy

if __name__ == "__main__":
    unique_t = plazy.unique(seq=(7, 3, 5, 3, 3, 7, 9)) # -> (7, 3, 5, 9)  
    unique_l = plazy.unique(seq=[7, 3, 5, 3, 3, 7, 9]) # -> [7, 3, 5, 9]
    unique_rt = plazy.unique(seq=(7, 3, 5, 3, 3, 7, 9), sort=True, reverse=True) # -> (9, 7, 5, 3)
```

[:link: Back to Index](#index)

## File

### read_txt

Plazy version: ~~0.1.2+~~, 0.1.4+

~~Read lines of text file, eliminate redundant characters of each line, skip the empty lines.~~

Read lines of text file as a list.

**plazy.read_txt(**

- **path**: path to text file
- line_func: function to process each line. Default: None
- skip_empty_line: skip empty line. Default: False

**)**

``` python
import plazy

if __name__ == "__main__":
    lines = plazy.read_txt(path='/home/video-list.txt')
    print(lines) # ['<line#1>', '<line#2>', '<line#3>', ...]

    # strip every text line, remove empty line in the list:
    lines = plazy.read_txt(
        path='/home/video-list.txt',
        line_func=lambda x : x.strip(),
        skip_empty_line=True
    )

    # -------------------------------
    # deprecated @ Plazy v0.1.2
    # lines = plazy.read_txt(path='/home/video-list.txt', strip=True)
    # print(lines) # ['<line#1>', '<line#2>', '<line#3>', ...]
    # lines = plazy.read_txt(path='/home/video-list.txt', strip=False) # no stripping
```

[:link: Back to Index](#index)

### write_txt

Plazy version: 0.1.4+

Write text file.

**plazy.write_txt(**

- **path**: path to text file
- **lines**: lines to write
- mode: write mode. Default: "w"
- cat_str: concat string between lines. Default: "\n" (new line character)

**)**

``` python
import os
import plazy

if __name__ == "__main__":
    path = '/home/plazy.txt'
    lines = [
        "hello",
        "world",
    ]
    plazy.write_txt(path=path, lines=lines)
    assert os.path.isfile(path)
```

[:link: Back to Index](#index)

### list_files

Plazy version: 0.1.1+

List files recursively in directory.

**plazy.list_files(**

- root: directory to traverse files. Default: "./" (current directory)
- filter_func: filter function to apply. Default: None
- is_include_root: include root directory path in the result. Default: False

**)**

``` python
import plazy

if __name__ == "__main__":
    files = plazy.list_files(root='images',
                            filter_func=lambda x : True if x.endswith('.jpg') else False,
                            is_include_root=False)
    print(files) # ['1.jpg', '2.jpg', '_sub_/4.jpg']
```

[:link: Back to Index](#index)

# CONTRIBUTING

* Step 1. Fork on **dev** branch.
* Step 2. Install **pre-commit** on the local dev environment.

```
pip install pre-commit
pre-commit install
```

* Step 3. Write test case(s) for the new feature or the bug.
* Step 4. Write code to pass the tests.
* Step 5. Make sure that the new code passes all the pre-commmit conditions.

```
pre-commit run -a
```

* Step 6. Create pull request.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kyzas/plazy",
    "name": "plazy",
    "maintainer": "kyzas",
    "docs_url": null,
    "requires_python": "<4,>=3.5",
    "maintainer_email": "kyznano@gmail.com",
    "keywords": "",
    "author": "kyzas",
    "author_email": "kyznano@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/38/ee/3d1d2edebadf005937f04d88ec287bdf214ba8a8e9964d5afd4e6d774f44/plazy-0.1.6.tar.gz",
    "platform": null,
    "description": "<img src='https://img.shields.io/pypi/l/plazy.svg'> <img src='https://codecov.io/gh/kyzas/plazy/branch/master/graph/badge.svg'> <img src='https://img.shields.io/pypi/pyversions/plazy.svg'> <img src='https://img.shields.io/pypi/v/plazy.svg'> <img src='https://img.shields.io/pypi/dm/plazy.svg'> <img src='https://img.shields.io/badge/code%20style-black-000000.svg'> <img src='https://readthedocs.org/projects/plazy/badge/?version=latest&style=plastic'>\n\n# plazy\nUtilities for lazy Python developers\n\n```\npip install plazy\n```\n\n# Index\n\n- [Coding](#coding)\n  - [plazy.random_string(size=6, digit=True, lower=True, upper=True)](#random_string)  \n  - [plazy.setattr_from_dict(obj, kv, override=True)](#setattr_from_dict)\n  - [@plazy.auto_assign](#auto_assign)\n  - [@plazy.auto_assign_strict](#auto_assign_strict)\n  - [@plazy.cloneable](#cloneable)\n  - [plazy.tic(&#42;names)](#tic)\n  - [plazy.toc(&#42;names, default=0)](#toc)\n  - [plazy.ts2dt(ts, format=\"%Y/%m/%d %H:%M:%S.%f\")](#ts2dt)\n  - [plazy.dt2ts(dt, format=\"%Y/%m/%d %H:%M:%S.%f\")](#dt2ts)\n- [Data](#data)\n  - [plazy.b64encode(value, pretty=False)](#b64encode)\n  - [plazy.b64decode(value)](#b64decode)\n  - [plazy.is_number(s)](#is_number)\n  - [plazy.unique(seq, sort=False, reverse=False)](#unique)\n- [File](#file)\n  - [plazy.read_txt(path, line_func=None, skip_empty_line=False)](#read_txt)\n  - [plazy.write_txt(path, lines, mode=\"w\", cat_str=\"\\n\")](#write_txt)\n  - [plazy.list_files(root, filter_func=None, is_include_root=False)](#list_files)\n\n# PLAZY FEATURES\n\n## Coding\n\n### random_string\n\nPlazy version: 0.1.2+\n\nGenerate random string.\n\n**plazy.random_string(**\n\n- size: length of random string. Default: 6\n- digit: random string may contains digits. Default: True\n- lower: random string may contains lowercases. Default: True\n- upper: random string may contains uppercases. Default: True\n\n**)**\n\n``` python\nimport plazy\n\nif __name__ == \"__main__\":\n    rstring = plazy.random_string() # iVr3FY\n    rstring = plazy.random_string(upper=False) # mzvn7b\n    rstring = plazy.random_string(size=8) # XqVDuu5R\n    rstring = plazy.random_string(size=6, digit=True, lower=False, upper=False) # 763099\n    rstring = plazy.random_string(size=6, digit=False, lower=True, upper=False) # djzcch\n    rstring = plazy.random_string(size=6, digit=False, lower=False, upper=True) # BGBMQN\n```\n\n[:link: Back to Index](#index)\n\n### setattr_from_dict\n\nPlazy version: 0.1.4+\n\nDynamically set object attributes from dictionary at runtime\n\n**plazy.setattr_from_dict(**\n\n- **obj**: object\n- **kv**: dictionary of new attributes. Eg: {\"name\": \"Peter\", \"age\": 14}\n- override: override old attribute(s). Default: True\n\n**)**\n\n``` python\nimport plazy\n\n# Our custom class\nclass Person(object):\n    def __init__(self, name):\n        self.name = name\n\nif __name__ == \"__main__\":\n    p1 = Person(name=\"plazy\") # init a Person object\n    plazy.setattr_from_dict(obj=p1, kv={\n        \"name\": \"yzalp\",\n        \"age\": 28,\n    })\n    print(p1.name) # \"yzalp\"\n    print(p1.age)  # 28\n\n    # set \"override\" to False\n    p2 = Person(name=\"plazy\") # init a Person object\n    plazy.setattr_from_dict(obj=p2,\n                            override=False,\n                            kv={\n                                \"name\": \"yzalp\",\n                                \"age\": 28,\n                            })\n    print(p1.name) # \"plazy\" <- no overriding the pre-existed attribute due to \"override=False\"\n    print(p1.age)  # 28\n\n```\n\n[:link: Back to Index](#index)\n\n### auto_assign\n\nPlazy version: 0.1.5+\n\nAssign attributes of class with the passed arguments automatically.\n\n\n\n**@plazy.auto_assign**\n\n``` python\nimport plazy\n\nclass Cat(object):\n    @plazy.auto_assign\n    def __init__(self, name, owner='Kyzas'):\n        # no variable assignment needed\n        pass\n\n    def get_age(self):\n        return self.age if hasattr(self, \"age\") else None\n\n    def get_type(self):\n        return self.type if hasattr(self, \"type\") else None\n\nif __name__ == \"__main__\":\n    mydict = {\"type\": \"pet\"}\n    my_cat = Cat('Kittie', age=10, **mydict) # \"age\" and \"type\" is unexpected arguments\n    print(my_cat.name)          # Kittie\n    print(my_cat.owner)         # Kyzas\n    print(my_cat.get_age())     # 10\n    print(my_cat.get_type())    # pet\n```\n\n[:link: Back to Index](#index)\n\n### auto_assign_strict\n\nPlazy version: 0.1.5+\n\nAssign attributes of class with the passed arguments automatically, strictly check the parameters passed to the function.\n\n**@plazy.auto_assign_strict**\n\n``` python\nimport plazy\n\nclass Cat(object):\n    @plazy.auto_assign_strict\n    def __init__(self, name, owner='Kyzas'):\n        pass\n\nif __name__ == \"__main__\":\n    my_cat = Cat('Kittie', 'Minh')\n    print(my_cat.name)      # Kittie\n    print(my_cat.owner)     # Minh\n    his_cat = Cat('Lulu', 'Peter', 'Mary')  # TypeError\n    her_cat = Cat('Kittie', age=10)         # TypeError\n```\n\n[:link: Back to Index](#index)\n\n### cloneable\n\nPlazy version: 0.1.5+\n\nMark constructor of class as being cloneable. Method \"clone\" is used to clone a new instance, its arguments are the same with the constructor.\n\n**@plazy.cloneable**\n\n``` python\nimport plazy\n\nclass Cat(object):\n    @plazy.cloneable\n    def __init__(self, name, owner='Kyzas'):\n        self.name = name\n        self.owner = owner\n        pass\n\n    def get_info(self):\n        return {\"name\": self.name, \"owner\": self.owner}\n\nclass Dog(object):\n    # combine auto_assign and cloneable decorators\n    @plazy.cloneable\n    @plazy.auto_assign\n    def __init__(self, name, owner='Kyzas'):\n        pass\n\n    def get_info(self):\n        result = {\"name\": self.name, \"owner\": self.owner}\n        if hasattr(self, \"age\"):\n            result[\"age\"] = self.age\n        else:\n            result[\"age\"] = -1\n        return result\n\nif __name__ == \"__main__\":\n    cat_template = Cat('<Cat Name>', '<Owner Name>')\n    his_cat = cat_template.clone('Lulu', 'Peter')\n    her_cat = cat_template.clone(name='Jessie')\n    print(his_cat.get_info()) # {'name': 'Lulu', 'owner': 'Peter'}\n    print(her_cat.get_info()) # {'name': 'Jessie', 'owner': '<Owner Name>'}\n\n    dog_template = Dog(name=\"<Dog Name>\", owner=\"<Owner Name>\", age=10) # age=10 by default\n    his_dog = dog_template.clone(owner='James')\n    her_dog = dog_template.clone(name=\"Husky\", owner=\"Bella\", age=5, note=\"Super Cute\")\n    print(his_dog.get_info()) # {'name': '<Dog Name>', 'owner': 'James', 'age': 10}\n    print(her_dog.get_info()) # {'name': 'Husky', 'owner': 'Bella', 'age': 5}\n    print(her_dog.note)       # Super Cute\n```\n\n[:link: Back to Index](#index)\n\n### tic\n\nPlazy version: 0.1.5+\n\nStart timer\n\n**plazy.tic(**\n\n- **&#42;names**: name (list)\n\n**)**\n\n``` python\nimport plazy\n\ndef foo():\n    total = 0\n    for _ in range(100000):\n        total += 1\n    return total\n\nif __name__ == \"__main__\":\n    plazy.tic()                 # T1\n    plazy.tic(\"B\")              # T2\n    plazy.tic(\"C\", \"D\", \"E\")    # T3\n    foo()\n    dt1 = plazy.toc()           # elapsed time since T1\n    dt2 = plazy.toc(\"B\")        # elapsed time since T2\n    dt3 = plazy.toc(\"C\", \"D\")   # elapsed time since T3\n    foo()\n    dt4 = plazy.toc(\"E\")        # elapsed time since T3\n    dt5 = plazy.toc(\"B\")        # elapsed time since T2\n    print(dt1)                  # 0.009924173355102539\n    print(dt2)                  # 0.009925603866577148\n    print(dt3)                  # [0.00992727279663086, 0.00992727279663086]\n    print(dt4)                  # 0.020497798919677734\n    print(dt5)                  # 0.020506620407104492\n```\n\n[:link: Back to Index](#index)\n\n### toc\n\nPlazy version: 0.1.5+\n\nGet elapsed time(s) by name(s)\n\n**plazy.toc(**\n\n- **&#42;names**: name (list)\n- **default**: default value if name not found. Default: 0\n\n**)**\n\n``` python\nimport plazy\n\ndef foo():\n    total = 0\n    for _ in range(100000):\n        total += 1\n    return total\n\nif __name__ == \"__main__\":\n    plazy.tic()\n    foo()\n    elapsed_seconds = plazy.toc()                   # 0.0098724365234375\n    elapsed_invalid = plazy.toc(\"B\", default=-1)    # -1 (name \"B\" does not exist, return default value)\n```\n\n[:link: Back to Index](#index)\n\n### ts2dt\n\nPlazy version: 0.1.5+\n\nConvert timestamp to datetime string\n\n**plazy.ts2dt(**\n\n- **ts**: timestamp string\n- **format**: datetime format. Default: \"%Y/%m/%d %H:%M:%S.%f\"\n\n**)**\n\n``` python\nimport time\nimport plazy\n\nif __name__ == \"__main__\":\n    res = plazy.ts2dt(time.time()) # 2021/08/28 08:48:05.451271\n```\n\n[:link: Back to Index](#index)\n\n### dt2ts\n\nPlazy version: 0.1.5+\n\nConvert datetime object / datetime string to timestamp\n\n**plazy.dt2ts(**\n\n- **dt**: datetime object or datetime string\n- **format**: datetime format. Default: \"%Y/%m/%d %H:%M:%S.%f\"\n\n**)**\n\n``` python\nimport time\nimport plazy\n\nif __name__ == \"__main__\":\n    res = plazy.dt2ts(\"2021/08/28 08:48:05.451271\") # 1630140485.451271\n    print(res)\n```\n\n[:link: Back to Index](#index)\n\n## Data\n\n### b64encode\n\n### b64decode\n\nPlazy version: 0.1.3+\n\nBase64 encode and decode for string.\n\n**plazy.b64encode(**\n\n- **value**: value to encode base64\n- pretty: remove \"=\" character at the end after encoding. Default: False\n\n**)**\n\n**plazy.b64decode(**\n\n- **value**: encoded base64 value to decode\n\n**)**\n\n``` python\nimport plazy\n\nif __name__ == \"__main__\":\n    encoded_val = plazy.b64encode('plazy') # cGxhenk=\n    encoded_val = plazy.b64encode('plazy', pretty=True) # cGxhenk => Note: this string cannot be decoded!\n    original_val = plazy.b64decode('cGxhenk=') # plazy\n```\n\n[:link: Back to Index](#index)\n\n### is_number\n\nPlazy version: 0.1.4+\n\nCheck whether string is a number\n\n**plazy.is_number(**\n\n- **s**: string to check\n\n**)**\n\n``` python\nimport plazy\n\nif __name__ == \"__main__\":\n    is_number = plazy.is_number(\"1\")         # True\n    is_number = plazy.is_number(\"0.234\")     # True\n    is_number = plazy.is_number(\"-0.234\")    # True\n    is_number = plazy.is_number(\"1e3\")       # True\n    is_number = plazy.is_number(\"plazy\")     # False\n    is_number = plazy.is_number(\"1.23k9\")    # False\n    is_number = plazy.is_number(\"x.3253254\") # False\n```\n\n[:link: Back to Index](#index)\n\n### unique\n\nPlazy version: 0.1.3+\n\nTurn list or tuple into unique list/tuple, keep order or sort the list/tuple.\n\n**plazy.unique(**\n\n- **seq**: sequence to process. Eg: [1, 3, 1, 2], (2, 5, 5, 1, 2), ...\n- sort: Sort result. Default: False\n- reverse: Reverse result. Default: False\n\n**)**\n\n``` python\nimport plazy\n\nif __name__ == \"__main__\":\n    unique_t = plazy.unique(seq=(7, 3, 5, 3, 3, 7, 9)) # -> (7, 3, 5, 9)  \n    unique_l = plazy.unique(seq=[7, 3, 5, 3, 3, 7, 9]) # -> [7, 3, 5, 9]\n    unique_rt = plazy.unique(seq=(7, 3, 5, 3, 3, 7, 9), sort=True, reverse=True) # -> (9, 7, 5, 3)\n```\n\n[:link: Back to Index](#index)\n\n## File\n\n### read_txt\n\nPlazy version: ~~0.1.2+~~, 0.1.4+\n\n~~Read lines of text file, eliminate redundant characters of each line, skip the empty lines.~~\n\nRead lines of text file as a list.\n\n**plazy.read_txt(**\n\n- **path**: path to text file\n- line_func: function to process each line. Default: None\n- skip_empty_line: skip empty line. Default: False\n\n**)**\n\n``` python\nimport plazy\n\nif __name__ == \"__main__\":\n    lines = plazy.read_txt(path='/home/video-list.txt')\n    print(lines) # ['<line#1>', '<line#2>', '<line#3>', ...]\n\n    # strip every text line, remove empty line in the list:\n    lines = plazy.read_txt(\n        path='/home/video-list.txt',\n        line_func=lambda x : x.strip(),\n        skip_empty_line=True\n    )\n\n    # -------------------------------\n    # deprecated @ Plazy v0.1.2\n    # lines = plazy.read_txt(path='/home/video-list.txt', strip=True)\n    # print(lines) # ['<line#1>', '<line#2>', '<line#3>', ...]\n    # lines = plazy.read_txt(path='/home/video-list.txt', strip=False) # no stripping\n```\n\n[:link: Back to Index](#index)\n\n### write_txt\n\nPlazy version: 0.1.4+\n\nWrite text file.\n\n**plazy.write_txt(**\n\n- **path**: path to text file\n- **lines**: lines to write\n- mode: write mode. Default: \"w\"\n- cat_str: concat string between lines. Default: \"\\n\" (new line character)\n\n**)**\n\n``` python\nimport os\nimport plazy\n\nif __name__ == \"__main__\":\n    path = '/home/plazy.txt'\n    lines = [\n        \"hello\",\n        \"world\",\n    ]\n    plazy.write_txt(path=path, lines=lines)\n    assert os.path.isfile(path)\n```\n\n[:link: Back to Index](#index)\n\n### list_files\n\nPlazy version: 0.1.1+\n\nList files recursively in directory.\n\n**plazy.list_files(**\n\n- root: directory to traverse files. Default: \"./\" (current directory)\n- filter_func: filter function to apply. Default: None\n- is_include_root: include root directory path in the result. Default: False\n\n**)**\n\n``` python\nimport plazy\n\nif __name__ == \"__main__\":\n    files = plazy.list_files(root='images',\n                            filter_func=lambda x : True if x.endswith('.jpg') else False,\n                            is_include_root=False)\n    print(files) # ['1.jpg', '2.jpg', '_sub_/4.jpg']\n```\n\n[:link: Back to Index](#index)\n\n# CONTRIBUTING\n\n* Step 1. Fork on **dev** branch.\n* Step 2. Install **pre-commit** on the local dev environment.\n\n```\npip install pre-commit\npre-commit install\n```\n\n* Step 3. Write test case(s) for the new feature or the bug.\n* Step 4. Write code to pass the tests.\n* Step 5. Make sure that the new code passes all the pre-commmit conditions.\n\n```\npre-commit run -a\n```\n\n* Step 6. Create pull request.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Utilities for lazy Python developers",
    "version": "0.1.6",
    "project_urls": {
        "Download": "https://github.com/kyzas/plazy/tarball/master",
        "Homepage": "https://github.com/kyzas/plazy"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a8087a4b2d3f07829590b04680d3db7cdabe921c60d9da426ff38e5a2bb38572",
                "md5": "59d8a5950def8179594ee5b553efb3c2",
                "sha256": "02daf2240d1fde72328286d71f3f4a712f478915f6f35f7c4bff43750c5764a9"
            },
            "downloads": -1,
            "filename": "plazy-0.1.6-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "59d8a5950def8179594ee5b553efb3c2",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": "<4,>=3.5",
            "size": 14257,
            "upload_time": "2023-09-24T19:46:33",
            "upload_time_iso_8601": "2023-09-24T19:46:33.127217Z",
            "url": "https://files.pythonhosted.org/packages/a8/08/7a4b2d3f07829590b04680d3db7cdabe921c60d9da426ff38e5a2bb38572/plazy-0.1.6-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "38ee3d1d2edebadf005937f04d88ec287bdf214ba8a8e9964d5afd4e6d774f44",
                "md5": "930aab9ec5b015a985481a7523d30ba5",
                "sha256": "0a50801bea1b261266519c9264642e582ead734737427474035c1cc6cd9b415c"
            },
            "downloads": -1,
            "filename": "plazy-0.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "930aab9ec5b015a985481a7523d30ba5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.5",
            "size": 15086,
            "upload_time": "2023-09-24T19:46:35",
            "upload_time_iso_8601": "2023-09-24T19:46:35.067462Z",
            "url": "https://files.pythonhosted.org/packages/38/ee/3d1d2edebadf005937f04d88ec287bdf214ba8a8e9964d5afd4e6d774f44/plazy-0.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-24 19:46:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kyzas",
    "github_project": "plazy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "scake",
            "specs": []
        },
        {
            "name": "sphinx",
            "specs": []
        },
        {
            "name": "sphinx_rtd_theme",
            "specs": []
        }
    ],
    "lcname": "plazy"
}
        
Elapsed time: 0.12534s