core-mixins#
This project provides a foundational set of common functions, decorators, and mixin classes designed to serve as a reusable base for other projects or libraries…
Documentation Contents#
Features#
This library provides the following modules and utilities:
- Compatibility
Self- Type hint for self-referential classesStrEnum- String enumeration compatibility across Python versions
- Decorators (
core_mixins.decorators) cache- Memoization decorator for function resultscount_calls/CountCalls- Track function call countsrepeat- Execute functions multiple timesretry- Automatic retry with configurable backoffsingleton- Enforce single instance patternSyncWrapper- Convert async functions to synchronoustimer- Measure function execution time
- File Utilities (
core_mixins.files) records_from_csv/records_to_csv- CSV file handlingrecords_from_buffer/records_to_buffer- In-memory CSV operations
- Interfaces (
core_mixins.interfaces) IFactory- Factory pattern interfaceITask- Task interface with status trackingTaskStatus- Task state enumerationTaskException- Task-specific exceptions
- Managers (
core_mixins.managers) TasksManager- Manage and execute multiple tasksTaskResult- Task execution result container
- Logging (
core_mixins.logger) get_logger- Standardized logger configuration
- Utilities (
core_mixins.utils) random_string- Generate random stringsget_batches- Batch list processingremove_attributes/rename_attributes/add_attributes- Dictionary manipulationconvert_data_type- Type conversion utilitiesto_snake_case- Convert strings to snake_caseflatten_json- Flatten nested JSON structuresto_one_line- Convert multiline strings to single linebytes_to_str- Convert bytes to string
- Exceptions (
core_mixins.exceptions) get_exception_data- Extract structured exception information
- CLI Utilities (
core_mixins.cli) ProgressTracker- TTY-aware progress bar; animates on real terminals, falls back tologger.infoon Lambda/ECS/CI
Installation#
Install the package:
pip install core-mixins
uv pip install core-mixins # Or using UV...
pip install -e ".[dev]" # For development...
Setting Up Environment#
Install required libraries:
pip install --upgrade pip
pip install virtualenv
Create Python virtual environment:
virtualenv --python=python3.12 .venv
Activate the virtual environment:
source .venv/bin/activate
Install packages#
pip install .
pip install -e ".[dev]"
Check tests and coverage#
python manager.py run-tests
python manager.py run-coverage
Contributing#
Contributions are welcome! Please:
Fork the repository
Create a feature branch
Write tests for new functionality
Ensure all tests pass:
python manager.py run-testsRun linting:
pylint core_mixinsRun security checks:
bandit -r core_mixinsSubmit a pull request
License#
This project is licensed under the MIT License. See the LICENSE file for details.
Links#
Documentation: https://core-mixins.readthedocs.io/en/latest/
Repository: bytecode-solutions/core/core-mixins
Changelog: bytecode-solutions/core/core-mixins/-/blob/master/CHANGELOG.md
Support#
For questions or support, please open an issue on GitLab or contact the maintainers.