qgoferutils

Utility functions that cut across most qgofer projects

Install

pip install qgoferutils

Or

conda install qgofer::qgoferutils

Available classes in qgoferutils are:

  • Configuration Module
from qgoferutils.config import QGoferConfig, create_config_table
  • Database Module
from qgoferutils.db import QGoferDBWrapper
  • Logger Module
from qgoferutils.logger import get_logger, get_log_path
  • Requests Module
from qgoferutils.requests import make_api_request, get_failed_response
  • Utility Functions Module
from qgoferutils import get_env_var, generate_uuid, init_path

Code Snippets or Examples

pip install qgoferutils
Requirement already satisfied: qgoferutils in c:\users\admi\miniconda3\envs\env4\lib\site-packages (0.0.7)
Requirement already satisfied: orjson in c:\users\admi\miniconda3\envs\env4\lib\site-packages (from qgoferutils) (3.9.10)
Requirement already satisfied: requests in c:\users\admi\miniconda3\envs\env4\lib\site-packages (from qgoferutils) (2.31.0)
Requirement already satisfied: aiofiles in c:\users\admi\miniconda3\envs\env4\lib\site-packages (from qgoferutils) (22.1.0)
Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\admi\miniconda3\envs\env4\lib\site-packages (from requests->qgoferutils) (2.0.4)
Requirement already satisfied: idna<4,>=2.5 in c:\users\admi\miniconda3\envs\env4\lib\site-packages (from requests->qgoferutils) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\admi\miniconda3\envs\env4\lib\site-packages (from requests->qgoferutils) (2.1.0)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\admi\miniconda3\envs\env4\lib\site-packages (from requests->qgoferutils) (2024.2.2)
Note: you may need to restart the kernel to use updated packages.

Example 1: Configuring QGofer

from qgoferutils.config import QGoferConfig, create_config_table

# Create a QGoferConfig instance
config_instance = QGoferConfig()

# Accessing attributes of QGoferConfig
print("Home directory:", config_instance.home)
print("Root directory:", config_instance.root_dir)
2024-03-09 18:57:17,308 - qgofer - INFO - Logging to C:\Users\admi\.qgofer\logs/W87gwqBURyOma4QkPG6L2g_log_24_03_09_18_57_17.log
Home directory: C:\Users\admi
Root directory: C:\Users\admi

Example 2: Interacting with the Database

from qgoferutils.db import QGoferDBWrapper

# Initialize QGoferDBWrapper with a specific database path
db_wrapper = QGoferDBWrapper("C:/data/dbb")

Example 3: Logging in QGofer

from qgoferutils.logger import get_logger, get_log_path

# Get a logger with a specified log path
logger = get_logger("C:/data/db")
logger.debug("Debug message")

# Get the log path
log_path = get_log_path("")
print("Log path:", log_path)
2024-03-09 18:57:17,500 - qgofer - DEBUG - Debug message
Log path: C:\Users\admi\saf-app\qgofertext\nbs

Example 4: Making API Requests

!pip install nest_asyncio
import nest_asyncio
from qgoferutils.requests import make_api_request, get_failed_response

nest_asyncio.apply()

async def main():
    # Make an API request to https://httpbin.org/get asynchronously
    api_url = "https://httpbin.org/get"
    response = await make_api_request(api_url)
    print("API Response:", response)

# Run the event loop
asyncio.run(main())
API Response: <Response [200]>