Skip to main content

generic-decorators

Generic Python Decorators for use in any project.

Install

generic-decorators is released to public PyPI - generic-decorators. It can be installed using this command:

pip install generic-decorators

Decorators

make_parallel

Summary: runs function in parallel instead of sequencial for loop.

Example

Parallel trigger of functions sample_function with 1 param list_of_post_ids using make_parallel decorator and equivalent sequential trigger using for loop.

def parallel_function_trigger():
    list_of_post_ids = list(range(1, 20))
    return make_parallel(sample_function)(list_of_post_ids)

#equivalent sequencial version
def serial_function_trigger():
    list_of_post_ids = list(range(1, 20))

    # Serial way of calling the function
    results = []
    for post_id in list_of_post_ids:
        res = sample_function(post_id)
        results.append(res)
    return results

You can use below timing decorator to compare time of above parallel and sequential versions.

make_parallel_processes

Description: Similar functionality like make_parallel but uses mulitprocessing instead of threading.

Example

def parallel_function_trigger():
    list_of_post_ids = list(range(1, 20))
    return make_parallel_processes(sample_function)(list_of_post_ids)

timing

Summary: calculate and print how much time function processing took.

Example

@timing
def sleep_n_seconds(n: int):
    time.sleep(n)

sleep_n_seconds(5)

It should print something like this (time can differ):

func:'sleep_n_seconds' args:[(5,), {}] took: 5.0047 sec

singleton

Summary: make class Singleton - class which will have max 1 instance created

Example

@singleton
class MyClass(object):
    """docstring for MyClass"""
    def __init__(self):
        pass

for i in range(0, 10):
    obj = MyClass()
    print(obj)

It should print something like this (all objects of class are the same):

<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>
<__main__.MyClass object at 0x7fc3bc38fc50>

Release files for generic-decorators 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for generic-decorators 1.0.3
File Size Uploaded
generic-decorators-1.0.3.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for generic-decorators 1.0.3
File Interpreter ABI Platform
generic_decorators-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 kB

Release files / generic-decorators-1.0.3.tar.gz

Download URL generic-decorators-1.0.3.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fb0b9eb7626689b569a427e6bd353672964ebe13d5e6906aff3def452e679e7f
BLAKE2b-256 checksum
How to use checksums
b6c6ae4e428807c70a1b97a25424e141d944a63a398d7ff8ba31901947dfd63e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.0

Release files / generic_decorators-1.0.3-py3-none-any.whl

Download URL generic_decorators-1.0.3-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
37bfe07c5196c500fa40d4b2e26d1eb7bd9fc276e2dd06653a91821a19125444
BLAKE2b-256 checksum
How to use checksums
942f680e3f9f97676f1ab67661c5dc740d2f7ab70621c86f172a73b3e49a6043
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.0

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page