Utility helpers for Python projects. The initial release provides a centralized logging helper that sends JSON log payloads to a remote API using an API key.
On macOS and modern Linux systems, Python environments are externally managed. Always use a virtual environment:
# Create a virtual environment
python3 -m venv venv
# Activate the virtual environment
# On macOS/Linux:
source venv/bin/activate
# On Windows:
# venv\Scripts\activate
# Install the package
pip install "git+https://github.com/laziness-coders/python-utils.git@main"Note: If you're not using a virtual environment and your system has both Python 2 and Python 3, use pip3 instead of pip:
pip3 install "git+https://github.com/laziness-coders/python-utils.git@main"If you've cloned the repository locally:
# Activate your virtual environment first
source venv/bin/activate
# Install in editable mode (changes reflect immediately)
pip install -e .
# Or install normally
pip install .Add to your project's requirements.txt:
python-utils @ git+https://github.com/laziness-coders/python-utils.git@main
Or pin to a specific version/tag:
python-utils @ git+https://github.com/laziness-coders/python-utils.git@v0.1.0
Then install with:
pip install -r requirements.txt- Defines build requirements and metadata in a single, modern standard that pip understands, so
pip install .works reliably. - Lets packaging tools discover the source layout (
src/in this repo) without additional configuration files. - Ensures dependency declaration (
requests) is installed automatically when the package is consumed.
The python_utils.logger module exposes convenience functions for sending logs to a remote API endpoint. Configure the endpoint with environment variables before calling send_log or its level-specific wrappers.
export LOG_API_URL="https://logging.example.com/logs"
export LOG_API_KEY="your-api-key"from python_utils import send_info, send_error
send_info("Background job started")
send_error("Could not fetch product catalog")- Includes caller file path and line number in the message for easier tracing.
- Generates an MD5-based
dedup_keyderived from the caller location to reduce duplicate log entries. - Uses a short timeout (5 seconds) when contacting the remote API and returns
Falseon failure.
send_log(level: str, message: str) -> boolsend_info(message: str) -> boolsend_warning(message: str) -> boolsend_error(message: str) -> boolsend_critical(message: str) -> bool
Run the included example script after setting your logging endpoint environment variables:
# Make sure you're in a virtual environment
source venv/bin/activate
# Install the package
pip install .
# Run the example
LOG_API_URL="https://logging.example.com/logs" LOG_API_KEY="your-api-key" python examples/basic_logging.py