The python package which eases your <codeflow> using decorators
Project description
utile
The python package which eases your <codeflow>
using @decorators
.
Now integrated with rust!
Installation
Install with:
pip install utile
For Google Colab:
!pip install utile
The art of using decorators
Decorators is one of the many concepts which makes Python programming amazing. The key usage
of decorators is to modify the functionality or state (behavior) of a function. This package brings out a relatively
new concept of
Function Foundation.
Function Foundation is a style of programming where a function tends to do nothing and acts like a robust base (or
foundation) for decorators and these decorators can be made to do sophisticated processes over the idle function.
This (according to us) eases intricate function designing.
Getting Started
@timer() decorator
To compute execution time of a function:
from utile.Timer import timer
import time
@timer()
def foo():
time.sleep(1)
foo()
This will show the execution time (in seconds) irrespective of any print statements.
Key features of utile
@threader() decorator
Provides an easy way to run multiple I/O bound tasks with no hassle of thread pools. Everything is done for you!
import requests
from utile.Threader import threader
def get_requester(endpoint):
return requests.get(f"https://localhost:5000/api/{endpoint}").text # sample GET request
@threader({get_requester: [["user/1"], ["user/1/followers"]]})
def foo(): pass
foo()
The @threader()
decorator takes in a frame-determined structure of all your functions along with its arguments
and returns the list of all the return values of the tasks.
@processor decorator
Provides an easy way to run multiple CPU bound tasks with no hassle of Process pools.
Again, Everything is done for you!
from utile.Processor import processor
def power(a, b):
return pow(a, b) # a sample method for computational task
if __name__ == "__main__": # important to ensure this.
@processor({power: [[123, 321] for _ in range(10000)]})
def foo(): pass
print(foo())
The @processor()
decorator takes in a frame-determined structure of all your functions along with its arguments
and returns the list of all the return values of the tasks.
It's that simple! We take care of all your Pooling processes and you do your work!
For more information, see Documentation.
Contribution
We encourage anyone who comes up with new ideas using decorators
to contribute and collaborate (do star the repo if you like it !).
Project details
Release history Release notifications | RSS feed
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 utile-1.1.tar.gz
.
File metadata
- Download URL: utile-1.1.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 601b0ad11b9248bc4c301b7fa738f988078e20142bb68439cf5cbc0bc283bec9 |
|
MD5 | e5fe10b5f2afbec546f2b38529747efa |
|
BLAKE2b-256 | cfd0a56d99a91f45923403ecfcf5f5420e05dcc649bc9665837e070b7e7a2135 |
File details
Details for the file utile-1.1-py3-none-any.whl
.
File metadata
- Download URL: utile-1.1-py3-none-any.whl
- Upload date:
- Size: 439.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5fae2034ec9837459bf99ab4e35ca98451fd9855b56107ec63ae185aad1848d |
|
MD5 | 3a66c41f1bb623fa0d238aafc8627c79 |
|
BLAKE2b-256 | 9068b7fadb6767929c98a6aa7cbf4a2d27270ede42b7ecc93dd4fb9b530692e0 |