Skip to main content

A collection of common python utilities.

Project description

mooch

PyPI Python Versions PyPI - Downloads GitHub issues

Lines Of Code Codecov GitHub Actions Workflow Status

standard-readme compliant license

mooch is a lightweight Python utility library designed to streamline common development tasks needed for every python project — file handling, path operations, logging decorators, and more — all in one convenient minimum package.

Table of Contents

✨ Features

Settings

mooch.settings is a seperate Python packaged included in mooch. It is lightweight, TOML-backed configuration/settings utility that that exposes project settings as standard Python dictionaries — allowing you to work with settings in a familiar, Pythonic way.

  • TOML-powered: Uses toml under the hood for modern, human-friendly settings files.
  • Dictionary-like interface: Access and manipulate settings with regular dict operations.
  • Nested access: Supports nested structures and dotted key notation.
  • Safe defaults: Easily provide fallback values or defaults when keys are missing from the setting file.
  • Optional always reload: Reloads setting file everytime a key is read. (Enabled by default)

Location

Provide a zip code to get city, state and lat, lon.

Require

Raise an exception if the installed python version is not compatible with a script. Raise an exception if the desired operating system is not compatible with a script.

Logging Decorators

@log_entry_exit

  • Logs the entry and exit of the function, including the arguments.
  • Useful for debugging and tracing.

Function Decorators

@silent(fallback="fallback value")

  • Suppresses exceptions raised within the decorated function.
  • Returns fallback if an exception is caught.

@retry(3)

  • Retries the decorated function if an exception is raised.
  • Returns the last exception on final retry attempt. Optional fallback returned instead if desired.
  • Set delay time between tries with delay argument.

🛠 Install

pip install mooch

or

uv add mooch

📌 Dependencies

Python 3.9 or greater

💡 Usage

Browse the examples folder for more examples.

Settings

from mooch.settings import Settings

defaults = {}
defaults["settings.mood"] = "happy"
defaults["settings.volume"] = 50

settings = Settings("mooch", defaults)  # Change 'mooch' to your project's name

print("Current Settings:")
print(f"Mood: {settings.get('settings.mood')}")
print(f"Volume: {settings.get('settings.volume')}")

settings["settings.volume"] = 75

print("Updated Settings:")
print(f"Mood: {settings.get('settings.mood')}")
print(f"Volume: {settings.get('settings.volume')}")

Logging Decorator

from mooch.decorators import log_entry_exit

@log_entry_exit
def random_function(arg1, arg2):
    print(arg1)
    print(arg2)

Log File Output:

DEBUG:__main__:Entering: random_function with args=('Hello', 'World'), kwargs={}
DEBUG:__main__:Exiting: random_function

Retry Decorator

from mooch.decorators import retry

@retry(3)
def get_age(name="random_person"):
    age = ...some other task...
    return age

Location

from mooch import Location
location = Location(62704).load()

print(location.city)                # "Springfield"
print(location.state)               # "Illinois"
print(location.state_abbreviation)  # "IL"
print(location.latitude)            # "39.7725"
print(location.longitude)           # "-89.6889"

Require

Raise an Exception if the requirement isn't satisified.

from mooch import Require

Require.python_version("3.13")
Require.operating_system("Windows")

🏆 Contributing

PRs accepted.

If editing the Readme, please conform to the standard-readme specification.

Bug Reports and Feature Requests

Please use the issue tracker to report any bugs or request new features.

Contributors

📃 License

MIT © Nick Stuer

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

mooch-1.1.0.tar.gz (44.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mooch-1.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file mooch-1.1.0.tar.gz.

File metadata

  • Download URL: mooch-1.1.0.tar.gz
  • Upload date:
  • Size: 44.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for mooch-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d0fee0229c7717f4b8b72609ce7fc6df5b96e5ebdce3135a9f88ab327bbf43bb
MD5 03e36af78a4b00397e8b1a52fd73f642
BLAKE2b-256 308040d284648d89b2a90581b7bd74d7578d7394a61a8bdeb28d63f43248b546

See more details on using hashes here.

File details

Details for the file mooch-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: mooch-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for mooch-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a8db98a6d5cdf243a267f62ea9f8acca4e31aa2e6f23556b4f2609bb8415fcc
MD5 f813fa6a350bde020fa67fc0045cfa81
BLAKE2b-256 ccd368b9e3962f81a22fae145b1936914b068e1e17863f452879c7f3b47013c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page