Skip to content

Instantly share code, notes, and snippets.

View d1vij's full-sized avatar

Divij Verma d1vij

View GitHub Profile
@d1vij
d1vij / SqlQueryWrapper.py
Last active September 28, 2025 18:32
Python wrapper for the SQLite3 Database
import sqlite3
from sqlite3 import OperationalError
from typing import Union, Literal
# typings
REPR_UNION = Union[Literal["string"], Literal["list"], None]
QUERY_UNION = Union[None, list[tuple[str]], str, list[str]]
class SqlQueryWrapper:
@d1vij
d1vij / get_function_from_module.py
Last active September 14, 2025 15:40
Import any function from any module (file)
from importlib.util import spec_from_file_location, module_from_spec
from os import path
def get_function_from_modulepath(function_name: str, module_path:str):
"""Returns a function with provided name object from provided module / python file path"""
if(not path.exists(module_path)):
raise FileNotFoundError(f"No module exists at path ${module_path}")
if(not path.isfile(module_path)):
raise FileNotFoundError(f"Target at path ${module_path} is not a file")