mooch
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
Seperate package named zettings
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)
Progress Bar
Seperate package named BarNone
A lightweight, eye-friendly, and feature-rich terminal progress bar.
- Clean, minimal visual output
- Smooth gradient color transition (Red → Gold → Green)
- ETA and step tracking
- Fast render speed of ~200ns per iteration
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
gitare not in system'sPATH - 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
fallbackif an exception is caught.
@retry(3)
- Retries the decorated function if an exception is raised.
- Returns the last exception on final retry attempt. Optional
fallbackreturned instead if desired. - Set delay time between tries with
delayargument.
@deprecated
- Emits a DeprecationWarning when the function is called.
- Accepts a custom reason string to explain the deprecation.
- Supports Python 3.9+ (
@deprecatedwas added to Python 3.13)
@timeit
- Logs execution time of a function using the Python
loggingmodule.
@with_lock(threading.Lock or asyncio.Lock)
- Prevents concurrent execution using provided threading.Lock or asyncio.Lock
- Lock object is created if not provided, but doing this only prevents concurrent execution of same function.
Install
pip install mooch
or
uv add mooch
Dependencies
Python 3.9 or greater
Usage
Browse the examples folder for more examples.
Settings
from zettings import Settings
defaults = {}
defaults["settings.mood"] = "happy"
defaults["settings.volume"] = 50
settings = Settings(".mooch/settings.toml", defaults) # Change 'mooch' to your project's name
print("Current Settings:")
print(f"Mood: {settings['settings.mood']}")
print(f"Volume: {settings['settings.volume']}") # prints 50
settings["settings.volume"] = 75
print("Updated Settings:")
print(f"Mood: {settings['settings.mood']}")
print(f"Volume: {settings['settings.volume']}") # prints 75
Progress Bar
from barnone import ColoredProgressBar
pb = ColoredProgressBar(5)
#pb = ProgressBar(total=5)
for _ in range(5):
time.sleep(0.1)
pb.update()
Terminal Output:
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_system, python_version
python_version.check("3.13")
operating_system.check("Windows")
command.check("python", "ls", "echo")
Development
Steps for setting up this project for development in VS Code.
Show Instructions
- Clone the Repository
git clone https://github.com/nickstuer/mooch
- Install
uv(skip if already installed)
curl -Ls https://astral.sh/uv/install.sh | sh
- Install Project Dependencies
uv sync
- Activate Virtual Environment
source .venv/bin/activate # On Windows: .venv/Scripts/activate
- Install pre-commit hooks
pre-commit install
# Verify
pre-commit run --all-files
- Setup Python Interpreter in VS Code
Press CMD + Shift + P # On Windows: 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
Metadata
Release files for mooch 2.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mooch-2.2.0.tar.gz | 72.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mooch-2.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 88.2 kB
Release files / mooch-2.2.0.tar.gz
| Download URL | mooch-2.2.0.tar.gz |
|---|---|
| Size | 72.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4d186681dc2624d9fe20aa923ff9c69546fc38fa2ccd2cf084440d02ddc2e222
|
|
BLAKE2b-256 checksum How to use checksums |
1b2243384c93f9c58e10014688b507f721d053b3bd28aaa47f1d4032dfdc3635
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.20
|
Release files / mooch-2.2.0-py3-none-any.whl
| Download URL | mooch-2.2.0-py3-none-any.whl |
|---|---|
| Size | 15.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84efe8dedb788547710a89c093fc99beacf8be31ce1f0996e70b2d95b68c58e9
|
|
BLAKE2b-256 checksum How to use checksums |
c37e2fae97dc901b46e52200429e520acc08e3eadc1df62de5d6a689797dd373
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.20
|
Security for mooch 2.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.