Skip to main content

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:

  1. Fork the repository.
  2. Create a new branch.
  3. Make changes and commit.
  4. 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

vatsal-1.2.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vatsal-1.2.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file vatsal-1.2.0.tar.gz.

File metadata

  • Download URL: vatsal-1.2.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.1

File hashes

Hashes for vatsal-1.2.0.tar.gz
Algorithm Hash digest
SHA256 dc4bd372fba4d253b3ebd0d7d15b5d4a8ce7dffdc06306840f4a7e6df6902a1e
MD5 1bab143094ecf1f63cf5ef8cdaa10188
BLAKE2b-256 f44e180c91283cbfcb451de11287f247fdbe2b1277f820ad8376e81897becaf7

See more details on using hashes here.

File details

Details for the file vatsal-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: vatsal-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.1

File hashes

Hashes for vatsal-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8a3017ac8a8e2a63917b7b7ac829b9e12dc68efe394e060b1d53ebe2dde17f4
MD5 211c5faae8c550438e4b428ae1c3287c
BLAKE2b-256 3f2788d08ff086c65ce4fe948c4053dd395a1fea8bac09cfb564d56848294594

See more details on using hashes here.

Supported by

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