Custom utility functions to reuse efficiently.
Project description
Utility Functions Repository
Overview
- A collection of optimized reusable utility functions for various tasks.
- View author details at the bottom.
Installation
To install the utility functions, run:
pip install git+https://github.com/vatsal1306/vatsal.git
or, you can directly install from pip.
pip install vatsal
Usage
Path operations
Import utils.Path class and use its methods for file operations.
from vatsal.utils import Path
# Validates path. If valid path, returns path in string, else returns FileNotFoundError.
obj = Path('/valid/path')
print(obj)
# Read file content. Optional mode and encoding params.
content = Path.read('/valid/path')
# Write to file. Optional mode and encoding params.
Path.write('/valid/path', "Hello world!")
# Append to file
Path.append('/valid/path', "Append text.")
# Get a list of all custom methods for Path .
obj.__dir__()
Wrappers
Use Wrappers class for using decorators.
from vatsal.utils import Wrappers
# Make any class method as a private method. Use private_method this as decorator, then that method can only be called internally by class. It cannot be used outside the class or by class object.
class DemoClass:
@Wrappers.private_method
def func(self):
print("This is a private method.")
# Make any class as a singleton class. Singleton class is only initialized once. Wrapping @singleton on a class will make sure the class __init__ is only called once. On initialzing the class again, it will return the previously initialized object.
@Wrappers.singleton
class DemoClass:
def __init__(self):
print("Inside init method.")
obj1 = DemoClass() # This will print 'Inside init method.'
obj2 = DemoClass() # This will not print anything because DemoClass is already initialized once.
Config
Use Config class to read .ini file. It will read all the sections and return a variable with .ini data in key-value pairs (dictionary).
from vatsal.utils import Config
config = Config('/path/to/config.ini')
print(config['key']) # prints value for key.
Progress tracking
Use the ProgressPercentage class for real time file upload data in bytes.
from vatsal.utils import ProgressPercentage
import boto3
# Initialize a ProgressPercentage object
progress = ProgressPercentage('file.txt')
# Upload file to S3 with progress tracking
s3 = boto3.client('s3')
s3.upload_file('file.txt', 'bucket-name', 'object-name', Callback=progress)
Contributing
Contributions are welcome. To contribute:
- Fork the repository.
- Create a new branch.
- Make changes and commit.
- Submit a pull request.
Authors
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vatsal-1.1.0.tar.gz.
File metadata
- Download URL: vatsal-1.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a30a0f42491c7cb6de29a4bdb5888bb1b2ae4db47b87436308c3f4ca6c60fc6
|
|
| MD5 |
975deb2f4a6b6adde320282ad02c178b
|
|
| BLAKE2b-256 |
7139be570185b8ce96630a3a6a5e7b26b739daf5960e7093e9cf4b1ac3554092
|
File details
Details for the file vatsal-1.1.0-py3-none-any.whl.
File metadata
- Download URL: vatsal-1.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb977de9a6d2c61af083be5442aa8c646b836329fa699b2650196732fe1ef23a
|
|
| MD5 |
6aefe4fc122eb17a6f71ed4dd630249f
|
|
| BLAKE2b-256 |
0a8b2d01ec653eec0e62195fb2f4d55e622f50efe5875961e01b5913efc3321f
|