A small package of reusable Python utilities for Python projects.
- Dependency Management: Smart detection of optional dependencies (rich, tqdm)
- Logging: Simplified logging setup with optional Rich support
- Progress Bars: Unified progress bar API with multiple backends
- Decorators: Robust decorators for timing (
@timed) and error handling (@safe) - Type Safe: Comprehensive type hints and PEP 561 compliance
pip install pedrosOR
uv add pedrosOptional features:
pip install "pedros[rich]" # Rich logging/progress backend
pip install "pedros[all]" # all optional backendsfrom pedros import setup_logging, get_logger, progbar, timed, safe
# Configure logging for pedros
setup_logging()
logger = get_logger()
# Or configure another package logger without touching root logging
setup_logging(logger_name="my_package")
logger = get_logger("my_package")
# Use progress bar (auto-selects backend: rich > tqdm > basic)
for item in progbar(range(10), desc="Processing"):
pass
# Time function execution
@timed(logger="my_package")
def process_data():
return "result"
process_data() # Logs: "process_data took 1.23 ms to execute."
# Safely handle errors
@safe(re_raise=False, logger="my_package")
def risky_operation():
raise ValueError("Something went wrong")
risky_operation() # Logs the error but doesn't crashThis project is licensed under the MIT License.
Contributions are welcome! Please open issues or pull requests on GitHub. Before submitting contributions via pull requests, make sure the pre-commit hooks are installed. Run them manually with:
uv run pre-commit run --all-filesFor questions or support, please open a GitHub issue.