A collection of pre-made Python utilities for everyday tasks. This package provides ready-to-use classes for data handling, database operations, file I/O, and HTTP requests — helping you build projects faster and more effectively.
- DataHandler: Timestamp formatting, data normalization, and common data manipulation utilities
- DbHandler: Full-featured SQLite database management with CRUD operations, table schema modifications, and index management
- FileHandler: Comprehensive file operations including read/write, CSV/Excel/PDF handling, and file system utilities
- Requester: Simplified HTTP request handling with common patterns and utilities
pip install custom_functions# Clone the repository
git clone https://github.com/coderooz/My_simple_functions.git
cd My_simple_functions
# Install in development mode
pip install -e .
# Or install with development dependencies
pip install -e ".[dev]"- Python 3.12 or higher
- Dependencies (installed automatically):
pytz>=2023.3.0requests>=2.31.0db-sqlite3>=0.0.1pandas>=2.1.3mysql-connector-python>=2.2.9openpyxl>=3.1.2PyPDF2>=3.0.0
# Import the handlers
from DataHandlers import DataHandler
from DbHandler import DbHandler
from FileHandler import FileHandler
from Requester import Requester
# Use DataHandler for timestamp formatting
timestamp = DataHandler.timestamp()
print(timestamp) # Output: 2024-01-15 10:30:45
# Use DbHandler for database operations
db = DbHandler('my_database.db')
db.createTb('users', ['name TEXT', 'email TEXT'])
db.insert('users', ['John Doe', 'john@example.com'])
# Use FileHandler for file operations
FileHandler.write('output.txt', 'Hello, World!')
content = FileHandler.read('output.txt')
# Use Requester for HTTP requests
# requester = Requester()
# response = requester.get('https://api.example.com/data')The DataHandler class provides utilities for common data manipulation tasks.
Returns the date and time in the specified format.
Parameters:
given_time: Optional datetime object or timestamp (default: current time)format: strftime format string (default:"%Y-%m-%d %H:%M:%S")time_zone: Optional timezone string (e.g.,"Asia/Kolkata")normalize: Normalization level —'sec','min', or'hour'(default:'sec')
Returns: str — Formatted timestamp string
Example:
from DataHandlers import DataHandler
# Current timestamp
print(DataHandler.timestamp())
# Output: 2024-01-15 10:30:45
# Custom format
print(DataHandler.timestamp(format="%Y-%m-%d"))
# Output: 2024-01-15
# With timezone
print(DataHandler.timestamp(time_zone="US/Pacific"))
# Output: 2024-01-14 21:00:45The DbHandler class provides a comprehensive interface for SQLite database operations.
from DbHandler import DbHandler
# Creates new database or connects to existing one
db = DbHandler('my_database.db')Creates a new table with optional data insertion.
Parameters:
table_name: Name of the tablecolumns: List of column definitions (e.g.,['col1 TEXT', 'col2 INT'])insertData: Optional data to insert immediately after creationaddId: Whether to add an auto-incrementing primary key (default:False)idKey: Name of the primary key column (default:'id')
Example:
# Create table with columns
db.createTb('users', ['name TEXT', 'email TEXT', 'age INT'])
# Create with auto ID and initial data
db.createTb('users', ['name TEXT', 'email TEXT'],
insertData=['John', 'john@example.com'],
addId=True)Inserts a row into the specified table.
Example:
db.insert('users', ['Alice', 'alice@example.com', 25])Fetches data from a table with optional filtering.
Example:
# Fetch all rows
all_users = db.fetch('users')
# Fetch specific columns with condition
result = db.fetch('users', columns='name, email', query="age > 18")Counts rows in a table, optionally with a filter.
Example:
total = db.getCount('users')
adults = db.getCount('users', query="age >= 18")Updates rows matching the query.
Example:
db.update('users', {'age': 26}, query="name='Alice'")Executes raw SQL queries.
Example:
db.execute("DROP TABLE IF EXISTS temp_table")| Method | Description |
|---|---|
delTb(table_name) |
Delete a table |
renameTb(old_name, new_name) |
Rename a table |
getTb() |
List all tables |
getTbData(table_name) |
Get all data from a table |
alterTb(table_name, operation) |
Alter table structure |
getColumnNames(table_name) |
Get column names |
get_table_info(table_name) |
Get detailed table info |
modifyColumns(table_name, columns) |
Modify column definitions |
checkIndex(table_name, index_name) |
Check if index exists |
getIndexes(table_name) |
Get all indexes |
addIndex(table_name, columns, unique=False) |
Add an index |
delIndex(index_name) |
Delete an index |
cleanTb(table_name) |
Delete all rows from a table |
addColumn(table_name, column_def) |
Add a new column |
renameColumn(table_name, old_name, new_name) |
Rename a column |
removeColumn(table_name, column_name) |
Remove a column |
close_connection() |
Close database connection |
The FileHandler class provides utilities for file system operations and file format handling.
from FileHandler import FileHandler
# Static class — no initialization needed
# Use directly: FileHandler.method_name()Gets list of files and/or folders in a directory.
Parameters:
file_path: Path to the directorycatg: Category filter —0for both,1for files only,2for directories only
Returns: list of file/directory names
Example:
# Get both files and folders
items = FileHandler.getFiles('./my_folder')
# Get only files
files = FileHandler.getFiles('./my_folder', catg=1)
# Get only directories
dirs = FileHandler.getFiles('./my_folder', catg=2)Extracts just the filename from a path.
Gets the file category/type based on extension.
Splits filename into name and extension.
Gets the file extension.
Reads and returns file contents.
Appends data to a file.
Parameters:
file_name: Path to the filedata: Content to writeseparator: Optional separator to append after data
Example:
FileHandler.write('output.txt', 'Hello, World!', separator='\n')Overwrites file contents with new data.
Reads a CSV file and returns a pandas DataFrame.
Writes data to a CSV file.
Reads an Excel file and returns a pandas DataFrame.
Writes data to an Excel file.
Extracts and returns text content from a PDF file.
Example:
text = FileHandler.read_pdf('document.pdf')
print(text)The Requester class provides simplified HTTP request handling.
from Requester import Requester
# Initialize
requester = Requester()
# GET request
response = requester.get('https://api.example.com/data')
# POST request
response = requester.post('https://api.example.com/data', json={'key': 'value'})
# With custom headers
response = requester.get('https://api.example.com/data',
headers={'Authorization': 'Bearer token'})custom_functions/
├── DataHandlers.py # Data manipulation utilities
├── DbHandler.py # SQLite database operations
├── FileHandler.py # File I/O and format handling
├── Requester.py # HTTP request utilities
├── __init__.py # Package initialization
├── setup.py # Package distribution setup
├── pyproject.toml # Modern Python project configuration
├── LICENSE.txt # MIT License
├── README.md # This file
├── CHANGELOG.md # Version history
├── CONTRIBUTING.md # Contribution guidelines
├── CODE_OF_CONDUCT.md # Community guidelines
├── SECURITY.md # Security policy
├── .gitignore # Git ignore rules
├── .editorconfig # Editor configuration
└── .github/ # GitHub-specific files
├── ISSUE_TEMPLATE/ # Issue templates
├── workflows/ # CI/CD workflows
├── CODEOWNERS # Code ownership
├── dependabot.yml # Dependency updates
├── labels.yml # Issue labels
├── PULL_REQUEST_TEMPLATE.md
└── FUNDING.yml # Sponsorship information
# Clone and set up virtual environment
git clone https://github.com/coderooz/My_simple_functions.git
cd My_simple_functions
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install with dev dependencies
pip install -e ".[dev]"# Run all tests
pytest
# Run with coverage
pytest --cov=custom_functions --cov-report=html
# Run specific test file
pytest tests/test_datahandler.py -v# Format code
black .
# Sort imports
isort .
# Lint
flake8 .
# Run all checks
black . && isort . && flake8 .We welcome contributions of all kinds! Please read our Contributing Guide for details on:
- How to set up your development environment
- Our coding standards and conventions
- How to submit pull requests
- How to report bugs or request features
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and linting
- Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please read our Code of Conduct before contributing.
We use Semantic Versioning (SemVer) for versioning. See the CHANGELOG.md for a list of available versions and the changes in each release.
This project is licensed under the MIT License — see the LICENSE.txt file for details.
Ranit Saha (Coderooz)
- GitHub: @Coderooz
- Website: https://coderooz.in
- Email: contact@coderooz.in
- Contact: https://coderooz.in/contact
- Thanks to all contributors who help improve this project
- Built with the goal of reducing repetitive coding tasks
If you find this project helpful, consider supporting:
Made with ❤️ by CodeRooz