A comprehensive collection of Python utilities and helper functions designed for learning and practical development tasks.
This repository serves as both a learning resource and a practical utility library for Python developers. Whether you're just starting your Python journey or looking for reusable code snippets for common tasks, this library has you covered.
- ποΈ File Operations: Safe file handling, JSON processing, directory management
- π Data Processing: Clean, analyze, and transform data with ease
- π Web Scraping: HTTP requests, HTML parsing, and content extraction
- βοΈ Automation: Task scheduling, system commands, and file monitoring
- π§ Utilities: Password generation, hashing, validation, and more
- π§ͺ Well Tested: Comprehensive test suite with pytest
- π Educational: Clear documentation and learning materials
# Clone the repository
git clone https://github.com/your-username/Python-Helper.git
cd Python-Helper
# Install dependencies
pip install -r requirements.txt
# Run an example
python examples/file_operations_example.py
# Import the helpers you need
from python_helpers.file_ops import ensure_directory, write_json
from python_helpers.utilities import generate_password
from python_helpers.data_processing import clean_data
# Create a directory and save some data
data_dir = ensure_directory("my_project/data")
config = {"api_key": generate_password(32), "version": "1.0"}
write_json(config, data_dir / "config.json")
# Clean messy data
raw_data = [{"name": " John ", "age": "", "score": "85"}]
clean_records = clean_data(raw_data)
print(clean_records) # [{"name": "John", "score": "85"}]
Python-Helper/
βββ π¦ python_helpers/ # Core library modules
β βββ file_ops/ # File & directory operations
β βββ data_processing/ # Data cleaning & analysis
β βββ web_scraping/ # HTTP requests & HTML parsing
β βββ automation/ # Task automation & scheduling
β βββ utilities/ # General-purpose utilities
βββ π scripts/ # Ready-to-use practical scripts
βββ π― examples/ # Usage examples & demonstrations
βββ π learning/ # Tutorials & educational content
βββ π§ͺ tests/ # Comprehensive test suite
βββ π docs/ # Detailed documentation
- Start Here: Run
python examples/file_operations_example.py
- Learn by Example: Explore the
examples/
directory - Practice: Try the tutorials in
learning/tutorials/
- Build Something: Work on projects in
learning/projects/
- Browse the API: Check out
docs/README.md
for full documentation - Use in Projects: Install with
pip install -e .
for development - Extend: Add your own modules and utilities
- Contribute: Submit pull requests with improvements
Module | Purpose | Key Functions |
---|---|---|
file_ops |
File operations | ensure_directory , safe_copy , read_json , write_json |
data_processing |
Data manipulation | clean_data , group_by , calculate_stats , csv_to_dict |
web_scraping |
Web scraping | safe_request , parse_html , extract_links , download_file |
automation |
Task automation | run_command , schedule_task , backup_files , monitor_directory |
utilities |
General utilities | generate_password , hash_string , validate_email , format_bytes |
from python_helpers.file_ops import find_files, get_file_info
# Find all Python files
py_files = find_files(".", "*.py")
# Get detailed file information
for file in py_files:
info = get_file_info(file)
print(f"{info['name']}: {info['size']} bytes")
from python_helpers.data_processing import group_by, calculate_stats
employees = [
{"name": "John", "dept": "Engineering", "salary": 75000},
{"name": "Jane", "dept": "Engineering", "salary": 80000},
{"name": "Bob", "dept": "Marketing", "salary": 65000}
]
# Group by department
dept_groups = group_by(employees, "dept")
# Calculate salary statistics
salaries = [emp["salary"] for emp in employees]
stats = calculate_stats(salaries)
print(f"Average salary: ${stats['mean']:,.2f}")
from python_helpers.web_scraping import safe_request, parse_html, extract_links
# Fetch and parse webpage
response = safe_request("https://example.com")
if response:
soup = parse_html(response.text)
links = extract_links(soup)
print(f"Found {len(links)} links")
from python_helpers.automation import backup_files, cleanup_old_files
# Backup important files
backup_files(["config.json", "data.csv"], "backups/")
# Clean up old log files
cleanup_old_files("logs/", days_old=7, pattern="*.log")
from python_helpers.utilities import generate_password, format_bytes, time_ago
from datetime import datetime, timedelta
# Generate secure password
password = generate_password(16, include_symbols=True)
# Format file sizes
print(format_bytes(1024 * 1024)) # "1.0 MB"
# Human-readable time differences
old_time = datetime.now() - timedelta(hours=2)
print(time_ago(old_time)) # "2 hours ago"
# Run all tests
pytest
# Run with coverage
pytest --cov=python_helpers
# Run specific test categories
pytest -m unit # Unit tests only
pytest -m integration # Integration tests only
We welcome contributions! Here's how you can help:
- Report Issues: Found a bug? Create an issue
- Suggest Features: Have an idea? We'd love to hear it
- Add Utilities: Write new helper functions
- Improve Documentation: Help make things clearer
- Write Tests: Help us maintain quality
# Install in development mode
pip install -e .[dev]
# Install pre-commit hooks (optional)
pre-commit install
# Run tests before committing
pytest
This library is perfect for:
- Learning Python: Understand practical coding patterns
- Rapid Prototyping: Get common tasks done quickly
- Automation Scripts: Build reliable automation tools
- Data Processing: Handle CSV files and data cleaning
- File Management: Organize and process files safely
- Web Scraping Projects: Extract data from websites
- System Administration: Automate system tasks
For detailed documentation, examples, and tutorials:
- API Reference: See
docs/README.md
- Examples: Browse the
examples/
directory - Tutorials: Check
learning/tutorials/
- Projects: Try
learning/projects/
This project is licensed under the MIT License - see the LICENSE file for details.
If you find this library helpful, please give it a star! It helps others discover the project and motivates continued development.
Happy Coding! π
Built with β€οΈ for the Python community
python samples