Skip to main content

NOFUS: Nate's One-File Utilities Stash

About NOFUS

A collection of single purpose classes for common tasks, focusing on simple and straightforward use. Each class can be taken and used individually and requires no external dependencies.

Uses

ConfigFile: No Hassle Config File Parser

Example Config:

[email]
admin    = admin@example.com
reply_to = feedback@example.com

[auth.sql]
host = sql.example.com
db   = mydbname
user = sqluser
pw   = "secret_passwd"

[auth.ldap]
uri = "ldap://ldap1.example.com:389"
uri = "ldap://ldap2.example.com:389"
uri = "ldap://ldap3.example.com:389"

Example Use:

from nofus import ConfigFile

conf = ConfigFile("/path/to/my.conf")
if not conf.load():
    print(conf.errors())
else:
    admin_email = conf.get("email.admin")
    reply_email = conf.get("email.reply_to", default="donotreply@example.com")

    sqlauth     = conf.get("auth.sql")
    sql_host    = sqlauth.get("host")
    sql_db      = sqlauth.get("db")
    sql_user    = sqlauth.get("user")
    sql_pw      = sqlauth.get("pw")

    ldap_uris   = conf.get_list("auth.ldap.uri")

Logger: Simplified Alternate Logging Interface

Example Use:

from nofus import Logger

# Fast setup, default to logging LOG_DEBUG and higher
Logger.initialize('/tmp/myfile.log')
Logger.info("Info!")
Logger.notice("Notice!")
Logger.warning("Warning!")
Logger.error("Error!")
Logger.critical("Critical!")

# Easily put an exception stack trace into the log
try:
    1/0
except ZeroDivisionError as exc:
    Logger.info("Caught something.", exc_info=exc)

# Disable logging
Logger.disable()

# Set custom log level
Logger.initialize('/tmp/myfile.log', Logger.LOG_TRACE)
Logger.trace("Trace!")

# Check log level
if Logger.is_enabled(Logger.LOG_DEBUG):
    Logger.debug("Yep, we're debugging.")

# Or Define a custom logger
from nofus import LoggingInterface
class CustomLogger(LoggingInterface):
    def __init__(self, log_file=None, log_level=None):
        if log_level is None:
            log_level = Logger.LOG_LOW
        # Customize your init

    def make_log(self, entry, log_level):
        # Customize your log actions

Logger.register(CustomLogger())

DBConnect: Quick interface for making MariaDB queries

Example Use:

from nofus import DBConnect

conn = [
    {"host": "127.0.0.1", "port": 3306, "database": "myapp", "username": "appuser", "password": "secret"}
]

db = DBConnect(conn)

# Simple query, rows being a list of dict with keys being table column names
rows = db.query("SELECT * FROM users WHERE username = ?", ["soandso"])

# Simple query, getting just first row. Returns None if no rows found
row = db.query_row("SELECT * FROM users WHERE username = ?", ["soandso"])

# Get a column of values as a list
list_user_ids = db.query_column("SELECT id FROM users")

# Print what a query might look like with values inserted, but doesn't run query
query_string = db.query_return("SELECT * FROM users WHERE username = ?", ["soandso"])

# For large queries, retrieve rows one at a time instead of all at once
db.query_loop("SELECT * FROM very_large_table")
while row := db.query_next():
    print(row)

# Safe handling of table and column names; returns empty string if invalid
safe_table_name = db.escape_identifer(table_name)
safe_column_name = db.escape_identifer(column_name)
if safe_table_name and safe_column_name:
    db.query(f"SELECT {safe_column_name} FROM {safe_table_name}")

# Return last insert id for single record inserts
new_user_id = db.query("INSERT INTO users SET username = ?", ['soando'])

# Returns row count for update, insert, delete, and multi-insert queries
rows_changed = db.query("UPDATE users SET last_updated = NOW()")

# Transactions
db.transaction_start()  # Default REPEATABLE READ, pass True for READ COMMITTED.
db.is_transaction_started()
db.transaction_commit()
db.transaction_rollback()

Installation

If all you need is one class, you can just grab a file and throw it in your project.

Or you can install the whole stack using pip:

pip install nofus

License

NOFUS is covered by the Simplified BSD License.

Metadata

Release files for nofus 0.2.1

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

Source distribution (sdist)

Source distribution for nofus 0.2.1
File Size Uploaded Provenance Actions
nofus-0.2.1.tar.gz 21.5 kB Without provenance Details for nofus-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 42.8 kB

Release files / nofus-0.2.1.tar.gz

Download URL nofus-0.2.1.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d8b5e359e2e8780d57c80e4c7ae1ce92796ee02b005eb7ec920e21a8a412a749
BLAKE2b-256 checksum
How to use checksums
c5278c4b4b46a975b5fb69a3df831cb1608c0229189f765598a991beba2de3b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / nofus-0.2.1-py3-none-any.whl

Download URL nofus-0.2.1-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16416e206751935a6b2bb00258b7afc7a7c93c09c501abb6de30ade767afd1b3
BLAKE2b-256 checksum
How to use checksums
9497f1d043a748c0f5141c860af116243bb0fd04556ef46293cc7885e7c857e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for nofus 0.2.1

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