A well-organized collection of miscellaneous Python utilities, helper functions, and standalone scripts that don't warrant their own dedicated projects. This repository serves as a centralized location for reusable code snippets and tools.
This project provides:
- Utility modules - Reusable functions for common tasks
- Example scripts - Standalone scripts demonstrating utility usage
- Organized structure - Clean separation of concerns
- Well-tested code - Unit tests for all utilities
- Easy to extend - Simple guidelines for adding new utilities
python-misc-utilities/
├── utils/ # Main utility package
│ ├── __init__.py
│ ├── file_operations.py # File and directory utilities
│ ├── string_helpers.py # String manipulation functions
│ └── date_time_utils.py # Date and time utilities
├── scripts/ # Standalone scripts
│ ├── example_file_processor.py
│ ├── example_string_processor.py
│ └── example_datetime_processor.py
├── tests/ # Unit tests
│ ├── test_file_operations.py
│ ├── test_string_helpers.py
│ └── test_date_time_utils.py
├── examples/ # Usage examples
├── docs/ # Additional documentation
├── pyproject.toml # Project configuration
├── requirements.txt # Runtime dependencies
└── requirements-dev.txt # Development dependencies
- Clone the repository:
git clone https://github.com/aaronnmajor/python-misc-utilities.git
cd python-misc-utilities- Install dependencies (optional):
pip install -r requirements.txt- Install development dependencies (for testing and linting):
pip install -r requirements-dev.txtfrom utils.string_helpers import to_snake_case, is_valid_email
from utils.file_operations import list_files_by_extension
from utils.date_time_utils import get_current_timestamp
# Convert strings
snake = to_snake_case("HelloWorld") # Returns: "hello_world"
# Validate email
is_valid = is_valid_email("test@example.com") # Returns: True
# List files
py_files = list_files_by_extension("/path/to/dir", ".py")
# Get timestamp
timestamp = get_current_timestamp() # Returns: "2024-01-15 10:30:45"python scripts/example_file_processor.py
python scripts/example_string_processor.py
python scripts/example_datetime_processor.pyRun all tests:
pytestRun tests with coverage:
pytest --cov=utils --cov-report=term-missingRun specific test file:
pytest tests/test_string_helpers.pyensure_directory_exists()- Create directories safelylist_files_by_extension()- Find files by extensionget_file_size_mb()- Get file size in MBcopy_files_by_pattern()- Copy files matching patternread_file_lines()- Read file lines into listwrite_file_lines()- Write list of lines to file
to_snake_case()- Convert to snake_caseto_camel_case()- Convert to camelCaseto_pascal_case()- Convert to PascalCasetruncate_string()- Truncate with suffixremove_extra_whitespace()- Normalize whitespaceextract_numbers()- Extract numbers from textcount_words()- Count words in stringis_valid_email()- Validate email formatreverse_words()- Reverse word orderremove_punctuation()- Strip punctuation
format_datetime()- Format datetime to stringparse_datetime()- Parse string to datetimeget_current_timestamp()- Get current timestampget_date_n_days_ago()- Calculate past datesget_date_n_days_ahead()- Calculate future datesdays_between_dates()- Calculate day differenceis_weekend()- Check if date is weekendget_day_name()- Get day nameget_month_name()- Get month nameget_quarter()- Get quarter of year
See CONTRIBUTING.md for guidelines on adding new utilities and scripts.
MIT License - feel free to use this code in your own projects!
See docs/RECOMMENDATIONS.md for best practices and suggestions for organizing your utilities.
- ✅ Clean, organized structure
- ✅ Well-documented code
- ✅ Comprehensive unit tests
- ✅ Type hints for better IDE support
- ✅ Easy to extend and customize
- ✅ No external dependencies (core utilities)
- ✅ Python 3.8+ compatible
For questions, issues, or suggestions, please open an issue on GitHub.