A collection of utilities for the QUAS ecosystem
Project description
quas-utils
Flask-focused helpers for quick, practical tasks: HTTP responses, retry/timing decorators, timezone-aware datetime utilities, simple logging, and a handful of misc helpers (slugging, random strings, key normalization).
Install
python -m pip install quas-utils
# or for local dev
python -m pip install -e .
What’s inside
- HTTP responses:
success_response,error_responsefor consistent JSON replies. - Decorators:
retryfor flaky DB calls;get_timeto log execution time. - Date/time:
QuasDateTimehelpers andto_gmt1_or_nonefor fixed GMT+1 conversions. - Logging:
console_log,log_exceptionthin wrappers over Flask/logging. - Misc: slug generation, key normalization to
snake_case, random strings/numbers, pagination.
Quickstart (Flask)
from flask import Flask
from quas_utils.api import success_response, error_response
from quas_utils.decorators import retry, get_time
from quas_utils.logging.loggers import console_log
app = Flask(__name__)
@app.route("/health")
def health():
return success_response("ok", 200, {"service": "quas-utils"})
@app.route("/fragile")
@retry(retries=3, delay=1.5)
@get_time
def fragile_work():
console_log("INFO", "doing work…")
# raise on failure; retry will handle
return success_response("done", 200)
@app.errorhandler(Exception)
def on_error(err):
return error_response(str(err), 500)
API cheat sheet
HTTP responses
from quas_utils.api import success_response, error_response
success_response("created", 201, {"id": 1})
error_response("not found", 404)
Decorators
from quas_utils.decorators import retry, get_time
@retry(retries=5, delay=2)
def fetch_from_db():
...
@get_time
def heavy_work():
...
Date/time
from quas_utils.date_time import QuasDateTime, to_gmt1_or_none
now = QuasDateTime.aware_utcnow()
pretty = QuasDateTime.format_date_readable(now)
gmt1 = to_gmt1_or_none(now)
Logging helpers
from quas_utils.logging.loggers import console_log, log_exception
console_log("INFO", "starting job")
try:
risky()
except Exception as exc:
log_exception("risky failed", exc)
Misc helpers
from quas_utils.misc import (
normalize_keys,
generate_random_string,
generate_random_number,
generate_slug,
paginate_results,
)
normalize_keys({"firstName": "Ada", "address": {"zipCode": "12345"}})
generate_random_string(length=12, prefix="user")
generate_random_number(length=6)
# generate_slug expects a SQLAlchemy model with `.query`
Notes
- Target Python: 3.12+
- Depends on Flask;
retryexpects SQLAlchemy installed for DB-related exceptions. - The project uses the
src/layout; imports are alwaysquas_utils.*(nosrcin paths).
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
quas_utils-0.0.6.tar.gz
(10.1 kB
view details)
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 quas_utils-0.0.6.tar.gz.
File metadata
- Download URL: quas_utils-0.0.6.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c8c90211b2fceaa4c216afbe63e1724f4a9491ab72268edd7526eef5d5858a1
|
|
| MD5 |
e1024d439674d6ba8c5118a4ff05c738
|
|
| BLAKE2b-256 |
1a262db3e163a3c5dfc0284ef6f9ce3ce2735653d4a8d8e7a71226986b1b5447
|
File details
Details for the file quas_utils-0.0.6-py3-none-any.whl.
File metadata
- Download URL: quas_utils-0.0.6-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3584593a910a849f2efdb9ced4dbc2a6e15cb2c7c2b108d4449740ea08b1a036
|
|
| MD5 |
333eac131b60c6bf4ac3e633324fa7b2
|
|
| BLAKE2b-256 |
bc54eb9025773828e2bf6a15122d5cca48d409e53c3d9fca2d9e7c3eb95e58ec
|