Skip to main content

qolpy logo

qolpy v0.2.0

Are you tired of making the same module in every project? Not a problem! Qol has your back.

A suite of random but useful functions that are aimed at giving you "piece of cake" level comfortability.

This package is also availabe as:

Some functionality is derived from:

Installation

pip install qolpy

or

pip3 install qolpy

Importing

# full import
import qolpy

# partial imports
from qolpy import random_colour, parse_date, num_parse, abbreviate, to_title_case, to_sentence_case, Logger

Functions

random_colour

Get a random colour; For those scenarios where you couldn't care less!

Returns a string

c = random_colour()
c_rgb = random_colour("rgb")
c_cmyk = random_colour("cmyk")
c_hsv = random_colour("hsv")
c_hsl = random_colour("hsl")

print(c, c_rgb, c_cmyk, c_hsv, c_hsl)
# #f7f7f7, rgb(247,247,247), cmyk(0%,0%,0%,3%), hsv(0,0%,97%), hsl(0,0%,97%)
Params
Parameter Default Setting Required? Definition Options
setting hex No The type of colour you would like returned hex, rgb, cmyk, hsv, hsl

parse_date

Send in date parameters and receive either an object with their metadata, or a parsed date (e.g 2 Sep 2020); American formatting is possible (e.g Sep 2 2020).

Returns a string or Date_Object. You can spread the args and use kwargs such as below:

import datetime

dt = datetime.datetime.now()
date_list = [dt.day, dt.weekday(), dt.month, dt.year]

pd = parse_date(*date_list, c_format="nll", american=True)
pd_full = parse_date(*date_list, c_format="lll")

print(pd, pd_full)
# April 15 2023, Saturday 15th April, 2023
interface
	"day": {
		"short": str,
		"long": str,
		"ordinal_month": str,
		"ordinal_week": str,
		"week_number": int,
		"month_number": int
	},
	"month": {
		"short": str,
		"long": str,
		"ordinal": str,
		"number": int
	},
	"year": {
		"short": int,
		"long": int
	}

Params
Parameter Default Setting Required? Definition Options
monthDay none Yes The day of the month type number
weekDay none Yes The day of the week type number
month none Yes The numeric month type number
year none Yes The full numeric year type number
format none No The date format you would like n = numeric, s = shorthand text, l = full text; nns, nnl, sss, ssl, lll, nss, nsl, nls, nll
american false No Whether or not you would like the format to be 'Americanised' true, false

num_parse

Convert a number into a string as if it's MS Excel!

Returns a string

num = num_parse(2100.45)
num_europe = num_parse(2100.45, "punct")
num_custom = num_parse(2100.45, "-")

print(num, num_europe, num_custom)
# 2,100.45, 2.100,45, 2-100.45)
Params
Parameter Default Setting Required? Definition Options
value undefined Yes The number you want to be parsed none
setting comma No The delimiter for the number space, comma, punct, any other delimiter as a string

abbreviate

name = "lEwiS mOsho junior"

print(abbreviate(name))
# LMJ

Make an abbreviation of a string; Usually used for names. It returns an upper case abbreviation of the string.

Params
Parameter Default Setting Required? Definition
text null Yes The string you wish to abbreviate
delimiter " " No The character or string that seperates words in the string

to_title_case

Make any string title cased. it returns a string in which every first letter of a word is upper cased with the rest being lower cased.

const name = "lEwiS mOsho junior"

print(to_title_case(name))
# Lewis Mosho Junior
Params
Parameter Default Setting Required? Definition
text null Yes The string you wish to change to title case
delimiter " " No The character or string that seperates words in the string

to_sentence_case

Make any string sentence cased; The current sentence delimiters are:

  • .
  • ;
  • :
  • !
  • ?

It returns a string in which every first letter of the first word of a sentence is capitalised, with the remainder of the senter being lower cased.

sentence = "heLLo wOrLD, mY NAME is lEwis; i am a Developer."

print(to_sentence_case(sentence))
# Hello world, my name is lewis; I am a developer.
Params
Parameter Default Setting Required? Definition
txt null Yes The string you wish to change to sentence case
delimiter " " No The character or string that seperates words in the string

Logger

Log code executions, stats, and processing times in any framework in any environment; and chain the logs to see the entire process in the terminal!

Returns None

code example

from qolpy import Logger
from .some_function import some_function
from fastapi import FastAPI, Request

app = FastAPI()
logger = Logger()

@app.middleware("http")
async def handler(req: Request, call_next):
	logger.new_log("log", req.method, req.url.path)

	logger.log("log", "some_function", "Doing something...")
	some_function()
	logger.proc_time()

	response = await call_next(req)

	logger.execTime()
	return response

...

terminal output

[log • aGy5Op]: GET => /hello | 07 Oct 2023 @ 19:40
[log • aGy5Op]: some_function => Doing something... | 07 Oct 2023 @ 19:40
[stats • aGy5Op]: some_function => 53.24ms
[exec • aGy5Op]: 121.07ms
Variables
Variable Default Setting Required? Definition
id_length 5 No An int that determines the length of the log id
american_date False No A bool that determines whether the parseDate output should be american
time_format %d %b %Y @ %H:%M No A str that defines other options for the log time output

These can be set when initialising the Logger or dynamically. NOTE that you can initialise any of them as undefined through the constructor and it will set their default values, however, dynamically they will need a value of their type unless they can be undefined.

# Set the americanDate param through the constructor
logger = Logger(american_date=True)

// set the americanDate param dynamically
logger.american_date = False

Methods
Method Type Details
new_log (config: Union["stats", "log", "error"], process: string, message: string) -> None Create a new log chain; This will change the log id
log (config: Union["stats", "log", "error"], process: string, message: string) -> None Add a log to the log chain; This will not change the log id
proc_time () -> void Log the processing time between this call and the previous call to view their processing time
exec_time () -> void View the entire execution time
lax decorator Useful to measure the process time for a single function (sync or async); not chainable but can have inner processes chained.

Decorator Example

logger = Logger()

@logger.lax
async def api_call() -> str:
    req = requests.get("https://api.site.com/hello")
    logger.log("log", "api_call", "request successfull!")

    res = req.json()
    return res["msg"]

asyncio.run(api_call())
[log • cy1zD]: api_call => Executing without args | 07 Oct 2023 @ 23:52
[log • cy1zD]: api_call => request successfull!| 07 Oct 2023 @ 23:52
[exec • cy1zD]: 107.09ms

If you add args and/or kwargs, it will log them too regardless of their type:

logger = Logger()

@logger.lax
async def api_call(uri: str, log_type: str) -> str:
    req = requests.get(uri)
    logger.log(log_type, "api_call", "request successfull!")

    res = req.json()
    return res["msg"]

asyncio.run(api_call("https://api.site.com/hello", log_type="log"))
[log • cy1zD]: api_call => Executing with arg 'https://api.site.com/hello' and kwarg log_type='log' | 07 Oct 2023 @ 23:52
[log • cy1zD]: api_call => request successfull!| 07 Oct 2023 @ 23:52
[exec • cy1zD]: 107.09ms

Changelog

v0.2.x

v0.2.0
  • Added Logger class

v0.1.x

v0.1.2
  • README updated
    • Repo links updated
  • color dir typing fixed; No more import error
v0.1.1
  • README completed
  • parse_date error fixed
    • Used tp return month object when nll was specifically set as an arg for c_format
  • Moved codebase into src folder
v0.1.0
  • Initial release
  • Excel number formatting, date parsing, random colour generation,string sentence casing, title casing, and abrreviations added and typed

Metadata

Release files for qolpy 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qolpy 0.2.0
File Size Uploaded Provenance Actions
qolpy-0.2.0.tar.gz 16.8 kB Without provenance Details for qolpy-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qolpy 0.2.0
File Interpreter ABI Platform Actions
qolpy-0.2.0-py3-none-any.whl Python 3 none any Details for qolpy-0.2.0-py3-none-any.whl

Total release size: 32.5 kB

Release files / qolpy-0.2.0.tar.gz

Download URL qolpy-0.2.0.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3ab7210914d97163195c03865711281cb1a7b6931114aeeb5ffbd1b6ebf1f53e
BLAKE2b-256 checksum
How to use checksums
5bdc8689dbdcd44d3a9f4ebe4e75dbbf67da48b04e8483a7d946b7a18d11ef65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / qolpy-0.2.0-py3-none-any.whl

Download URL qolpy-0.2.0-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
acf3c0675d9e9deae7b33f26017346782ce489cfc8d9e026b181e5a52206e548
BLAKE2b-256 checksum
How to use checksums
3ccd9f7a90c3888191a4aaa4dea4118e2a858dfb2a29a19ec697809d0862c50f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Security for qolpy 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page