Skip to main content

Lightweight Python utility library designed to streamline common development tasks needed for every python project.

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 dictionary operations.
  • Nested access: Supports nested keys with dotted key notation.
  • Optional defaults: Provide default values for initializing the settings file or for when a key is missing in the settings file.
  • Optional always_reload: Reload the setting file everytime a key is read. (Enabled by default)

Location

Uses the https://api.zippopotam.us API to retrieve location information from a zip code or a city and state. U.S. only for now.

  • Input options:
    • zipcode (int)
    • city (str)
    • state (star)
  • Retrieves:
    • ZIP Code
    • City
    • State
    • Latitude & Longitude

Validators

  • Raise a RuntimeError if the current python version is not compatible with your project.
  • Raise a RuntimeError if the current operating system is not compatible with your project.
  • Raise a RuntimeError if system commands like git are not in system's PATH
  • Raise a RuntimeError if a list of environmental variables are not set.

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.

@deprecated

  • Emits a DeprecationWarning when the function is called.
  • Accepts a custom reason string to explain the deprecation.
  • Supports Python 3.9+ (@deprecated was added to Python 3.13)

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['settings.mood']}")
print(f"Volume: {settings['settings.volume']}")

settings["settings.volume"] = 75

print("Updated Settings:")
print(f"Mood: {settings['settings.mood']}")
print(f"Volume: {settings['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(zipcode=62704)

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

Validators

Raise an RuntimeError if the requirement isn't satisified.

from mooch.validators import command, operating_sytem, python_version

python_version.check("3.13")
operating_system.check(["Windows"])
command.check(["python", "ls", "echo"])

Development

Steps for setting up this project in VS Code.

  1. Clone the Repository
git clone https://github.com/nickstuer/mooch
  1. Install uv (skip if already installed)
curl -Ls https://astral.sh/uv/install.sh | sh
  1. Install Project Dependencies
uv sync
  1. Activate Virtual Environment
source .venv/bin/activate  # On Windows: .venv/Scripts/activate
  1. Install pre-commit hooks
pre-commit install
  1. Setup Python Interpreter in VS Code (On Windows)
Press CTRL + Shift + P
Select `Python: Select Interpreter'
Choose `.\.venv\Scripts\python.exe`

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.2.0.tar.gz (48.4 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.2.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mooch-1.2.0.tar.gz
Algorithm Hash digest
SHA256 88c7c9214554644f205683030a1da3a68c6d3985e46938568d69b56e0b21dec6
MD5 86e6287eb0bb7cb490acb38b46b46bfa
BLAKE2b-256 bbb41737547f93c686f65911ce4dbe11b9c4e3b5265bb0446c82217b9e376951

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for mooch-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd8601749d23de25b8d65128296c6bb7416484f925478ca51f15e2a23c6c9c8c
MD5 161ddfee16d36e2dbf5fd05c4227d2c4
BLAKE2b-256 f39c6ae914a43b695310182dbea5cf81e9fdbfa384b7d5c06723e257cb787406

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